This example shows how to create filters using the
fspecial function that can be used with imfilter. The
fspecial function produces several kinds of predefined filters, in the form of correlation kernels. This example illustrates applying an unsharp masking filter to a grayscale image. The unsharp masking filter has the effect of making edges and fine detail in the image more crisp.
I = imread('moon.tif');
Create filter, using
h = fspecial('unsharp')
h = 3×3 -0.1667 -0.6667 -0.1667 -0.6667 4.3333 -0.6667 -0.1667 -0.6667 -0.1667
Apply filter to image using
I2 = imfilter(I,h);
Display original image and filtered image for comparison.
imshow(I) title('Original Image')
figure imshow(I2) title('Filtered Image')