unknown@wiki 【MATLAB】 edge_mapの関数


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

%To make edge maps

function y = edge_fnc(x);
%C=edge_fnc(imread('51.pgm'));


B=double(x);
[xsize,ysize] = size(B);


H = [  0  0  0  0  0 ;
       1  1  1  1  1 ;
       0  0  0  0  0 ;
      -1 -1 -1 -1 -1 ;
       0  0  0  0  0 ;
    ];

P45 = [  0  0  0  1  0 ;
         0  1  1  0 -1 ;
         0  1  0 -1  0 ;
         1  0 -1 -1  0 ;
         0 -1  0  0  0 ;
      ];

V = [ 0  1  0 -1  0 ;
      0  1  0 -1  0 ;
      0  1  0 -1  0 ;
      0  1  0 -1  0 ;
      0  1  0 -1  0;
    ];

M45 = [ 0  1  0  0  0 ;
       -1  0  1  1  0 ;
        0 -1  0  1  0 ;
        0 -1 -1  0  1 ;
        0  0  0 -1  0 ;
      ];

fil(:,:,1) = filter2(H,B);
fil(:,:,2) = filter2(P45,B);
fil(:,:,3) = filter2(V,B);
fil(:,:,4) = filter2(M45,B);

feature(:,:,1) = abs(fil(3:xsize-2,3:ysize-2,1));
feature(:,:,2) = abs(fil(3:xsize-2,3:ysize-2,2));
feature(:,:,3) = abs(fil(3:xsize-2,3:ysize-2,3));
feature(:,:,4) = abs(fil(3:xsize-2,3:ysize-2,4));

diffrow = abs(filter2([1 -1],B));
diffcol = abs(filter2([1 ;-1],B));
      trimBrow = zeros(5,4,3,3);
      trimBcol = zeros(4,5,3,3);

for i = 1 : xsize-4,
    for j = 1 : ysize-4,
        trimBrow(:,:,i,j) = (diffrow(i:i+4,j:j+3));
        trimBcol(:,:,i,j) = (diffcol(i:i+3,j:j+4));
        diff_sort(1,:,i,j) = sort([trimBrow(1,:,i,j) trimBrow(2,:,i,j) trimBrow(3,:,i,j) trimBrow(4,:,i,j) trimBrow(5,:,i,j) trimBcol(1,:,i,j) trimBcol(2,1:5,i,j) trimBcol(3,1:5,i,j) trimBcol(4,1:5,i,j)]);
        th(i,j) = 5*diff_sort(1,20,i,j);
    end;
end;
       
label=0;
mxvl=0;
for i=1:xsize-4;
    for j=1:ysize-4;  
        wta(:,:,i,j)=[feature(i,j,1),feature(i,j,2),feature(i,j,3),feature(i,j,4),th(i,j)];
        [mxvl(1,1,i,j),label(1,1,i,j)]=max(wta(:,:,i,j));
        wta_sort(:,:,i,j)=sort(wta(:,:,i,j));
          if wta_sort(1,5,i,j)==wta_sort(1,4,i,j);
               label(1,1,i,j)=5;
          end
    end
end

fbitmap=zeros(xsize-4,ysize-4);

for i=1:xsize-4
for j=1:ysize-4                 
        if label(1,1,i,j)==1
            fbitmap(i,j,1)=1;
        elseif label(1,1,i,j)==2
            fbitmap(i,j,2)=1;
        elseif label(1,1,i,j)==3
            fbitmap(i,j,3)=1;
        elseif label(1,1,i,j)==4
            fbitmap(i,j,4)=1;
        end       
    end
end

y=fbitmap;