如何在MATLAB中应用滤波器



我的问题是如何在MATLAB中应用以8为中心的5×5拉普拉斯滤波器?

我尝试了这个代码,但它不工作

kAvg = fspecial('average',[5 5]);
kLap = fspecial('laplacian');

根据文档,您可以使用imfilter应用过滤器:

I = imread('cameraman.tif');
kLap = fspecial('laplacian');
filtered = imfilter(I,kLap,'replicate');
imshow(filtered); title('Filtered Image');

编辑:我刚刚意识到你在要求什么:

I = imread('cameraman.tif');
% simple high pass filter
kLap = [-1, -1, -1;
        -1,  8, -1;
        -1, -1, -1];
filtered_3x3 = imfilter(I,kLap,'replicate');
imshow(filtered_3x3); title('Filtered Image (3x3)');
pause();
% another simple high pass filter
kLap = [-1 -3 -4 -3 -1;
        -3  0  6  0 -3;
        -4  6 20  6 -4;
        -3  0  6  0 -3;
        -1 -3 -4 -3 -1];
filtered_5x5 = imfilter(I,kLap,'replicate');
imshow( filtered_5x5 ); title('Filtered Image (5x5)');

最新更新