TwelveMonkeys icon indicating copy to clipboard operation
TwelveMonkeys copied to clipboard

Image position changes depending on the filter used with ResampleOp

Open vpmuli opened this issue 7 years ago • 3 comments

The resulting image seems to move one pixel to right and down when resizing an image with ResampleOp's Lanczos filter. Because of this the right side and the bottom of the image look like that one row of pixels is cut off. The result does not look good with round images like I was using. Triangle filter does not result in the image moving like this. Example code and images below.

BufferedImage input = ImageIO.read(new File("original.png"));
BufferedImageOp resampler = new ResampleOp(50, 50, ResampleOp.FILTER_LANCZOS);
BufferedImage output = resampler.filter(input, null);
ImageIO.write(output, "png", new File("lanczos.png"));

Original: original.png Lanczos: lanczos.png Triangle: triangle.png

vpmuli avatar Aug 12 '17 14:08 vpmuli

Hi vpmuli,

Thanks for reporting!

I'll try to look into it at some point. If you have time to dig a little bit more that would also be great. :-)

-- Harald K

haraldk avatar Aug 14 '17 07:08 haraldk

I don't have the competence to check the algorithms themselves, but I made a test run using all the ResampleOp's filters. Point and quadratic filters behave like triangle and preserve the roundness of the image. All the other filters behave like Lanczos and result in an image that is less round. This makes sense as point, quadratic and triangle have special handling in the code. I don't know is this information at all useful, but it's all I'm able to do.

vpmuli avatar Aug 14 '17 15:08 vpmuli

Thanks!

That will make the debugging a little easier at least! :-)

-- Harald K

haraldk avatar Aug 16 '17 09:08 haraldk