Image: Upscaling with linear interpolation doesn't give expected result

Created on 20 May 2017  路  4Comments  路  Source: image-rs/image

Using the image::FilterType::Triangle filter seems to give incorrect results. I'm assuming that a triangle filter is the same thing as what other software usually calls a "linear" filter, because in the documentation it says "Linear Filter" under that filter type (source: https://docs.rs/image/0.13.0/image/enum.FilterType.html ).

This is the code I run:

extern crate image;
use std::fs::File;
use std::path::Path;

fn main() {
    // Load image.
    let image_path = Path::new("heart.png");
    let img = image::open(&image_path).unwrap();

    // Resize image.
    let width = 1024;
    let height = 1024;
    let filter = image::FilterType::Triangle;
    let img = img.resize_exact(width, height, filter);

    // Write image.
    let output_path = Path::new("output.png");
    let ref mut fout = File::create(&output_path).unwrap();
    let _ = img.save(fout, image::PNG).unwrap();
}

This is my input image:
heart

This is the image that the program outputs:
output

This is the result you get if you upscale the image in GIMP with linear interpolation:
heart_gimp

bug

Most helpful comment

Hi. I recently opened a PR (https://github.com/PistonDevelopers/image/pull/661) to fix some issues with image scaling. I tried running your code with my changes applied to the image library:
output

All 4 comments

Hi. I recently opened a PR (https://github.com/PistonDevelopers/image/pull/661) to fix some issues with image scaling. I tried running your code with my changes applied to the image library:
output

That's awesome, excellent work!

I guess I wait for the PR to get accepted before I close this issue, right?

I think so, yeh.

This was fixed in the latest version https://github.com/PistonDevelopers/image/pull/673

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theotherphil picture theotherphil  路  3Comments

qarmin picture qarmin  路  8Comments

saschanaz picture saschanaz  路  6Comments

martinlindhe picture martinlindhe  路  6Comments

nabijaczleweli picture nabijaczleweli  路  6Comments