2012-04-18 107 views
-3

我不能得到如何運行它,任何人都可以幫助我這個請。索引超出界限在matlab

我收到此錯誤:

K>> [minutiae_valid]=postprocess_TICO(B,im,~K) 
??? Attempted to access wind(273,386); index out of bounds because size(wind)=[368,385]. 

Error in ==> postprocess_TICO at 214 
if (thinned(p,q)==1)&&(wind(p,q)==0) 

postprocess_Tico

function [minutiae_valid]=postprocess_TICO(minutiae_valid,im1,thinned) 
% clc; 
% close all; 
% clear all; 
cell=16;%total no. of cells needed in quantization; 
% im1= imread('E:\FINGERPRINT DATABASE\FVC2002\Dbs\Db1_a\16_6.tif'); 
wl=(33-1)/2; 
% no=20; 
% no2=20; 
% nox = 0; 
% noy = 0; %to choose border area 
% 
m=size(im1,1); 
n=size(im1,2); 
%m=(round(m/cell))*cell; 
%n=(round(n/cell))*cell; 
% im1=imresize(im1,[m n]); 
% im=double(im1); 
% figure; 
% subplot(1,2,1); 
% imshow(uint8(im)); 
% title('original input image'); 
% 
% %Identify ridge-like regions and normalise image-------------------------- 
% blksze = 10; 
% thresh =30; 
% M0=100; 
% STD0=150; 
% [thinim, mask] = imgenhance(im, blksze, M0, STD0); 
% subplot(1,2,2); subimage((thinim)); 
% title('Improved thinned input image', 'FontSize', 12); 
% INPUT_IMG=thinim; 
% 
% %minutiae extraction 
% thinned= INPUT_IMG; 
% img = INPUT_IMG; 
% [minutiae, minutiae_img, combined] = findminutiae(thinned, img); 
% totminu_I = size(minutiae,1) 
% figure, 
% subplot(1,2,1), subimage(combined), title('minutiae before postprocess.') 
% %______________________________________________________________ 
% %TO FIND BOUNDARY OF INPUT IMAGE AS WELL AS REGION OF FALSE MINU 
% mask_input=mask; 
% border=uint8(zeros(m,n)); 
% 
% [m,n]=size(mask); 
%  validr=uint8(zeros(m,n)); 
%  thin_temp=thinned; 
%  for i=1:m 
%   for j=2:n-1 
%    if((mask_input(i,j-1)==0)&&(mask_input(i,j)==1)&&(j<=n-no)) 
%      border(i,j)=1; 
%     validr(i,j-nox:j+no)=1; 
%      thin_temp(i,j-nox:j+no)=1; 
%    end 
%     
%    if ((mask_input(i,j+1)==0)&&(mask_input(i,j)==1)&&(j>no)) 
%      border(i,j)=1; 
%     validr(i,j+nox:-1:j-no)=1; 
%     thin_temp(i,j+nox:-1:j-no)=1; 
%    end 
%     
%   end 
%  end 
% 
%   for i=1:m 
%   for j=1:n-1:n 
%    if (mask_input(i,j)==1) 
%     if (j==1) 
%      border(i,j)=1; 
%     validr(i,j:j+no)=1; 
%     thin_temp(i,j:j+no)=1; 
%     end 
%     if (j==n) 
%      border(i,j)=1; 
%     validr(i,j:-1:j-no)=1; 
%     thin_temp(i,j:-1:j-no)=1; 
%     end 
%    end 
%   end 
%   end 
%  
%   
%   
% for j=1:n 
%   for i=2:m-1 
%    if((mask_input(i-1,j)==0)&&(mask_input(i,j)==1)&&(i<=m-no)) 
%      border(i,j)=1; 
%     validr(i-noy:i+no,j)=1; 
%      thin_temp(i-noy:i+no,j)=1; 
%    end 
%    if((mask_input(i+1,j)==0)&&(mask_input(i,j)==1)&&(i>no)) 
%      border(i,j)=1; 
%      validr(i+noy:-1:i-no,j)=1; 
%      thin_temp(i+noy:-1:i-no,j)=1; 
%    end 
%     
%   end 
% end 
% 
% for j=1:n 
%   for i=1:m-1:m 
%    if (mask_input(i,j)==1) 
%    if (i==1) 
%      border(i,j)=1; 
%     validr(i:i+no,j)=1; 
%     thin_temp(i:i+no,j)=1; 
%    else validr(i:-1:i-no,j)=1; 
%     thin_temp(i:-1:i-no,j)=1; 
%    end 
%    end 
%   end 
% end 
% 
% %___________________________________________________________________ 
% % removing minu at the border of roi 
% for x=1:size(thinned,1) 
% for y=1:size(thinned,2) 
%   if ((validr(x,y)==1)&&(thinned(x,y)==1)) 
%    combined(x,y,:)=[255,255,255]; 
%    minutiae_img(x,y,:)=[0,0,0]; 
%    
%   end 
% end 
% end 
%  
% for i=1:totminu_I 
%  x=minutiae(i,1); 
%  y=minutiae(i,2); 
%  if ((validr(x,y)==1)&&(thinned(x,y)==1)) 
%   minutiae(i,:)=0; 
%  end 
% end 
% %__________________________ 
% 
% subplot(1,2,2), subimage(combined), title('after boundary effect ') 
% minu_count=1; 
% minutiae_valid(minu_count, :) = [0,0,0,0]; %to make x, y, CN, theta value of minutiae not in border region. 
% for i=1:totminu_I 
%  CN=minutiae(i,3); 
%  if (CN~=0) 
%   minutiae_valid(minu_count, :) = minutiae(i,:); 
%   minu_count = minu_count + 1; 
%  end 
% end 

% totminu_I= minu_count-1; 


k=size(minutiae_valid); 
totminu_I=k(1,1); 
%FALSE RIDGE BIFURCATION 
for i=1:totminu_I 
if minutiae_valid(i,3)==3 
      wind=ones(m,n); 
     xi= minutiae_valid(i,1); 
     yi=minutiae_valid(i,2); 
     x=xi; 
     y=yi; 
     wind(xi-wl:xi+wl,yi-wl:yi+wl)=0; %window of size 25 cross 25 
     wind(xi,yi)=-1; 

     %mark '1', '2', '3'. 
     value=0; 

     r=x-1; 
     for c=y-1:y+1 
      if (thinned(r,c)==1)&&(wind(r,c)==0) 
       value=value+1; 
       wind(r,c)=value; 
      end 
     end 

     c=y+1; 
     for r=x-1:x+1 
      if (thinned(r,c)==1)&&(wind(r,c)==0) 
       value=value+1; 
       wind(r,c)=value; 
      end 
     end 

     r=x+1; 
     for c=y+1:-1:y-1 
      if (thinned(r,c)==1)&&(wind(r,c)==0) 
       value=value+1; 
       wind(r,c)=value; 
      end 
     end 

     c=y-1; 
     for r=x+1:-1:x-1 
      if (thinned(r,c)==1)&&(wind(r,c)==0) 
       value=value+1; 
       wind(r,c)=value; 
      end 
     end 


for value=1:3 %search '1'/'2/'3' value pixel arond the minutia point in the window. 
for p=x-1:x+1 
    for q=y-1:y+1 
     if wind(p,q)==value 
      xi=p; 
      yi=q; 
     end 
    end 
end 

cnt=0; 
     while(xi>x-wl)&&(xi<x+wl)&&(yi>y-wl)&&(yi<y+wl) %mark '1'/'2'/'3' to the adjacent connected pixels 
      k=0; 
      for p=xi-1:xi+1 
       for q=yi-1:yi+1 
        if (thinned(p,q)==1)&&(wind(p,q)==0) 
         wind(p,q)=value; 
          k=k+1; 
         if k==1 
          x1=p; 
          y1=q; 
         end 
         if k==2 %more than one connected pixel 
          cnt=cnt+1; 
          x2=p; 
          y2=q; 

          t1=x1; 
          x1=x2; 
          x2=t1; 

          t2=y1; 
          y1=y2; 
          y2=t2; 
          %___________ 
          xi=x2; 
          yi=y2; 

         while(xi>x-wl)&&(xi<x+wl)&&(yi>y-wl)&&(yi<y+wl) 
            k=0; 
            flag_see=0; 
          for p=xi-1:xi+1 

           for q=yi-1:yi+1 

            if (thinned(p,q)==1)&&(wind(p,q)==0) 
              wind(p,q)=value; 
              flag_see=1; 
              x3=p; 
              y3=q; 
              k=k+1;    
            end 
           end 
          end 
          if(flag_see==1) 
          xi=x3; 
          yi=y3; 
          else 
           xi=p; 
           yi=q; 

          end 

           if k==0 
           break 
           end 
          end 
%   xi=x1; 
%   yi=y1; 

         end 
        end 
       end 
      end 
      xi=x1; 
      yi=y1; 
      if k==0 
       break 
      end 
     end 

end 

% figure,subimage(wind); 
%to count 0-1, 0-2, 0-3 transition around the boundary clkwise 
T=1; 
for v=1:3 
     T0v=0; 
     r=x-wl; 
     for c=y-wl:y+(wl-1) 
      if (wind(r,c)==0)&&(wind(r,c+1)==v) 
       T0v=T0v+1; 
      end 
     end 

     c=y+wl; 
     for r=x-wl:x+(wl-1) 
      if (wind(r,c)==0)&&(wind(r+1,c)==v) 
       T0v=T0v+1; 
      end 
     end 

     r=x+wl; 
     for c=y+wl:-1:y-(wl-1) 
      if (wind(r,c)==0)&&(wind(r,c-1)==v) 
       T0v=T0v+1; 
      end 
     end 

     c=y-wl; 
     for r=x+wl:-1:x-(wl-1) 
      if (wind(r,c)==0)&&(wind(r-1,c)==v) 
       T0v=T0v+1; 
      end 
     end 

T1=T0v==1; 
    T=T & T1; 
end 
     if T~=1 
      minutiae_valid(i,:)=[0 0 0 0]; 
      combined(x,y,:)=[255,255,255]; 
     end 

end 
end 


minu_count=1; 
minutiae_valid_final(minu_count, :) = [0,0,0,0]; %to make x, y, CN, theta value of minutiae not in border region. 
for i=1:totminu_I 
    CN = minutiae_valid(i,3); 
    if (CN~=0) 
     minutiae_valid_final(minu_count, :) = minutiae_valid(i,:); 
      minu_count = minu_count + 1; 
    end 
end 

% totminu_I= minu_count-1; 
minutiae_valid = minutiae_valid_final; 

% figure, subimage(combined); 
+2

你不能只是在這裏轉儲你的整個代碼,並期望我們修復它。請創建儘可能最小的測試用例,然後發佈。 – 2012-04-18 17:24:22

+0

@OliCharlesworth @OliCharlesworth我無法得到問題所在,所以只是拋棄了代碼..你可以看看 – 2012-04-18 17:27:42

+7

。堆棧溢出不是讓人們爲你做調試的地方。請首先自己做一些調試,這樣就可以隔離導致問題的簡單的10行代碼。 – 2012-04-18 17:28:41

回答

2

在線路212和213創建嵌套循環在風九個元素循環尋找符合某種條件的元素。當你找到一個,你改變九個元素塊的中心。

問題出現時,您的塊的中心是在風的邊緣。當您查看以邊緣爲中心的九個元素時,您不得以相同的方式訪問索引,否則您將得到如上所述的錯誤。爲了說明的這種簡單的情況下:

a = rand(4,4); 
for p=2:4 
    for q = 1:3 
    tmp += a(p,q) 
    end 
end 

和的(正方形陣列)的9種元素在(3,2)爲中心。

a = rand(4,4); 
for p=3:5 
    for q = 1:3 
    tmp += a(p,q) 
    end 
end 

將產生與您嘗試訪問(5,1)時相同的錯誤,因爲該數組的元素不存在。解決這個問題的正確方法取決於你想要做什麼,但這絕對超出了你的問題的範圍,以及我們弄清楚的能力。

我希望這會有所幫助。

迴應一些評論,我想爲您提供一些建議。在未來,如果您可以將問題歸結爲儘可能短的測試用例,那麼您更有可能獲得滿意的答案,並獲得高質量的答案。這也是調試你自己的代碼的有價值的一步。弄清楚如何構建測試用例通常會使問題的答案顯而易見。當它不明顯時,Stackoverflow是一個很好的資源。