[Image-SIG] binary image rotation

Christian Jauvin cjauvin at gmail.com
Sat Oct 15 17:56:32 CEST 2011


Hi,

I'm very new to PIL, and I'm exploring it as a way to rotate simple binary
images. Suppose I have an image like this:

0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 1 0 0 0
0 0 0 1 0 0 0
0 0 1 1 1 0 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0

created with:

from PIL import Image
im = Image.new('1', (7,7))
for p in [(1,3), (2,3), (3,3), (4,2), (4,3), (4,4),
          (5,1), (5,2), (5,3), (5,4), (5,5)]:
    im.putpixel(p, 1)

that I'd like to rotate 45 degrees:

im = im.rotate(45)

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 1 1 0
0 1 1 1 1 0 0
0 1 1 1 0 0 0
0 0 1 1 0 0 0

or with expansion:

im = im.rotate(45, expand=True)

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 1 1 1 1 0 0 0 0
0 0 0 1 1 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0

The results don't look 100% right.. Am I doing something wrong? Is there a
way to obtain better results?

Thanks,

Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20111015/b37c4bdf/attachment.html>


More information about the Image-SIG mailing list