-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
About using Image.ANTIALIAS with resize (downscaling) #6200
Comments
Yes, Here's a blogpost about the different methods in Pillow: |
@mitchellwiebe did that answer your question, or no? |
It did help with the general concept. I suppose what I am really looking for is a toy example of what happens to the pixels of a sample image to obtain the downsized image in this way. I see lots of examples online of how images are upscaled and values must be interpolated (to determine pixel values between the original image pixels); however, it is difficult to visualize how this works for the downscaling case - as the final image has fewer pixels than the original. I hope my message makes sense. |
The previously linked article does have a section talking about downscaling - https://uploadcare.com/blog/the-fastest-image-resize/#convolution-based-resampling. There are two passes over the image - horizontal, and then vertical. Pillow/src/libImaging/Resample.c Line 655 in 46ba6b5
The filter chosen is used to calculate the coefficients for each pass. Our lanczos function is truncated to between -3 and 3 (https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel, where 'a' is 3). As far as visualising, I suggest looking at the Lanczos graph from the article, from PIL import Image
im = Image.new("L", (4, 1))
px = im.load()
px[0, 0] = 1
px[1, 0] = 2
px[2, 0] = 3
px[3, 0] = 4
im = im.resize((1, 1), Image.Resampling.LANCZOS)
print(im.getpixel((0, 0))) So in words, the Lanczos curve is applied to the pixels, considering the values of closer pixels more heavily, and the values of more distant pixels less heavily. |
Hi radarhere and hugovk, I may have been overthinking things but this has helped to clarify my confusion. Thank you very much for your help, it is greatly appreciated. |
Hi there,
I've been trying to understand how images are resized (specifically downscaled) when using Image.ANTIALIAS. I understand that a Lanczos kernel is involved, but not exactly sure how. For example, if an image is being downscaled to half of its original size, is the process something like: 1.) Lanczos low-pass filter applied, 2.) Retain every second pixel? Or is something more/less technical going on here?
Thanks for your time,
Mitch
The text was updated successfully, but these errors were encountered: