Ask Your Question

Revision history [back]

Get rid of artifacts after png resize

Hello,

Having trouble to correctly resize a png image. For some reason getting black lines on edges where white area meets transparency. Used example from here(https://docs.opencv.org/master/js_geometric_transformations_resize.html) Source Image:

image description

Code:

let src = cv.imread('canvasInput');
let dst = new cv.Mat();
let dsize = new cv.Size(408 * 2, 581 * 2);
// You can try more different parameters
cv.resize(src, dst, dsize, 0, 0, cv.INTER_LANCZOS4);
cv.imshow('canvasOutput', dst);
src.delete(); dst.delete();

Code above results in a resized image with a visible distortion image description

(Png is placed on a white background by default, it's easier to spot the issue this way)

To achieve better quality, I'm using an INTER_LANCZOS4 interpolation algorithm. Changing it to INTER_NEAREST helps to fix this particular image but then I'm losing quality for images with more details. Question is how to get rid of these black lines?

Thank you.

Get rid of artifacts after png resize

Hello,

Having trouble to correctly resize a png image. For some reason getting black lines on edges where white area meets transparency. Used example from here(https://docs.opencv.org/master/js_geometric_transformations_resize.html) here (https://docs.opencv.org/master/js_geometric_transformations_resize.html) Source Image:

image description

Code:

let src = cv.imread('canvasInput');
let dst = new cv.Mat();
let dsize = new cv.Size(408 * 2, 581 * 2);
// You can try more different parameters
cv.resize(src, dst, dsize, 0, 0, cv.INTER_LANCZOS4);
cv.imshow('canvasOutput', dst);
src.delete(); dst.delete();

Code above results in a resized image with a visible distortion image description

(Png is placed on a white background by default, it's easier to spot the issue this way)

To achieve better quality, I'm using an INTER_LANCZOS4 interpolation algorithm. Changing it to INTER_NEAREST helps to fix this particular image but then I'm losing quality for images with more details. Question is how to get rid of these black lines?

Thank you.