-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Incorrect upsampling with Image.BOX #4258
Comments
I can confirm. The problem is that BOX, unlike other filters, is a discontinuous function. It equals 1 in range (-0.5, 0.5) and equals 0 on the rest range. What is it equal to in -0.5 and 0.5? I don't know exactly, because it should be exactly 1 long, so if it equals 1, it will be a bit longer than 1, and if it will be 0, it will be slightly shorter than 1. Current implementation defines box filter as 1 on [-0.5, 0.5) range (0.5 is not included). static inline double box_filter(double x)
{
if (x >= -0.5 && x < 0.5)
return 1.0;
return 0.0;
} I'll try to find the way how to fix this gently. |
For reference, OpenCV's |
Oh my god, I believe I found a fix and can mathematically prove it. The fix is very simple. Instead of defining the BOX filter as 1 on [-0.5, 0.5), define it 1 on (-0.5, 0.5]. static inline double box_filter(double x)
{
if (x > -0.5 && x <= 0.5)
return 1.0;
return 0.0;
} The main question is "how we can be sure that 0.0 is the correct value for To prove this I'm going to prove that I will use the following lines from the code: filterscale = max(1.0, scale)
support = filterp->support * filterscale;
ss = 1.0 / filterscale;
xmin = (int) (center - support + 0.5);
for (x = 0; x < xmax; x++) {
double w = filterp->filter((x + xmin - center + 0.5) * ss);
k[x] = w;
ww += w;
} StartFor
Now we have two branches, first with
|
What did you do?
I created a white image and resized it using
Image.BOX
resampling.What did you expect to happen?
I expected a white image:
What actually happened?
But instead, I got a white image with vertical black lines:
What are your OS, Python and Pillow versions?
I think a good starting point to find this bug would be to check if any of the horizontal filtering coefficients are zero.
The text was updated successfully, but these errors were encountered: