“crisp” is somewhat ambiguous here. “crisp” is usually a desirable quality, the opposite of “blurry”. when you speak of jagged/aliased lines, “crisp” is not the word you should use if you want to get your point across.
OpenCV does blend with a borderValue
. the default is 0, so the image would have nice antialiased edges against black background.
I think the javascript variant of OpenCV deals with RGBA images usually… so an all-zero borderValue
would represent transparent black. you need to try transparent white, i.e. (255,255,255,0)
. that, blended with the source image, looks better against white background.
OpenCV is not alpha-aware. it does not understand alpha blending, or what an image needs to be like to be alpha-blendable. it merely does interpolation on all channels.
the issue is that in these edge pixels, “background” shouldn’t be mixed in. only the alpha channel should change. OpenCV doesn’t do that, it mixes all channels. that means, whatever borderValue
you have, will get mixed into those edge pixels.
that is why you got some black shining through in those edge pixels.
some python, not sure if that’s illuminating or not. just imagine that this happens to BOTH the alpha channel AND the color channels.
>>> im = np.full((4,4), 99, 'uint8'); M = np.eye(3); M[0:2,2] = (2.5,2.5); cv.warpAffine(src=im, dsize=(10,10), M=M[:2])
array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 25, 50, 50, 50, 25, 0, 0, 0],
[ 0, 0, 50, 99, 99, 99, 50, 0, 0, 0],
[ 0, 0, 50, 99, 99, 99, 50, 0, 0, 0],
[ 0, 0, 50, 99, 99, 99, 50, 0, 0, 0],
[ 0, 0, 25, 50, 50, 50, 25, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
>>> im = np.full((4,4), 99, 'uint8'); M = np.eye(3); M[0:2,2] = (2.5,2.5); cv.warpAffine(src=im, dsize=(10,10), M=M[:2], borderMode=cv.BORDER_CONSTANT, borderValue=99)
array([[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
[99, 99, 99, 99, 99, 99, 99, 99, 99, 99]], dtype=uint8)