user458753
user458753

Reputation: 147

image zoom/sharpness in opencv

When i open a image with some gray text on a black background in any image editing software and i zoom in i get "pixel perfect" zoomed in letters.

how can i get the same with opencv??

i tried doing it with cv::resize but that gives very blurry/unsharp results.

on a side note and im probably wrong here but it seems to me that all images tend to get a little blurry/unsharp with opencv?

thanks in advance!

Upvotes: 1

Views: 6424

Answers (1)

Frank Bollack
Frank Bollack

Reputation: 25166

From the docs you can see, that there are several different interpolation methods available for cv::resize():

INTER_NEAREST nearest-neighbor interpolation
INTER_LINEAR bilinear interpolation (used by default)
INTER_AREA resampling using pixel area relation. It may be the preferred method for
image decimation, as it gives moire-free results. But when the image is zoomed, it is
similar to the INTER_NEAREST method
INTER_CUBIC bicubic interpolation over 4x4 pixel neighborhood INTER_LANCZOS4 Lanczos interpolation over 8x8 pixel neighborhood

The bilinear interpolation method that is used by default, tries to smooth the resuling image by "calculating" intermediate pixel values. For your requirements use the nearest-neighbor method (INTER_NEAREST). It simply picks the pixel value closest to the new pixels position.

For a short overview of common interpolation methods take a look at wikipedia.

Upvotes: 9

Related Questions