Lazar
Lazar

Reputation: 81

Improve image quality

I need to improve image quality, from low quality to high hd quality. I am using OpenCV libraries. I experimented a lot with GaussianBlur(), Laplacian(), transformation functions, filter functions etc, but all I could succeed is to convert image to hd resolution and keep the same quality. Is it possible to do this? Do I need to implement my own algorithm or is there a way how it's done? I will really appreciate any kind of help. Thanks in advance.

Upvotes: 8

Views: 21384

Answers (4)

duck
duck

Reputation: 2561

+1 to kris stern answer,

If you are looking for practical implementation of super resolution using pretrained model in OpenCV, have a look at below notebook also video describing details.

https://github.com/pankajr141/experiments/blob/master/Reasoning/ComputerVision/super_resolution_enhancing_image_quality_using_pretrained_models.ipynb

https://www.youtube.com/watch?v=JrWIYWO4bac&list=UUplf_LWNn0a9ubnKCZ-95YQ&index=4

enter image description here

Below is a sample code using opencv

model_pretrained = cv2.dnn_superres.DnnSuperResImpl_create()

# setting up the model initialization
model_pretrained.readModel(filemodel_filepath)
model_pretrained.setModel(modelname, scale)

# prediction or upscaling
img_upscaled = model_pretrained.upsample(img_small)

Upvotes: 0

Jeru Luke
Jeru Luke

Reputation: 21243

I used this link for my reference. It has other interesting filters that you can play with.

If you are using C++:

detailEnhance(Mat src, Mat dst, float sigma_s=10, float sigma_r=0.15f)

If you are using python:

dst = cv2.detailEnhance(src, sigma_s=10, sigma_r=0.15)

The variable 'sigma_s' determines how big the neighbourhood of pixels must be to perform filtering.

The variable 'sigma_r' determines how the different colours within the neighbourhood of pixels will be averaged with each other. Its range is from: 0 - 1. A smaller value means similar colors will be averaged out while different colors remain as they are.

Since you are looking for sharpness in the image, I would suggest you keep the kernel as minimum as possible.

Here is the result I obtained for a sample image:

1. Original image:

enter image description here

2. Sharpened image for lower sigma_r value:

enter image description here

3. Sharpened image for higher sigma_r value:

enter image description here

Check the above mentioned link for more information.

Upvotes: 4

Kris Stern
Kris Stern

Reputation: 1350

How about applying Super Resolution in OpenCV? A reference article with more details can be found here: https://learnopencv.com/super-resolution-in-opencv/

So basically you will need to have the Python dependency opencv-contrib-python installed, together with a working version of opencv-python.

There are different techniques for the Super Resolution in OpenCV you can choose from, including EDSR, ESPCN, FSRCNN, and LapSRN. Code examples in both Python and C++ have been included in the tutorial article as well for easy reference.

Upvotes: 3

TDI-India
TDI-India

Reputation: 37

A correction is needed dst = cv2.detailEnhance(src, sigma_s=10, sigma_r=0.15)

using kernel will give error.

Upvotes: 2

Related Questions