How do I sharpen/refocus an image using only the fspecial and conv2 commands?

6 次查看(过去 30 天)
We are studying simple convolution in my class. So far we have convolved 2 signals and reduced noise from sine waves. Now we've an assignment to refocus an image.
This is my code so far:
x=imread('Sgrayblur.png');
h=
y=conv2(x,h);
subplot(1,2,1),imshow(x);
subplot(1,2,2),imshow(y);
What must I put after 'h='? Is it possible to use fspecial to sharpen without using imfilter or the like?

回答(1 个)

Image Analyst
Image Analyst 2015-4-14
You can use a Laplacian to get a high pass filter, then add it to the original image to sharpen the edges. Of course because convolution is a linear filter, you can simply add the kernels together and do a convolution once. So a 3 by 3 filter for a high boost filter would be:
kernel = [-1, -1, -1; -1, 17, -1; -1, -1, -1]/ 9;
sharpenedImage = conv2(double(grayImage), kernel, 'same');
You can use imfilter() instead of conv2() if you want.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by