作者jeep168917 (帮帮)
看板MATLAB
标题[问题]对大量图片的处理
时间Sun Oct 30 23:42:37 2011
目前有47张影像
每张影像都要撷取七个特徵
也就是用GLCM,然後求出特徵
小弟,目前只能一张一张影像求出特徵
不知道要如何用for回圈,
还是其他方式可以一次求出这47张影像分别七个特徵值(ENT,ASM,CON,HOM,COR,CLU,DIS)
麻烦版友们帮忙了~感恩
以下是我的程式码,只能求单张影像的特徵值
close all
clear all
X=imread('1.jpg'); %读入影像
c=colormap(gray(256));
nbcol = size(c,1);
I=X;
[cA1,cH1,cV1,cD1] = dwt2(X,'db1');
cod_X = wcodemat(X,nbcol);
cod_cA1 = wcodemat(cA1,nbcol);
cod_cH1 = wcodemat(cH1,nbcol);
cod_cV1 = wcodemat(cV1,nbcol);
cod_cD1 = wcodemat(cD1,nbcol);
dec2d = [cod_cA1,cod_cH1;cod_cV1,cod_cD1];
imshow(double(dec2d)/256)
p2=double(cod_cH1)/256;
p3=double(cod_cV1)/256;
p4=double(cod_cD1)/256;
p2_gray=rgb2gray(p2);
p3_gray=rgb2gray(p3);
p4_gray=rgb2gray(p4);
glcm2 = graycomatrix(p2_gray);
glcm3 = graycomatrix(p3_gray);
glcm4 = graycomatrix(p4_gray);
%pij
P=glcm2/(sum(sum(glcm2)));
%ux
for i=1:8
for j=1:8
U1(i,j)=i*P(i,j);
end
end
Ux=sum(sum(U1));
%uy
for i=1:8
for j=1:8
U2(i,j)=j*P(i,j);
end
end
Uy=sum(sum(U2));
%sigma_x
for i=1:8
for j=1:8
s1(i,j)=sqrt(((i-Ux)^2)*P(i,j));
end
end
sigma_x=sum(sum(s1));
%sigma_y
for i=1:8
for j=1:8
s2(i,j)=sqrt(((i-Ux)^2)*P(i,j));
end
end
sigma_y=sum(sum(s2));
%ENT
E=P.*log(P);
E1=~isnan(E);
E2=E(E1);
ENT=sum(sum(E2));
%ASM
for i=1:8
for j=1:8
A(i,j)=P(i,j)^2;
end
end
ASM=sum(sum(A));
%CON
for i=1:8
for j=1:8
C(i,j)=((i-j)^2)*P(i,j);
end
end
CON=sum(sum(C));
%HOM
for i=1:8
for j=1:8
H(i,j)=(1/(1+(i-j)^2))*P(i,j);
end
end
HOM=sum(sum(H));
%COR
for i=1:8
for j=1:8
C(i,j)=((i*j)*P(i,j)-Ux*Uy)/(sigma_x*sigma_y);
end
end
COR=sum(sum(C));
%CLU
for i=1:8
for j=1:8
C1(i,j)=((i-Ux+j-Uy)^2)*P(i,j);
end
end
CLU=sum(sum(C1));
%DIS
for i=1:8
for j=1:8
D(i,j)=abs(i-j)*P(i,j);
end
end
DIS=sum(sum(D));
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.171.51.7
1F:→ larryeipi:最外面加个回圈就好了吧? 10/31 06:58
2F:→ abc01251:我觉得 你需要 eval + num2str() 然後附上一个回圈 10/31 13:38
3F:推 winse:写成function 在另一个.m档写个回圈呼叫 11/01 08:44