Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageFilter.Kernel uses kernel weights in the wrong order? #3678

Closed
carlosefr opened this issue Feb 27, 2019 · 4 comments · Fixed by #7204
Closed

ImageFilter.Kernel uses kernel weights in the wrong order? #3678

carlosefr opened this issue Feb 27, 2019 · 4 comments · Fixed by #7204
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects

Comments

@carlosefr
Copy link

What did you do?

I'm using the ImageFilter.Kernel filter with a 3x3 kernel that should shift the image down by one pixel, but instead it is shifting the image one pixel up.

I'm assuming the order of weights in the kernel is left-right, top-bottom because, AFAIK, the documentation doesn't specify the order and I assume it uses the same ordering/coordinates as the image itself.

So, this is either a bug in the code, or a bug in the documentation.

What did you expect to happen?

The image should be shifted one pixel down.

What actually happened?

The image is shifted one pixel up.

What are your OS, Python and Pillow versions?

  • OS: CentOS Linux 7.6
  • Python: 3.6.7
  • Pillow: 5.4.1
from PIL import Image, ImageFilter

shift_down = (
    0, 1, 0,
    0, 0, 0,
    0, 0, 0,
)

original_image = Image.open("images/example.png", mode="r")
filtered_image = original_image.filter(ImageFilter.Kernel((3, 3), shift_down))
filtered_image.save("filtered.png", format="PNG")
@carlosefr
Copy link
Author

carlosefr commented Feb 27, 2019

Additional note, this kernel shifts the image left by one pixel as expected:

shift_left = (
    0, 0, 0,
    0, 0, 1,
    0, 0, 0,
)

@hugovk
Copy link
Member

hugovk commented Feb 27, 2019

Possibly related to #3134?

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label May 11, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@homm
Copy link
Member

homm commented Dec 31, 2019

This can't ever be fixed due to backward compatibility. Think about this as a call convention. The only we can do is update documentation. Pull requests are welcome.

@radarhere
Copy link
Member

The previous comment states that we should retain the current behaviour for backwards compatibility, whereas an earlier comment on a different issue suggests that we change it.

I'm more inclined to go with retaining the current behaviour - I don't think there's a neat way to transition users into reversing the operation, even with deprecation.

I've created PR #7204 to document this.

Pillow automation moved this from In progress to Closed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
No open projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants