image icon indicating copy to clipboard operation
image copied to clipboard

Resize using FilterType::Lanczos3 produces unexpected artifacts

Open ojensen5115 opened this issue 5 years ago • 3 comments

This happens when using image = "0.22.3".

Begin with a 75x70 reference image edge.png: edge

Resize edge.png to 45x42 with the Lanczos3 filter using ImageMagic to produce edge-im.png: edge_im

Resize edge.png to 45x42 with the Lanczos3 filter using image-rs to produce edge-imagers.png: edge-imagers

Expected

Images edge-im.png and edge-imagers.png should look the same.

Actual behaviour

The image produced by image-rs contains a significant artifacting around the edge. This is most easily seen in the upper half of the resulting images. I've zoomed in on the same section of both images here:

edge-im.png: edge-im-zoom

edge-imagers.png edge-imagers-zoom

Reproduction steps

To resize the image using ImageMagick, I used the following command: convert edge.png -resize 45x42 -filter Lanczos edge_im.png

To resize the image using image-rs, I used the following code:

extern crate image;

use image::imageops::FilterType::Lanczos3;

fn main() {
    let mut image = image::open("edge.png").unwrap().to_rgba();
    image = image::imageops::resize(&image, 45, 42, Lanczos3);
    match image.save("edge-imagers.png") {
        Ok(()) => eprintln!("image written"),
        Err(e) => eprintln!("failed to write image: {}", e),
    }
}

ojensen5115 avatar Jan 17 '20 14:01 ojensen5115

Is this maybe the same bug as #862?

JulianGaibler avatar Jan 21 '20 14:01 JulianGaibler

Reading through #862, It's possible.

I experimented with the various resize filters and only noticed the discrepancy with Lanczos3, and my assumption (in particular based on the "edge-hardening" effect visible above) was that the algorithm used was incorrect. That said, it's possible I just didn't notice the discrepancy on the others, as I was most interested in using Lanczos3 anyway.

ojensen5115 avatar Jan 21 '20 15:01 ojensen5115

I recall getting a similar edge-hardening effect out of GIMP 2.8. I actually considered it a desirable property of sinc+lanczos3 filter.

Shnatsel avatar Feb 08 '20 20:02 Shnatsel