使用MPI进行图像处理

时间:2014-05-03 13:15:22

标签: python parallel-processing mpi

我必须使用并行编程进行一些图像处理。我正在使用Python和MPI(mpi4py)。 我有两个功能,棕褐色和翻转。我认为他们是自我解释的。这是顺序代码:

def sepia(name):
  img = Image.open('dog.jpg')
  for i in range(width):
    for j in range(height):
      r, g, b = img.getpixel((i, j))
      rr = int(r * 0.393 + g * 0.769 + b * 0.189)
      gg = int(r * 0.349 + g * 0.686 + b * 0.168)
      bb = int(r * 0.272 + g * 0.534 + b * 0.131)
      img.putpixel((i,j),(rr,gg,bb))
  img.save(name)

def flip(name):
  img = Image.open('dog.jpg')
  white = (255,255,255)
  image = Image.new("RGB", (width, height))
  for i in range(width):
    for j in range(height):
      r, g, b = img.getpixel((i,j))
      image.putpixel((width-i-1, height-j-1),(r,g,b))
  image.save(name)

如何使用MPI并行化此代码?

0 个答案:

没有答案