Algorithm for clearly scaling images

I know that images can be enlarged using image pyramids. And I know the opencv pyrUp() method can scale images. But, to a certain extent, the image becomes unclear. For example, if we enlarge a small image 15 times from its original size, this is definitely not clear.

Is there any method in OpenCV to enlarge an image but keep the resolution as it is in the original? Or otherwise, any algorithm for this?

Please, help.

+4
source share
6 answers

OpenCV has a Super Resolution module . I did not have the opportunity to try it, but not too sure how it works.

You should check Super Resolution from a single image :

Super resolution methods (SR) can be broadly classified into two families of methods: (i) classical multi-window super resolution (combining images obtained at subpixel offsets) and (ii) resolution (matching training between low and high resolution images from the database). In this article, we propose a single structure for combining these two families of methods.

+4
source

One thing to remember: you cannot pull extra permission out of nowhere. When you enlarge the image, you can either have a blurry, smooth image, or have a sharp, blocky image, or you can have something in between. The best algorithms, which seem to have better performance with specific types of objects, make certain assumptions about the contents of the image, which, if true, can give higher apparent performance, but will be corrupted if these assumptions turn out to be false; there you trade precision for sharpness.

There are several good algorithms for scaling certain types of objects, including pixel art , faces, or text. More general algorithms for sharpening images include blurring masking, edge enhancement, and others, but they all imply specific things about the contents of the image, for example, that the image contains text or that the noisy area will still be noisy (or not) with higher resolution.

A low-resolution shelf-point or sandy sandy pattern will not work very well, and a computer can turn your seascape into something more like a mosh pit. Each scaling algorithm or sharpening filter has a number of costs associated with it.

For the right choice of scaling or sharpening algorithm, context, including sample images, is absolutely necessary.

+8
source

You will most likely want to experiment with different interpolation schemes for your images. OpenCV provides a resize function that can be used with various different interpolation schemes ( docs ). You are most likely trading from blur (for example, in bicubic or bilinear interpolation schemes) with jagged smoothing effects (for example, when interpolating nearest neighbors). I would recommend experimenting with the various schemes that he provides and see which ones give the best results.

Supported interpolation schemes are listed as:

 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 

Wikimedia commons provides this good comparative image for interpolating the nearest neighbor, bilinear and bicubic:

Different interpolation schemes

You can see that when scaling, you are unlikely to get the same sharpness as the original image, but you can exchange โ€œsmoothnessโ€ for smoothing effects (ie, jagged edges).

+4
source

See algorithms for fast image scaling .

First, I will discuss a simple algorithm called the โ€œsmooth Bresenham,โ€ which can best be called interpolating the nearest neighbor on an enlarged grid using the Bresenem algorithm. The algorithm is fast, it provides a quality equivalent to the quality of linear interpolation, and it can scale up and down, but it is suitable only for the scaling factor, which is in a fairly small range. To compensate for this, I further developed a directional interpolation algorithm that can only be scaled up (scaled) with a factor of 2 ร—, but this is done so that it is sharp. This directional interpolation method is quite a bit slower than the smooth Breshenem algorithm, and therefore it is advisable to cache these 2 ร— images after calculation. Caching images with relative sizes that have degree 2, combined with simple interpolation, is actually the third way to scale the image: MIP-mapping.

A related question is Image scaling and rotation in C / C ++ . Alternatively, you can use CImpg .

+3
source

What do you ask comes out of this physics of the universe: in the original image there are simply not enough bits to represent 15 * 15 times more details. Whatever algorithm could come up with the "right information", which is not. He can just find a suitable interpolation. But he will never increase the details.

Despite what happens in many police fictions, obtaining a fingerprint image on a car door handle indicating a panoramic view of the city is completely fake.

+2
source

You can easily zoom in or zoom out to create an image in opencv using the following two functions.

To scale

 pyrUp(tmp, dst, Size(tmp.cols * 2, tmp.rows * 2)); 

To zoom out

 pyrDown(tmp, dst, Size(tmp.cols / 2, tmp.rows / 2)); 

Information about the method can be obtained at the following link:

Zoom out and zoom with OpenCV

+1
source

Source: https://habr.com/ru/post/1485198/


All Articles