How to horizontally offset odd and even rows of pixels in an image using Python? -
i learning how use python image manipulation , trying create image odd , rows of pixels shifted horizontally same amount (e.g. odd rows shifted 10 pixels right , rows shifted 10 pixels left).
the image consists of single black word printed on white background, this:
http://oi63.tinypic.com/2i255bn.jpg
with code below, can odd , rows of pixels in 2 separate images, not sure how combine them single 1 20 pixels total horizontal offset.
from pil import image im = image.open('myimage.bmp') print im.size white = 255,255,255 = image.new('rgb',[1024,768], white) in range( im.size[0] ): j in range(im.size[1]): if j % 2 == 0 : even.putpixel(( int(i), int(j) ), im.getpixel((i,j)) ) even.show() odd = image.new('rgb',[1024,768], white) in range( im.size[0] ): j in range(im.size[1]): if j % 2 != 0 : odd.putpixel(( int(i), int(j) ), im.getpixel((i,j)) ) odd.show()
i new python , grateful this!
as rad suggested in question comments, need create 1 image , output both odd , pixels correct positions within it:
from pil import image im = image.open('myimage.bmp') print im.size white = 255,255,255 = image.new('rgb',[1024,768], white) offset = 10 in range( im.size[0] ): j in range(im.size[1]): x = int(i)+offset if j % 2 == 0: x = x+10 else: x = x-10 even.putpixel(( x, int(j) ), im.getpixel((i,j)) ) even.show()
i added offset ensure pixels don't go off left of canvas.
Comments
Post a Comment