python 的 PIL 的 resize 的默认插值是什么?

python 的 PIL 的 resize 的默认插值是什么?_第1张图片

chatGPT 告诉我,PIL 的 resize 的默认插值是 BILINEAR

事实真是如此吗?

看一下 PIL 的源码:

PIL/Image.py

def resize(self, size, resample=None, box=None, reducing_gap=None):
    """
    Returns a resized copy of this image.

    :param size: The requested size in pixels, as a 2-tuple:
        (width, height).
    :param resample: An optional resampling filter.  This can be
        one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`,
        :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
        :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
        If the image has mode "1" or "P", it is always set to
        :py:data:`Resampling.NEAREST`. If the image mode specifies a number
        of bits, such as "I;16", then the default filter is
        :py:data:`Resampling.NEAREST`. Otherwise, the default filter is
        :py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`.
    :param box: An optional 4-tuple of floats providing
        the source image region to be scaled.
        The values must be within (0, 0, width, height) rectangle.
        If omitted or None, the entire source is used.
    :param reducing_gap: Apply optimization by resizing the image
        in two steps. First, reducing the image by integer times
        using :py:meth:`~PIL.Image.Image.reduce`.
        Second, resizing using regular resampling. The last step
        changes size no less than by ``reducing_gap`` times.
        ``reducing_gap`` may be None (no first step is performed)
        or should be greater than 1.0. The bigger ``reducing_gap``,
        the closer the result to the fair resampling.
        The smaller ``reducing_gap``, the faster resizing.
        With ``reducing_gap`` greater or equal to 3.0, the result is
        indistinguishable from fair resampling in most cases.
        The default value is None (no optimization).
    :returns: An :py:class:`~PIL.Image.Image` object.
    """

    if resample is None:
        type_special = ";" in self.mode
        resample = Resampling.NEAREST if type_special else Resampling.BICUBIC
    elif resample not in (
        Resampling.NEAREST,
        Resampling.BILINEAR,
        Resampling.BICUBIC,
        Resampling.LANCZOS,
        Resampling.BOX,
        Resampling.HAMMING,
    ):

图片.png

但没有指定 resample 的时候,并且 mode 不含 ; 的时候, 就是用 BICUBIC, BICUBIC 是 三次样条插值

你可能感兴趣的:(python)