2012-03-06 106 views
3

我的問題是如何在MATLAB的中心應用5×5拉普拉斯濾波器?如何在MATLAB中應用濾波器?

我試試這個代碼,但它不工作

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

請給出更多的上下文。在我的例子中,我看不到任何圖像。您是否看過http://www.mathworks.com/help/toolbox/images/ref/fspecial.html上的Matlab文檔?拉普拉斯與8在中心是什麼意思。拉普拉斯在中心有一個-1。 – 2012-03-06 12:38:50

回答

2

按照documentation,您可以使用imfilter應用過濾器:

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

編輯:我只是意識到你問什麼for

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)'); 
+0

如果你把8放在中心,它不再是一個拉普拉斯濾波器... – 2012-03-06 14:00:17

+0

@CharlesBrunet - 當然它不是拉普拉斯算子。雖然這個問題不是很清楚,但根據我的理解,OP詢問了如何在中心應用8個拉普拉斯濾波器。也許標題應改爲「如何應用過濾器」? – zenpoy 2012-03-06 14:11:18

+0

感謝您的幫助...但是,當我在中心應用8拉普拉斯濾波器時,這是錯誤的嗎? – Muna 2012-03-06 17:09:35