[Image-SIG] How to improve rotation quality?

Christopher Barker Chris.Barker at noaa.gov
Wed Feb 17 23:38:03 CET 2010


Alec Bennett wrote:
> I'm wondering if anyone has any idea how to get better results from 
> PIL's rotate() function? No matter what filter I use I'm getting very 
> jagged edges after rotating an image.
> 
> Here's how I'm invoking the filters:
> 
> pic = pic.rotate(random_rotation, resample=Image.NEAREST, expand=1)   
> pic = pic.rotate(random_rotation, resample=Image.BILINEAR, expand=1)   
> pic = pic.rotate(random_rotation, resample=Image.BICUBIC, expand=1)    # 
> the best I think

Too bad ANTIALIAS doesn't seem to be available for rotate -- darn. It 
might look better.

But to some extent, you can only get so good rotating an image.

However, I took at look at your test images -- it looked like better 
smoothing was going on inside the white border than outside, which made 
me think -- when rotating, if you are going to use interpolation, how 
does it interpolate to outside the image? It doesn't. So I tried adding 
a black background to the image first, then rotating it -- much better. 
See the enclosed version of your test code, and a rotated image.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: application/x-python
Size: 961 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100217/b9ba0d63/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-3.jpg
Type: image/jpeg
Size: 42962 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100217/b9ba0d63/attachment-0001.jpg>


More information about the Image-SIG mailing list