Skip to content

Fix bicubic stretch interpolation#970

Merged
wiredfool merged 4 commits intopython-pillow:masterfrom
homm:fix-bicubic-stretch
Nov 6, 2014
Merged

Fix bicubic stretch interpolation#970
wiredfool merged 4 commits intopython-pillow:masterfrom
homm:fix-bicubic-stretch

Conversation

@homm
Copy link
Member

@homm homm commented Oct 24, 2014

This fixes incorrect result for Bicubic interpolation in im.stretch, discovered by me in comment: #964 (comment)

The error was in line: https://github.com/python-pillow/Pillow/blob/master/libImaging/Antialias.c#L76
Third item was 8*x while should be 8*a*x (see there).

Scale down before and after PR:
small down b
small down

Scale up before and after PR:
small up bc
small up bc

Source code

# original image
image = Image.open('small.jpg').copy()
image._new(image.im.stretch((117, 77), Image.BICUBIC)).save('small.down.jpg', quality=100)
# make a small copy to enlarge it
image = image.resize((117, 77), Image.ANTIALIAS)
image._new(image.im.stretch((586, 387), Image.BICUBIC)).save('small.up.jpg', quality=100)

@hugovk
Copy link
Member

hugovk commented Oct 24, 2014

Please can you add tests? This bit of code isn't currently covered by any tests and it's good to improve as we go along.

Apt there was an old comment FIXME: double-check this algorithm here :)

@homm
Copy link
Member Author

homm commented Oct 25, 2014

I've found another problem! For some reasons, support radius for upscaling were artificially limited to 0.5. Therefore all the filters gave almost identical results for upscaling (same as last picture above).

Without this limitation:
Bilinear:
small up bl

Bicubic with ɑ = -1.0:
small up bc 10

Lanczos:
small up l

As you can see, ɑ = -1.0 gives pixelated result for upscaling, so I have changed ɑ to -0.5:
small up bc 5

@homm
Copy link
Member Author

homm commented Oct 25, 2014

@hugovk done.

@homm homm mentioned this pull request Oct 26, 2014
@homm
Copy link
Member Author

homm commented Oct 30, 2014

It is better to merge this request before looking at #977

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this to correspond with wikipedia link.

wiredfool added a commit that referenced this pull request Nov 6, 2014
Fix bicubic stretch interpolation
@wiredfool wiredfool merged commit 20be641 into python-pillow:master Nov 6, 2014
@homm homm deleted the fix-bicubic-stretch branch April 27, 2016 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants