mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Review edits [CI skip]
This commit is contained in:
parent
53e54b6f96
commit
cfe41caa8a
|
@ -1,144 +1,143 @@
|
||||||
Pillow 2.7
|
Pillow 2.7.0
|
||||||
==========
|
============
|
||||||
|
|
||||||
Image resizing filters
|
Image resizing filters
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Image resizing methods :py:meth:`~PIL.Image.Image.resize` and
|
Image resizing methods :py:meth:`~PIL.Image.Image.resize` and
|
||||||
:py:meth:`~PIL.Image.Image.thumbnail` takes `resample` argument, which tells
|
:py:meth:`~PIL.Image.Image.thumbnail` take a `resample` argument, which tells
|
||||||
what filter should be used for resampling. Possible values are:
|
which filter should be used for resampling. Possible values are:
|
||||||
:py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
|
:py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
|
||||||
:py:attr:`PIL.Image.BICUBIC` and :py:attr:`PIL.Image.ANTIALIAS`.
|
:py:attr:`PIL.Image.BICUBIC` and :py:attr:`PIL.Image.ANTIALIAS`.
|
||||||
Almost all of them was changed in this version.
|
Almost all of them were changed in this version.
|
||||||
|
|
||||||
Bicubic and Bilinear downscaling
|
Bicubic and bilinear downscaling
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
From very begining :py:attr:`~PIL.Image.BILINEAR` and
|
From the beginning :py:attr:`~PIL.Image.BILINEAR` and
|
||||||
:py:attr:`~PIL.Image.BICUBIC` filters was based on affine transformations
|
:py:attr:`~PIL.Image.BICUBIC` filters were based on affine transformations
|
||||||
and uses fixed number of pixels from source image for every destination pixel
|
and used a fixed number of pixels from the source image for every destination
|
||||||
(that was 2x2 pixels for :py:attr:`~PIL.Image.BILINEAR` and 4x4 for
|
pixel (2x2 pixels for :py:attr:`~PIL.Image.BILINEAR` and 4x4 for
|
||||||
:py:attr:`~PIL.Image.BICUBIC`). This gave an unsatisfied result for downscaling.
|
:py:attr:`~PIL.Image.BICUBIC`). This gave an unsatisfactory result for
|
||||||
At the same time high quality convolutions-based algorithm with flexible kernel
|
downscaling. At the same time, a high quality convolutions-based algorithm with
|
||||||
was used for :py:attr:`~PIL.Image.ANTIALIAS` filter).
|
flexible kernel was used for :py:attr:`~PIL.Image.ANTIALIAS` filter).
|
||||||
|
|
||||||
Starting from 2.7 high quality convolutions-based algorithm is used for all of
|
Starting from Pillow 2.7.0, a high quality convolutions-based algorithm is used
|
||||||
these three filters.
|
for all of these three filters.
|
||||||
|
|
||||||
If you have previously used any tricks to maintain quality when downscaling with
|
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
|
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` filters
|
||||||
(for example, reducing within several steps), they a unnecessary now.
|
(for example, reducing within several steps), they are unnecessary now.
|
||||||
|
|
||||||
Antialias renamed to Lanczos
|
Antialias renamed to Lanczos
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
New :py:attr:`PIL.Image.LANCZOS` constant was added instead of
|
A new :py:attr:`PIL.Image.LANCZOS` constant was added instead of
|
||||||
:py:attr:`~PIL.Image.ANTIALIAS`.
|
:py:attr:`~PIL.Image.ANTIALIAS`.
|
||||||
|
|
||||||
When :py:attr:`~PIL.Image.ANTIALIAS` was initially added, it was the only
|
When :py:attr:`~PIL.Image.ANTIALIAS` was initially added, it was the only
|
||||||
high-quality filter based on convolutions. It's name was supposed to reflect
|
high-quality filter based on convolutions. It's name was supposed to reflect
|
||||||
this. Starting from 2.7 all resize method are based on convolutions. All of them
|
this. Starting from Pillow 2.7.0 all resize method are based on convolutions.
|
||||||
are antialias from now. And the real name of :py:attr:`~PIL.Image.ANTIALIAS`
|
All of them are antialias from now on. And the real name of the
|
||||||
filter is Lanczos filter.
|
:py:attr:`~PIL.Image.ANTIALIAS` filter is Lanczos filter.
|
||||||
|
|
||||||
:py:attr:`~PIL.Image.ANTIALIAS` constant is leaved for backward compatibility
|
The :py:attr:`~PIL.Image.ANTIALIAS` constant is left for backward compatibility
|
||||||
and is an alias for :py:attr:`~PIL.Image.LANCZOS`.
|
and is an alias for :py:attr:`~PIL.Image.LANCZOS`.
|
||||||
|
|
||||||
Lanczos upscaling quality
|
Lanczos upscaling quality
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Image upscaling quality with :py:attr:`~PIL.Image.LANCZOS` filter was almost
|
The image upscaling quality with :py:attr:`~PIL.Image.LANCZOS` filter was
|
||||||
the same as :py:attr:`~PIL.Image.BILINEAR` due to bug. This was fixed.
|
almost the same as :py:attr:`~PIL.Image.BILINEAR` due to bug. This has been fixed.
|
||||||
|
|
||||||
Bicubic upscaling quality
|
Bicubic upscaling quality
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
:py:attr:`~PIL.Image.BICUBIC` filter for affine transformations produced
|
The :py:attr:`~PIL.Image.BICUBIC` filter for affine transformations produced
|
||||||
sharp, slightly pixelated image for upscaling. Bicubic for convolutions is
|
sharp, slightly pixelated image for upscaling. Bicubic for convolutions is
|
||||||
more soft.
|
more soft.
|
||||||
|
|
||||||
Resize performance
|
Resize performance
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
In most cases convolution is more expensive algorithm for downscaling because
|
In most cases, convolution is more a expensive algorithm for downscaling
|
||||||
it takes in account all pixels of source image. Therefore
|
because it takes into account all the pixels of source image. Therefore
|
||||||
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` filters
|
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` filters'
|
||||||
performance can be lower than before. On the other hand quality of
|
performance can be lower than before. On the other hand the quality of
|
||||||
:py:attr:`~PIL.Image.BILINEAR` and :py:attr:`~PIL.Image.BICUBIC` was close to
|
: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
|
:py:attr:`~PIL.Image.NEAREST`. So if such quality is suitable for your tasks
|
||||||
you can switch to :py:attr:`~PIL.Image.NEAREST` filter for downscaling,
|
you can switch to :py:attr:`~PIL.Image.NEAREST` filter for downscaling,
|
||||||
that will give huge win in performance.
|
which will give a huge improvement in performance.
|
||||||
|
|
||||||
At the same time performance of convolution resampling for downscaling was
|
At the same time performance of convolution resampling for downscaling has been
|
||||||
improved in about two times compared to previous version.
|
improved by around a factor of two compared to the previous version.
|
||||||
Upscaling performance of :py:attr:`~PIL.Image.LANCZOS` filter remained the same.
|
The upscaling performance of the :py:attr:`~PIL.Image.LANCZOS` filter has
|
||||||
For :py:attr:`~PIL.Image.BILINEAR` filter it grew in 1.5 times and
|
remained the same. For :py:attr:`~PIL.Image.BILINEAR` filter it has improved by
|
||||||
for :py:attr:`~PIL.Image.BICUBIC` in 4 times.
|
1.5 times and for :py:attr:`~PIL.Image.BICUBIC` by four times.
|
||||||
|
|
||||||
Default filter for thumbnails
|
Default filter for thumbnails
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
In Pillow 2.5 default filter for :py:meth:`~PIL.Image.Image.thumbnail` was
|
In Pillow 2.5 the default filter for :py:meth:`~PIL.Image.Image.thumbnail` was
|
||||||
changed from :py:attr:`~PIL.Image.NEAREST` to :py:attr:`~PIL.Image.ANTIALIAS`.
|
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.
|
Antialias was chosen because all the other filters gave poor quality for
|
||||||
Starting from Pillow 2.7 :py:attr:`~PIL.Image.ANTIALIAS` replaced with
|
reduction. Starting from Pillow 2.7.0, :py:attr:`~PIL.Image.ANTIALIAS` has been
|
||||||
:py:attr:`~PIL.Image.BICUBIC`, because it faster and
|
replaced with :py:attr:`~PIL.Image.BICUBIC`, because it's faster and
|
||||||
:py:attr:`~PIL.Image.ANTIALIAS` doesn't give any advantages after
|
:py:attr:`~PIL.Image.ANTIALIAS` doesn't give any advantages after
|
||||||
downscaling with libJPEG, which uses supersampling internally, not convolutions.
|
downscaling with libjpeg, which uses supersampling internally, not convolutions.
|
||||||
|
|
||||||
Image transposing
|
Image transposition
|
||||||
-----------------
|
-------------------
|
||||||
|
|
||||||
New method :py:attr:`PIL.Image.TRANSPOSE` was added for
|
A new method :py:attr:`PIL.Image.TRANSPOSE` has been added for the
|
||||||
:py:meth:`~PIL.Image.Image.transpose` operation in addition to
|
: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.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_90`, :py:attr:`~PIL.Image.ROTATE_180`,
|
||||||
:py:attr:`~PIL.Image.ROTATE_270`. :py:attr:`~PIL.Image.TRANSPOSE` is algebra
|
:py:attr:`~PIL.Image.ROTATE_270`. :py:attr:`~PIL.Image.TRANSPOSE` is an algebra
|
||||||
transpose, when image reflected over its main diagonal.
|
transpose, with an image reflected across its main diagonal.
|
||||||
|
|
||||||
Speed of :py:attr:`~PIL.Image.ROTATE_90`, :py:attr:`~PIL.Image.ROTATE_270`
|
The 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,
|
and :py:attr:`~PIL.Image.TRANSPOSE` has been significantly improved for large
|
||||||
which doesn't fit in processor cache.
|
images which don't fit in the processor cache.
|
||||||
|
|
||||||
Gaussian blur and unsharp mask
|
Gaussian blur and unsharp mask
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
:py:meth:`~PIL.ImageFilter.GaussianBlur` implementation was replaced with
|
The :py:meth:`~PIL.ImageFilter.GaussianBlur` implementation has been replaced
|
||||||
sequential applying of series of box filters. New implementation is based on
|
with a sequential application of box filters. The new implementation is based on
|
||||||
"Theoretical foundations of Gaussian convolution by extended box filtering" from
|
"Theoretical foundations of Gaussian convolution by extended box filtering" from
|
||||||
Mathematical Image Analysis Group. As :py:meth:`~PIL.ImageFilter.UnsharpMask`
|
the Mathematical Image Analysis Group. As :py:meth:`~PIL.ImageFilter.UnsharpMask`
|
||||||
implementations uses Gaussian blur internally, all changes from this chapter
|
implementations use Gaussian blur internally, all changes from this chapter
|
||||||
also applicable to it.
|
are also applicable to it.
|
||||||
|
|
||||||
Blur radius
|
Blur radius
|
||||||
^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
|
|
||||||
There was an error in previous version of PIL, when blur radius (the standard
|
There was an error in the previous version of Pillow, where blur radius (the
|
||||||
deviation of Gaussian) is actually meant blur diameter.
|
standard deviation of Gaussian) actually meant blur diameter. For example, to
|
||||||
For example for blurring image with actual radius 5 you were forced
|
blur an image with actual radius 5 you were forced to use value 10. This has
|
||||||
to use value 10. This was fixed. For now the meaning of the radius
|
been fixed. Now the meaning of the radius is the same as in other software.
|
||||||
is the same as in other software.
|
|
||||||
|
|
||||||
If you used a Gaussian blur with some radius value, you need to divide this
|
If you used a Gaussian blur with some radius value, you need to divide this
|
||||||
value by two.
|
value by two.
|
||||||
|
|
||||||
Blur Performance
|
Blur performance
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Box filter computation time is constant relative to the radius and depends
|
Box filter computation time is constant relative to the radius and depends
|
||||||
on source image size only. Because new Gaussian blur implementation
|
on source image size only. Because the new Gaussian blur implementation
|
||||||
is based on box filter, it's computation time is also doesn't depends on blur
|
is based on box filter, its computation time also doesn't depends on the blur
|
||||||
radius.
|
radius.
|
||||||
|
|
||||||
If before execution time for the same test image was 1 second for radius 1,
|
For example, previously, if the execution time for a given test image was 1
|
||||||
3.6 seconds for radius 10, 17 seconds for 50. Now blur with any radius on same
|
second for radius 1, 3.6 seconds for radius 10 and 17 seconds for 50, now blur
|
||||||
image is executed for 0.2 seconds.
|
with any radius on same image is executed for 0.2 seconds.
|
||||||
|
|
||||||
Blur quality
|
Blur quality
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
Previous implementation takes in account only source pixels within
|
The previous implementation takes into account only source pixels within
|
||||||
2 * standard deviation radius for every destination pixel. This was not enough,
|
2 * standard deviation radius for every destination pixel. This was not enough,
|
||||||
so quality was worse compared to other Gaussian blur software.
|
so the quality was worse compared to other Gaussian blur software.
|
||||||
|
|
||||||
The new implementation does not have this drawback.
|
The new implementation does not have this drawback.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user