Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing image scale and maximizing resolution using opencv?

I've just started looking into OpenCV, I've looked at some similar questions but I haven't found the answers helpful. I have a number of images with the pixel dimensions of 50 wide and 50 heigh (thumb nail size).

I'm slightly confused regarding the following:

Q. By increasing the scale of these images, am I automatically increasing the resolution? Or do I need to be performing another function?

Its essential that I get the maximum resolution possible whilst increasing the scale of the images.

I'm using the below function:

int IncreaseScale()
{
  char *image_name {"./image/my_image.jpg"};
  cv::Mat Image;
  Image = cv::imread(image_name, 1);
  if(!Image.data)
  {
    //Cant find image
    return 0;
  }
  const float rescale_value {4.10}; 
  cv::Mat Image2;
  cv::resize(Image, Image2, cvSize(0, 0), rescale_value, rescale_value);
  return 1;
}
like image 356
Babra Cunningham Avatar asked Mar 10 '23 09:03

Babra Cunningham


2 Answers

As previously stated by people here, using interpolation is very limited when increasing the size of the image. You are using pixels from the previous resolution to guess on what their values are when you increase the resolution of your image. Though the image will be of higher resolution, it won't be any better in quality.

One technique that has been proposed to overcome this is the idea of super resolution. The idea of this is that when you look at a scene, you take several different images looking at different view point. Each image offers some slight differences in information that the other images have not seen before. You determine what's unique about each view point then you combine this information together to make an enhanced stream of images that are of better quality. This unfortunately does not work with a single image as there is no additional information to extract from the stream of images. You can however use multiple images of the same view point. The noise profile that is introduced at the camera sensor should be enough to provide different information to the super resolution algorithm in order to produce an upscaled image of higher quality. In fact, the idea of super resolution is to take several images that are of "low quality" and to create a high quality result by combining their information together into a final image. This idea has been around for some time, not just related to image processing but in various areas of microscopy and imaging in science.

Using just a single image goes into the area of artificially creating super resolution images, which may or may not work depending on the image. Having a stream of images will have a higher probability of success. You can read more details about Super Resolution here: http://www.infognition.com/articles/what_is_super_resolution.html

Fortunately, OpenCV does have a module that implements Super Resolution and it's found in the Super Resolution module. You do need to feed in a series of images and the output will be a series of images that are of higher quality at the desired higher resolution you want.

A code example on how to use the Super Resolution module can be found here on OpenCV's Github repo: https://github.com/opencv/opencv/blob/master/samples/gpu/super_resolution.cpp. Don't be fooled on where the source is located. Even though it's placed under GPU examples, the code is designed to handle both CPU and GPU cases as you can see in the if statements. The code simply takes in a video feed and with a desired resolution, it outputs a super-resolution based result.

like image 96
rayryeng Avatar answered Mar 23 '23 01:03

rayryeng


Yes, this code is effectively doing a 4.1x "digital zoom", so the output image should have resolution 205 x 205, or something like that. When left unspecified, resize uses bilinear interpolation for upsampling. The result will have higher resolution, but will not be any sharper than the original low-resolution image.

like image 20
willem Avatar answered Mar 23 '23 03:03

willem