Skip to content

RGBA Image.resize with Nearest Neighbor Interpolation introduces new RGB Values #5300

@gerhardneuhold

Description

@gerhardneuhold

What did you do?

Resizing an RGBA image with Image.resize and nearest neighbor interpolation.

What did you expect to happen?

Image resized to given size, no new RGB values introduced.

What actually happened?

New RGB values introduced.

What are your OS, Python and Pillow versions?

  • OS: Linux
  • Python: 3.8.6
  • Pillow: 6.2.1

Python Example

import numpy as np
from PIL import Image

image = np.asarray([[[1, 1, 0, 128]], [[2, 2, 0, 64]]], dtype=np.uint8)

print("Input")
print(image)
print("")

image = Image.fromarray(image)
image = image.resize((1, 1), Image.NEAREST)
image = np.asarray(image)

print("Output")
print(image)
Input
[[[  1   1   0 128]]
 [[  2   2   0  64]]]

Output
[[[ 3  3  0 64]]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions