Ask Your Question

Antialiasing in warpPerspective

asked 2016-08-19 09:00:32 -0600

visiBug gravatar image

updated 2016-08-26 05:15:21 -0600

I have noticed that there is a lot of aliasing when I perform downsampling (resize) or distortions on an image (warpPerspective) using any of the interpolation methods.

Is this a limitation of the opencv implementations?

Can someone suggest a method to effectively antialias the images? I have already tried the various interpolation schemes and they do not give any better results. I'm particularly interesting in correcting for the jagged edges in PNG images.

The below image has been creating using the function:

distorted_img = cv2.warpPerspective(input_img, M, (w_dst, h_dst), cv2.INTER_CUBIC | cv2.WARP_INVERSE_MAP, cv2.BORDER_CONSTANT)

Alias example

Edit: Imagemagick and Opencv Comparison image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-19 22:11:38 -0600

Tetragramm gravatar image

Just blur it a bit. Run blur with a 3x3.

You actually are seeing antialiasing in the shrunken image, it's just subtle. Zoom in and you can see it.

edit flag offensive delete link more


I've done that, but the results are still not satisfactory. I want something that mimics how photoshop does these operations - it rasterizes the image then does a resize/reshape of the object without losing the properties. Any chance we can do something like that in OpenCV?

visiBug gravatar imagevisiBug ( 2016-08-24 02:39:28 -0600 )edit

If you use INTER_CUBIC, OpenCV seems to match GIMP's Cubic resize. I don't see what you're talking about.

Tetragramm gravatar imageTetragramm ( 2016-08-24 07:40:53 -0600 )edit

@Tetragramm - thanks for your inputs, I've updated the question. Basically, image quality is very important in the operations I am doing and I'm unable to match the output produced by Imagemagick using the inherent functions. I suspect is has something to do on how the resampling is being done in opencv.

visiBug gravatar imagevisiBug ( 2016-08-26 05:18:21 -0600 )edit

What's the transformation matrix you used so I can test?

Tetragramm gravatar imageTetragramm ( 2016-08-26 16:28:36 -0600 )edit

Question Tools

1 follower


Asked: 2016-08-19 09:00:32 -0600

Seen: 3,364 times

Last updated: Aug 26 '16