⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 laws.m

📁 Laws texture Energy
💻 M
字号:
function [c] = laws(im1,x,y)
im2=imread('2_cropped512.JPG'); %Image in database
im1=mat2gray(rgb2gray(im1));
im2=mat2gray(rgb2gray(im2));
%-----------------------------------
%Preprocessing
%-----------------------------------
fil = fspecial('average',5);
im1 = im1 - imfilter(im1,fil);
im2 = im2 - imfilter(im2,fil);
%----------------------------------------
%Selection of portions from images to test
%----------------------------------------
im1=im1(1:50,1:50);
im2=im2(1:50,1:50);
%-----------------------------------------
%Preparation of masks
%-----------------------------------------
L5=[1 4 6 4 1];
E5=[-1 -2 0 2 1];
S5=[-1 0 2 0 1];
R5=[1 -4 6 -4 1];
mask(:,:,1)=L5'*E5;
mask(:,:,2)=E5'*L5;
mask(:,:,3)=L5'*S5;
mask(:,:,4)=S5'*L5;
mask(:,:,5)=L5'*R5;
mask(:,:,6)=R5'*L5;
mask(:,:,7)=E5'*E5;
mask(:,:,8)=E5'*S5;
mask(:,:,9)=S5'*E5;
mask(:,:,10)=E5'*R5;
mask(:,:,11)=R5'*E5;
mask(:,:,12)=S5'*S5;
mask(:,:,13)=S5'*R5;
mask(:,:,14)=R5'*S5;
mask(:,:,15)=R5'*R5;
mask(:,:,16)=L5'*L5;
%------------------------------------------
%Applying masks on the images
%------------------------------------------
for i=1:16
    im_masked1(:,:,i)=imfilter(im1,mask(:,:,i));
    im_masked2(:,:,i)=imfilter(im2,mask(:,:,i));
end
%------------------------------------------
%Constructing Texture Energy map
%-----------------------------------------
for i=1:16
    [m n z]=size(im_masked1);
    s = 0;
    for p=8:m-7
         s = s+1;
         t= 0;
        for q=8:n-7
             t = t+1;
            a1=0;
            a2=0;
            for j=p-7:p+7
                for k=q-7:q+7
            a1 = a1 + abs(im_masked1(j,k,i));
            a2 = a2 + abs(im_masked2(j,k,i));
                end
            end
            imeng1(s,t)=a1;
            imeng2(s,t)=a2;
        end
    end
    imengf1(:,:,i)=imeng1;
    imengf2(:,:,i)=imeng2;
end

%-----------------------------------------
%Averaging out symmetric pairs
%-----------------------------------------
imres1(:,:,1)=(imengf1(:,:,1)+imengf1(:,:,2))/2;
imres1(:,:,2)=(imengf1(:,:,3)+imengf1(:,:,4))/2;
imres1(:,:,3)=(imengf1(:,:,5)+imengf1(:,:,6))/2;
imres1(:,:,4)=imengf1(:,:,7);
imres1(:,:,5)=(imengf1(:,:,8)+imengf1(:,:,9))/2;
imres1(:,:,6)=(imengf1(:,:,10)+imengf1(:,:,11))/2; 
imres1(:,:,7)=imengf1(:,:,12);
imres1(:,:,8)=(imengf1(:,:,13)+imengf1(:,:,14))/2; 
imres1(:,:,9)=imengf1(:,:,15);

imres2(:,:,1)=(imengf2(:,:,1)+imengf2(:,:,2))/2;
imres2(:,:,2)=(imengf2(:,:,3)+imengf2(:,:,4))/2;
imres2(:,:,3)=(imengf2(:,:,5)+imengf2(:,:,6))/2;
imres2(:,:,4)=imengf2(:,:,7);
imres2(:,:,5)=(imengf2(:,:,8)+imengf2(:,:,9))/2;
imres2(:,:,6)=(imengf2(:,:,10)+imengf2(:,:,11))/2; 
imres2(:,:,7)=imengf2(:,:,12);
imres2(:,:,8)=(imengf2(:,:,13)+imengf2(:,:,14))/2; 
imres2(:,:,9)=imengf2(:,:,15);

%--------------------------------------------
%Comparison
%--------------------------------------------
[m n p]=size(imres1);
c=0;
for i=1:m
    for j=1:n
      if (imres1(x,y,1)== imres2(i,j,1) && imres1(x,y,2)== imres2(i,j,2)...
      && imres1(x,y,3)== imres2(i,j,3) && imres1(x,y,4)== imres2(i,j,4)... 
      && imres1(x,y,5)== imres2(i,j,5) && imres1(x,y,6)== imres2(i,j,6)...
      && imres1(x,y,7)== imres2(i,j,7) && imres1(x,y,8)== imres2(i,j,8)...
      && imres1(x,y,9)== imres2(i,j,9))
                c=c+1; 
       
        end

    end

end                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -