bug in nearest-neighbour resize
Nicolas Limare <[email protected]>
| Newsgroups | gmane.comp.python.image |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I think there is a bug in the nearest neighbour resizing filter: when
resizing an image with an integer ratio, the original pixels are not
all expanded by this ratio. For example:
>>> from PIL import Image
>>> Image.VERSION
'1.1.7'
>>> im = Image.open("input.png")
>>> for x in range(0, 6):
... im.getpixel((x, 0))
...
(255, 0, 0)
(0, 255, 0)
(0, 0, 255)
(255, 0, 0)
(0, 255, 0)
(0, 0, 255)
The first column of my input image is RGBRGB...
>>> zim = im.resize((im.size[0] * 3, im.size[0] * 3), Image.NEAREST)
>>> for x in range(0, 18):
... zim.getpixel((x, 0))
...
(255, 0, 0)
(255, 0, 0)
(255, 0, 0)
(0, 255, 0)
(0, 255, 0)
(0, 255, 0)
(0, 255, 0)
(0, 0, 255)
(0, 0, 255)
(255, 0, 0)
(255, 0, 0)
(255, 0, 0)
(0, 255, 0)
(0, 255, 0)
(0, 255, 0)
(0, 255, 0)
(0, 0, 255)
(0, 0, 255)
Note that the first pixel is repeated 3 times, the second 4 times,
then 2, 3, 4, amd 2 times. I would expect each pixel to be repeated 3
times, and I think that is what "nearest neighbour" means.
I could track the bug down to libImaging/Geometry.c, function
ImagingScaleAffine(), lines 672-697. there must be something wrong in
these two loops, probably related to the integer rounding, but I
wasn't able to figure out the exact meaning of all the variables.
--
Nicolas LIMARE - CMLA - ENS Cachan http://www.cmla.ens-cachan.fr/~limare/
IPOL - image processing on line http://www.ipol.im/
_______________________________________________
Image-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/image-sig
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk1t61cACgkQvviFAPpCP09V5gCeP5UMSEl7n3Endz4TOvviQhOW wtIAnjG/uhzPbC74dNOUNoL6n0/JMAam =zcy6 -----END PGP SIGNATURE-----