Main Content

Filter Images Using Predefined Filter

This example shows how to create a predefined Laplacian of Gaussian (LoG) filter using the fspecial function and apply the filter to an image using the imfilter function. A LoG filter highlights regions with rapidly varying intensities and reduces the impact of variations caused by noise. The fspecial function produces several additional types of predefined filters in the form of correlation kernels.

Read and display an image.

I = imread('moon.tif');
imshow(I)

Create a 7-by-7 LoG filter with a standard deviation of 0.4 using fspecial.

h = fspecial('log',7,0.4)
h = 7×7

    0.1263    0.1263    0.1263    0.1263    0.1263    0.1263    0.1263
    0.1263    0.1263    0.1263    0.1267    0.1263    0.1263    0.1263
    0.1263    0.1263    0.2333    1.1124    0.2333    0.1263    0.1263
    0.1263    0.1267    1.1124  -10.4357    1.1124    0.1267    0.1263
    0.1263    0.1263    0.2333    1.1124    0.2333    0.1263    0.1263
    0.1263    0.1263    0.1263    0.1267    0.1263    0.1263    0.1263
    0.1263    0.1263    0.1263    0.1263    0.1263    0.1263    0.1263

Apply the filter to the image using imfilter.

I2 = imfilter(I,h);

Display the filtered image.

imshow(I2)

See Also

|

Related Topics