Ask Your Question
0

How could do sharpness images?

asked 2019-07-30 12:37:01 -0600

kykodev gravatar image

Hello everyone, I want a sharpness image like a camera. In fact, I find how to blur with cv2.GaussianBlur or cv2.Blur but I want to focus or blur depending on the value that is set. What opencv functions could be done with? I am currently doing it in python and I would like to perform the process as if it were photoshop but I have only found a pillow and it does not give me good results.

I try use:

cv2.GaussianBlur(img,(5,5),0)
cv2.Blur(img, (5,5))

And laplace but i want to do this to color images.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2019-07-31 16:34:33 -0600

Witek gravatar image

This actually also surprised me a few years back - there are blurring filters but not sharpening ones...

One way of sharpening an image is doing this:

Mat sharp;
Mat sharpening_kernel = (Mat_<double>(3, 3) << -1, -1, -1,
        -1, 9, -1,
        -1, -1, -1);
filter2D(img, sharp, -1, sharpening_kernel);

The sharpening strength depends on the values of the kernel which should sum up to 1).

Another way is subtracting a smoothed image from its original:

double sigma=1, amount=1;
Mat blurry, sharp;
GaussianBlur(img, blurry, Size(), sigma);
addWeighted(img, 1 + amount, blurry, -amount, 0, sharp);

Play with blur strength and weights for different results.

If you add the following, you will get unsharp mask algorithm, but the differences are not significant or even none with conservative settings:

Mat lowContrastMask = abs(img - blurry) < 5; //experiment with values
sharp = img*(1+amount) + blurry*(-amount); //this is the same as addWeighted - is addWeightd obsolete??
img.copyTo(sharp, lowContrastMask);

The above code is in C++ but you should be able to translate it to Python easily.

edit flag offensive delete link more
1

answered 2019-08-01 06:00:46 -0600

LBerger gravatar image

You can try detailEnhance

edit flag offensive delete link more

Comments

1

I missed that one :(

Witek gravatar imageWitek ( 2019-08-01 17:24:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-30 12:37:01 -0600

Seen: 13,016 times

Last updated: Aug 01 '19