brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.17k stars 265 forks source link

Add lanczos interpolation #292

Open CaptainDario opened 3 years ago

CaptainDario commented 3 years ago

Hello, I really like this library and it already helped me a lot.

However currently I am trying to down sample a black and white image of lines. In this case the cubic down sampling sometimes makes "holes" in those lines. From the Pillow python library I know that this is not the case with their Lanczos implementation.

Looking at this article the difference becomes very clear. Untitled

Therefore it would be very nice to have this interpolation method.

brendan-duncan commented 3 years ago

Lanczos is a pretty heavy method, it might be a bit slower with Dart, but if you provide an explicit example image and the arguments you're using for downsizing that's causing the not great results, I can take a look at it.

CaptainDario commented 3 years ago

@brendan-duncan thank you for looking at this! I think I could get away with using average interpolation but lanczos would be the best.

From this base image:

I get these results.

The code I am using is this:

image.Image base = image.decodeImage(await getImageFromCanvas());
image.Image resizedImage = image.copyResize(base,
      height: 64, width: 64, interpolation: image.Interpolation.average);
Uint8List resizedBytes = resizedImage.getBytes(format: image.Format.luminance);
String test = resizedBytes.toString();

I added the images and a jupyter notebook to show the images to this reply.

comparison.zip