L7ColWinters
L7ColWinters

Reputation: 1362

OpenCV Image processing

I have an Image that I would like to zoom into and view at high detail. It is of unknown size and mostly black and white with some text on it. When I zoom in the text becomes unreadable and I thought it was to do with not having enough pixels/texels to display so I upscaled the image by a factor of 2. Now that I have scaled it, it is still unreadable.

Then I started to use OpenCV with :

void resizeFirst(){
  Mat src = imread( "../floor.png", 1 );
  Mat tmp;
  resize(src,tmp,Size(),3,3,INTER_CUBIC);
  Mat dst = tmp.clone();
  Size s(3,3);
  //blur( tmp, dst, s, Point(-1,-1) );//homogeneous
  GaussianBlur(tmp, dst, s, 3);//gaussian
  //medianBlur ( tmp, dst, 5 );//median
  //bilateralFilter ( tmp, dst, 5, 5*2, 5/2 );
  addWeighted(tmp, 1.5, dst, -0.5, 0, dst);
  imwrite("sharpenedImage.png",dst);
}

void blurFirst(){
  Mat src = imread( "../floor.png", 1 );
  Size s(3,3);
  Mat dst;
  GaussianBlur(src, dst, s, 3);//gaussian
  addWeighted(src, 2, dst, -1, 0, dst);
  Mat tmp;
  resize(dst,tmp,Size(),3,3,INTER_CUBIC);
  imwrite("sharpenedImage0.png",tmp);
}

and the output is better but the image still isnt sharp. Does anyone have any ideas on how to keep text sharp when zooming into an image?

EDIT: below are sample images.

Original Image

Enhanced Image

The first one is the smaller res original and the second I resized and tried to do gaussian sharpening as per below

Upvotes: 2

Views: 2453

Answers (1)

Abhishek Thakur
Abhishek Thakur

Reputation: 16995

Resize function offers different interpolation methods

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

try all the interpolation methods and use the one that suits you the most. The resize function will however change the aspect ratio of your image.

Upvotes: 2

Related Questions