谁有灰度共生矩阵的Matlab代码?
最近在做纹理分析,想用灰度共生矩阵去做,谁有相应的代码?能否给我传一份啊!在此先谢谢了...我的邮箱是:good2006.love@163.com...
最近在做纹理分析,想用灰度共生矩阵去做,谁有相应的代码?能否给我传一份啊!在此先谢谢了...我的邮箱是:good2006.love@163.com
展开
1个回答
展开全部
matlab有相应的函数,可以直接调用。
close all
clear all
clc;
I=imread('F:\图像变化检测\image\Texture image(3.27)\texture5.tif');
%I=rgb2gray(I); %% if the input image is RGB form.
%I=I(1:128,1:128); %% derive a small one just for demo
I=im2double(I);
w=15;
I1=wextend('2D','sym',I,(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(I1);
I11=zeros(m,n); %定义5个矩阵用于存放由graycomatrix产生的5个参数
I12=zeros(m,n); %这样就能够再执行完一次操作后,利用得到的各种特征参数矩阵分别去聚类分割
I13=zeros(m,n); %这样总的耗时短,不用每次都重新执行扫描窗口和共生矩阵来产生特征参数(这个最耗费时间)
I14=zeros(m,n);
I15=zeros(m,n);
for i=(w+1)/2:m-(w-1)/2
for j=(w+1)/2:n-(w-1)/2
W=zeros();
W=I1(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);
I11(i,j)=eigenvalue;
I12(i,j)=mean(H);
I13(i,j)=mean(Cor);
I14(i,j)=mean(Ee);
I15(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);
close all
clear all
clc;
I=imread('F:\图像变化检测\image\Texture image(3.27)\texture5.tif');
%I=rgb2gray(I); %% if the input image is RGB form.
%I=I(1:128,1:128); %% derive a small one just for demo
I=im2double(I);
w=15;
I1=wextend('2D','sym',I,(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(I1);
I11=zeros(m,n); %定义5个矩阵用于存放由graycomatrix产生的5个参数
I12=zeros(m,n); %这样就能够再执行完一次操作后,利用得到的各种特征参数矩阵分别去聚类分割
I13=zeros(m,n); %这样总的耗时短,不用每次都重新执行扫描窗口和共生矩阵来产生特征参数(这个最耗费时间)
I14=zeros(m,n);
I15=zeros(m,n);
for i=(w+1)/2:m-(w-1)/2
for j=(w+1)/2:n-(w-1)/2
W=zeros();
W=I1(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);
I11(i,j)=eigenvalue;
I12(i,j)=mean(H);
I13(i,j)=mean(Cor);
I14(i,j)=mean(Ee);
I15(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);
东莞大凡
2024-11-19 广告
2024-11-19 广告
作为东莞市大凡光学科技有限公司的工作人员,对于halcon标定板有所了解。Halcon标定板是高精度相机标定的关键工具,通常采用实心圆点或方格作为标志点。我们公司提供的halcon标定板,具有高精度、稳定可靠的特点,适用于机器视觉领域的各种...
点击进入详情页
本回答由东莞大凡提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询