2010-06-07 31 views
0
img=imread('img27.jpg'); 

%function rectangle=rect_test(img) 

% edge detection 

[gx,gy]=gradient(img); 

gx=abs(gx); 
gy=abs(gy); 
g=gx+gy; 

g=abs(g); 

% make it 300x300 

img=zeros(300); 

s=size(g); 

img(1:s(1),1:s(2))=g; 

figure; 
imagesc((img)); 
colormap(gray); 
title('Edge detection') 


% take the dct of the image 

IM=abs(dct2(img)); 
figure; 
imagesc((IM)); 
colormap(gray); 
title('DCT') 

% normalize 

m=max(max(IM)); IM2=IM./m*100; 

% get rid of the peak 

size_IM2=size(IM2); 
IM2(1:round(.05*size_IM2(1)),1:round(.05*size_IM2(2))) = 0; 

% threshold 
L=length(find(IM2>20)) ; 


if(L > 60) 
    ret = 1; 
else 
    ret = 0; 
end 
+2

你需要更具體 - 什麼不工作? – 2010-06-07 22:47:28

+0

功能矩形不起作用 – raju 2010-06-07 22:48:52

+1

不工作怎麼樣?你到底做了什麼來調試它? – Donnie 2010-06-07 23:51:46

回答

2

我想這個函數不起作用,如果你取消註釋行function rectangle=rect_test(img)。這很可能是因爲在你的函數中,變量rectangle從未被定義過。可能你想寫ret=rect_test(img)來代替。

+0

這可能會做到這一點。調試時,儘量不要將函數轉換爲腳本。這可能變得非常混亂。 – 2010-06-08 03:30:53