Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image
- import struct
- if __name__ == '__main__':
- width = 1280
- height = 720 - 2
- img_grey = Image.new('L', (width, height))
- pix_grey = img_grey.load()
- img_color = Image.new('RGB', (width, height))
- pix_color = img_color.load()
- print "start calc"
- with open("pic.bin", "rb") as fin:
- for y in range(2):
- for x in range(width):
- fin.read(1)
- for y in range(height):
- for x in range(width):
- v, = struct.unpack('<B', fin.read(1))
- pix_grey[x, y] = (v)
- for y in range(1,height-1):
- for x in range(1,width-1):
- ind = (x-1) % 2 + (y % 2) * 2;
- '''
- if ind == 0: # red
- red = pix_grey[x, y]
- green = 128
- blue = 128
- elif ind == 1: # green on RG row
- red = 128
- green = pix_grey[x, y]
- blue = 128
- elif ind == 2: # green on GB row
- red = 128
- green = pix_grey[x, y]
- blue = 128
- elif ind == 3: # blue
- red = 128
- green = 128
- blue = pix_grey[x, y]
- '''
- if ind == 0: # red
- red = pix_grey[x, y];
- green = (pix_grey[x, y - 1] + pix_grey[x - 1, y] + pix_grey[x + 1, y] + pix_grey[x, y + 1]) / 4;
- blue = (pix_grey[x - 1, y - 1] + pix_grey[x + 1, y - 1] + pix_grey[x - 1, y + 1] + pix_grey[x + 1, y + 1]) / 4;
- elif ind == 1: # green on RG row
- red = (pix_grey[x - 1, y] + pix_grey[x + 1, y]) / 2;
- green = pix_grey[x, y];
- blue = (pix_grey[x, y - 1] + pix_grey[x, y + 1]) / 2;
- elif ind == 2: # green on GB row
- red = (pix_grey[x, y - 1] + pix_grey[x, y + 1]) / 2;
- green = pix_grey[x, y];
- blue = (pix_grey[x - 1, y] + pix_grey[x + 1, y]) / 2;
- elif ind == 3: # blue
- red = (pix_grey[x - 1, y - 1] + pix_grey[x + 1, y - 1] + pix_grey[x - 1, y + 1] + pix_grey[x + 1, y + 1]) / 4;
- green = (pix_grey[x, y - 1] + pix_grey[x - 1, y] + pix_grey[x + 1, y] + pix_grey[x, y + 1]) / 4;
- blue = pix_grey[x, y];
- pix_color[x, y] = (red, green, blue)
- print "save result"
- img_grey.save("01_grey.png")
- img_color.save("02_color.png")
- print "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement