Ask Your Question
0

Get rid of artifacts after png resize

asked 2020-03-22 09:54:29 -0600

borington gravatar image

updated 2020-03-22 12:36:11 -0600

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_geo...) 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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-22 10:28:54 -0600

mvuori gravatar image

You have tried the best and worst algorithms for generic use. The Laczos may have a problem, but most often the bicobic INTER_CUBIC is practically pretty much similar, so I'd try that. Indeed, photographers often use INTER_LINEAR, as it often holds details best when downsizing.

edit flag offensive delete link more

Comments

Hi, thanks for the advice. With INTER_CUBIC, INTER_CUBIC, INTER_AREA I'm getting a similar result distortion is still visible INTER-CUBICINTER-LINEAR

borington gravatar imageborington ( 2020-03-22 10:40:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-22 09:54:29 -0600

Seen: 836 times

Last updated: Mar 22 '20