看看这个吧希望有帮助!
clear all
close all
clc
%计算图像的梯度
[I,map]=imread('C:\Users\Administrator\Pictures\12345.jpg'); %读入图像
imshow(I,map); %显示原图像
I=double(I) %转换为double类型
[Gx,Gy]=gradient(I); % 计算梯度
G=sqrt(Gx.*Gx+Gy.*Gy); % 水平垂直差分
J=I;
K=find(G>=7); %指定灰度级
J(K)=0;
figure,imshow(J,map); % 显示处理后的图像
%计算图像的标准差
I1=rgb2gray(I); %彩色图像
A=mean(mean(mean(I)));
I2=double(I);
C=std(I2(:)) %灰度图像
B=mean(mean(I1));
I2=double(I1);
D=std(I2(:))
%计算图像的熵
%随机生成图像
[M,N]=size(I);
temp=zeros(1,256);
%对图像的灰度值在[0,255]上做统计
for m=1:M;
for n=1:N;
if I(m,n)==0;
i=1;
else
i=I(m,n);
end
temp(i)=temp(i)+1;
end
end
temp=temp./(M*N);
%由熵的定义做计算
result=0;
for i=1:length(temp)
if temp(i)==0;
result=result;
else
result=result-temp(i)*log2(temp(i));
end
end
result
%计算图像的峰态
[m,n]=size(I);
mean=mean2(I);
for i=1:1:m
for j=1:1:n
sum(i,j)=(I(i,j)-mean).^4;
end
end
meanx=mean2(sum);
stdx=std2(I);
ratio=meanx/stdx
close all
clear all
clc;
I=imread('C:\Users\Administrator\Pictures\lalala.jpg');
%I=rgb2gray(I); %% if the input image is RGB form.
%I=I(1:128,1:128); %% derive a small one just for demo
p=im2double(I);
w=15;
P=wextend('2D','sym',p,(w-1)/2); %I=wextend('2D','sys',I,[w/2-1/2,w/2-1/2]); this is used for odd size window %扫描窗口的大小15*15,为之后程序方便找中心点可以将窗口设置成4*4-32*32之间的任何奇数窗口
%
%s=4; %this variable is used for setting the range of the distance between i and j,remember don't set s a too big num.
%A=zeros(s,1);
%B=(1:s)';
%offsets1 = [A B;-B B;-B A;-B -B]; %% sets the directions and distance within the pexil i and j
%
offsets1=[0 1]; %水平单步
%
[m,n]=size(P);
P1=zeros(m,n); %定义5个矩阵用于存放由graycomatrix产生的5个参数
P2=zeros(m,n); %这样就能够再执行完一次操作后,利用得到的各种特征参数矩阵分别去聚类分割
P3=zeros(m,n); %这样总的耗时短,不用每次都重新执行扫描窗口和共生矩阵来产生特征参数(这个最耗费时间)
P4=zeros(m,n);
P5=zeros(m,n);
for i=(w+1)/2:m-(w-1)/2
for j=(w+1)/2:n-(w-1)/2
W=zeros();
W=P(i-(w-1)/2:i+(w-1)/2,j-(w-1)/2:j+(w-1)/2);
[glcms,SI] = graycomatrix(W,'NumLevels',8,'G',[],'offset',offsets1);
stats = graycoprops(glcms,'all');
Con=[stats.Contrast];
H=[stats.Homogeneity];
Cor=[stats.Correlation];
Ee=[stats.Energy];
eigenvalue=mean(Con);
P1(i,j)=eigenvalue;
P2(i,j)=mean(H);
P3(i,j)=mean(Cor);
P4(i,j)=mean(Ee);
P5(i,j)=mean(En);
end
end
%
I2=I15((w+1)/2:m-(w-1)/2,(w+1)/2:n-(w-1)/2);
ma=max(I2(:));
mi=min(I2(:));
I3=(I2-mi)/(ma-mi);
I3=im2double(I3);