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

Document order of kernel weights #7204

Merged
merged 1 commit into from
Jun 9, 2023
Merged

Conversation

radarhere
Copy link
Member

Resolves #3678

https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html#PIL.ImageFilter.Kernel

kernel – A sequence containing kernel weights.

The issue notes that this doesn't specify the order. As #3134 notes, Pillow does not use convolution order or correlation order.

https://towardsdatascience.com/convolution-vs-correlation-af868b6b4fb5 has figures 5d and 6g of this,

noting that

In Convolution operation, the kernel is first flipped by an angle of 180 degrees and is then applied to the image.

So our order, as noted by #3134, is

# result:
#[[0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0]
# [0 0 3 2 1 0 0]
# [0 0 6 5 4 0 0]
# [0 0 9 8 7 0 0]
# [0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0]]

which would be flipping the kernel vertically before applying it. I've added that note to the documentation.

@radarhere radarhere requested a review from homm June 9, 2023 01:02
@hugovk hugovk merged commit 1fc8d82 into python-pillow:main Jun 9, 2023
58 checks passed
@radarhere radarhere deleted the kernel branch June 9, 2023 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageFilter.Kernel uses kernel weights in the wrong order?
2 participants