2014-11-29 03:58:52 +03:00
|
|
|
Pillow 2.7
|
|
|
|
==========
|
|
|
|
|
|
|
|
Image resizing filters
|
|
|
|
----------------------
|
|
|
|
|
2014-11-30 03:09:39 +03:00
|
|
|
Image resizing methods :py:meth:`~PIL.Image.Image.resize` and
|
|
|
|
:py:meth:`~PIL.Image.Image.thumbnail` takes `resample` argument, which tells
|
|
|
|
what filter should be used for resampling. Possible values are:
|
|
|
|
:py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
|
|
|
|
:py:attr:`PIL.Image.BICUBIC` and :py:attr:`PIL.Image.ANTIALIAS`.
|
|
|
|
Almost all of them was changed in this version.
|
|
|
|
|
|
|
|
Bicubic and Bilinear downscaling
|
2014-11-29 03:58:52 +03:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-11-30 03:09:39 +03:00
|
|
|
From very begining :py:attr:`~PIL.Image.BILINEAR` and
|
2014-12-01 02:23:31 +03:00
|
|
|
:py:attr:`~PIL.Image.BICUBIC` filters was based on affine transformations
|
2014-11-30 03:09:39 +03:00
|
|
|
and uses fixed number of pixels from source image for every destination pixel
|
|
|
|
(that was 2x2 pixels for :py:attr:`~PIL.Image.BILINEAR` and 4x4 for
|
|
|
|
:py:attr:`~PIL.Image.BICUBIC`). This gave an unsatisfied result for downscaling.
|
2014-12-01 02:23:31 +03:00
|
|
|
At the same time high quality convolutions-based algorithm with flexible kernel
|
2014-11-30 03:09:39 +03:00
|
|
|
was used for :py:attr:`~PIL.Image.ANTIALIAS` filter).
|
|
|
|
|
|
|
|
Starting from 2.7 high quality convolutions-based algorithm is used for all of
|
|
|
|
these three filters.
|
|
|
|
|
|
|
|
If you have previously used any tricks to maintain quality when downscaling with
|
|
|
|
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` filters
|
|
|
|
(for example, reducing within several steps), they a unnecessary now.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Antialias renamed to Lanczos
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-11-29 23:04:51 +03:00
|
|
|
New :py:attr:`PIL.Image.LANCZOS` constant was added instead of
|
2014-11-30 03:09:39 +03:00
|
|
|
:py:attr:`~PIL.Image.ANTIALIAS`.
|
2014-11-29 23:04:51 +03:00
|
|
|
|
|
|
|
When :py:attr:`~PIL.Image.ANTIALIAS` was initially added, it was the only
|
2014-12-01 02:23:31 +03:00
|
|
|
high-quality filter based on convolutions. It's name was supposed to reflect
|
2014-11-29 23:04:51 +03:00
|
|
|
this. Starting from 2.7 all resize method are based on convolutions. All of them
|
|
|
|
are antialias from now. And the real name of :py:attr:`~PIL.Image.ANTIALIAS`
|
|
|
|
filter is Lanczos filter.
|
|
|
|
|
|
|
|
:py:attr:`~PIL.Image.ANTIALIAS` constant is leaved for backward compatibility
|
|
|
|
and is an alias for :py:attr:`~PIL.Image.LANCZOS`.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Lanczos upscaling quality
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-11-30 20:31:33 +03:00
|
|
|
Image upscaling quality with :py:attr:`~PIL.Image.LANCZOS` filter was almost
|
|
|
|
the same as :py:attr:`~PIL.Image.BILINEAR` due to bug. This was fixed.
|
2014-11-30 03:09:39 +03:00
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Bicubic upscaling quality
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-12-01 02:23:31 +03:00
|
|
|
:py:attr:`~PIL.Image.BICUBIC` filter for affine transformations produced
|
2014-11-30 03:09:39 +03:00
|
|
|
sharp, slightly pixelated image for upscaling. Bicubic for convolutions is
|
|
|
|
more soft.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Resize performance
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-11-30 20:31:33 +03:00
|
|
|
In most cases convolution is more expensive algorithm for downscaling because
|
2014-12-01 02:23:31 +03:00
|
|
|
it takes in account all pixels of source image. Therefore
|
2014-11-30 20:31:33 +03:00
|
|
|
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` filters
|
|
|
|
performance can be lower than before. On the other hand quality of
|
|
|
|
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` was close to
|
|
|
|
:py:attr:`~PIL.Image.NEAREST`. So if such quality is suitable for your task
|
|
|
|
you can switch to :py:attr:`~PIL.Image.NEAREST` filter for downscaling,
|
|
|
|
that will give huge win in performance.
|
|
|
|
|
|
|
|
At the same time performance of convolution resampling for downscaling was
|
|
|
|
improved in about two times compared to previous version.
|
|
|
|
Upscaling performance of :py:attr:`~PIL.Image.LANCZOS` filter remained the same.
|
|
|
|
For :py:attr:`~PIL.Image.BILINEAR` filter it grew in 1.5 times and
|
|
|
|
for :py:attr:`~PIL.Image.BICUBIC` in 4 times.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Default filter for thumbnails
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-11-29 23:04:51 +03:00
|
|
|
In Pillow 2.5 default filter for :py:meth:`~PIL.Image.Image.thumbnail` was
|
|
|
|
changed from :py:attr:`~PIL.Image.NEAREST` to :py:attr:`~PIL.Image.ANTIALIAS`.
|
|
|
|
Antialias was chosen because all other filters gave poor quality for reduction.
|
|
|
|
Starting from Pillow 2.7 :py:attr:`~PIL.Image.ANTIALIAS` replaced with
|
2014-11-30 20:31:33 +03:00
|
|
|
:py:attr:`~PIL.Image.BICUBIC`, because it faster and
|
2014-11-29 23:04:51 +03:00
|
|
|
:py:attr:`~PIL.Image.ANTIALIAS` doesn't give any advantages after
|
2014-12-01 02:23:31 +03:00
|
|
|
downscaling with libJPEG, which uses supersampling internally, not convolutions.
|
2014-11-29 23:04:51 +03:00
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Image transposing
|
|
|
|
-----------------
|
|
|
|
|
2014-11-29 23:04:51 +03:00
|
|
|
New method :py:attr:`PIL.Image.TRANSPOSE` was added for
|
|
|
|
:py:meth:`~PIL.Image.Image.transpose` operation in addition to
|
|
|
|
:py:attr:`~PIL.Image.FLIP_LEFT_RIGHT`, :py:attr:`~PIL.Image.FLIP_TOP_BOTTOM`,
|
|
|
|
:py:attr:`~PIL.Image.ROTATE_90`, :py:attr:`~PIL.Image.ROTATE_180`,
|
|
|
|
:py:attr:`~PIL.Image.ROTATE_270`. :py:attr:`~PIL.Image.TRANSPOSE` is algebra
|
|
|
|
transpose, when image reflected over its main diagonal.
|
|
|
|
|
|
|
|
Speed of :py:attr:`~PIL.Image.ROTATE_90`, :py:attr:`~PIL.Image.ROTATE_270`
|
|
|
|
and :py:attr:`~PIL.Image.TRANSPOSE` was significantly improved for large images,
|
|
|
|
which doesn't fit in processor cache.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Gaussian blur and unsharp mask
|
|
|
|
------------------------------
|
|
|
|
|
2014-12-01 02:18:11 +03:00
|
|
|
:py:meth:`~PIL.ImageFilter.GaussianBlur` implementation was replaced with
|
|
|
|
sequential applying of series of box filters. New implementation is based on
|
|
|
|
"Theoretical foundations of Gaussian convolution by extended box filtering" from
|
|
|
|
Mathematical Image Analysis Group. As :py:meth:`~PIL.ImageFilter.UnsharpMask`
|
|
|
|
implementations uses Gaussian blur internally, all changes from this chapter
|
2014-12-01 02:23:31 +03:00
|
|
|
also applicable to it.
|
2014-12-01 02:18:11 +03:00
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Blur radius
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
2014-12-01 02:18:11 +03:00
|
|
|
There was an error in previous version of PIL, when blur radius (the standard
|
|
|
|
deviation of Gaussian) is actually meant blur diameter.
|
|
|
|
For example for blurring image with actual radius 5 you were forced
|
|
|
|
to use value 10. This was fixed. For now the meaning of the radius
|
|
|
|
is the same as in other software.
|
|
|
|
|
2014-12-01 02:23:31 +03:00
|
|
|
If you used a Gaussian blur with some radius value, you need to divide this
|
2014-12-01 02:18:11 +03:00
|
|
|
value by two.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Blur Performance
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
2014-12-01 02:18:11 +03:00
|
|
|
Box filter computation time is constant relative to the radius and depends
|
|
|
|
on source image size only. Because new Gaussian blur implementation
|
|
|
|
is based on box filter, it's computation time is also doesn't depends on blur
|
|
|
|
radius.
|
|
|
|
|
|
|
|
If before execution time for the same test image was 1 second for radius 1,
|
|
|
|
3.6 seconds for radius 10, 17 seconds for 50. Now blur with any radius on same
|
|
|
|
image is executed for 0.2 seconds.
|
|
|
|
|
2014-11-29 03:58:52 +03:00
|
|
|
Blur quality
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
2014-12-01 02:18:11 +03:00
|
|
|
Previous implementation takes in account only source pixels within
|
2014-12-01 02:23:31 +03:00
|
|
|
2 * standard deviation radius for every destination pixel. This was not enough,
|
|
|
|
so quality was worse compared to other Gaussian blur software.
|
2014-12-01 02:18:11 +03:00
|
|
|
|
|
|
|
The new implementation does not have this drawback.
|