[Image-SIG] Bilinear filter: unexpected results for 50 percent resize

Bruce Sutherland bruces1 at gmail.com
Tue Jan 13 16:13:54 CET 2009


Hi everyone.

I resized an 8x16 RGB image to 4x8 using PIL (1.1.6). I used the
bilinear filter. The results were not exactly as I had expected.

I performed the same operation using The Gimp (2.4.2), and sure
enough, the result was quite different, and fit my understanding of a
bilinear filter.

See attached images.

There seem to be two difference, one significant (for my application),
and one a minor implementation detail.

1) Each pixel in The Gimp's output image can be determined by summing
the pixels in each 2x2 block starting from the top left hand corner
and dividing by four. This fits my understanding of a bilinear filter.
I don't understand how PIL arrives at its result.
2) PIL appears to use pure integer division to average the 2x2 blocks,
resulting in truncation. By contrast, Gimp's filter seems to use
fractional math and round to the nearest value.

I examined the resize function in the Image class, but stopped when I
realised that it calls a function from the compiled imaging core
library. This is my first adventure with PIL. Please forgive the
attachments, but they are very small.

Bruce.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: original.png
Type: image/png
Size: 193 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090114/afbe51b1/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pil_resize_linear.png
Type: image/png
Size: 159 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090114/afbe51b1/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gimp_resize_linear.png
Type: image/png
Size: 141 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090114/afbe51b1/attachment-0002.png>


More information about the Image-SIG mailing list