• 大小: 3KB
    文件类型: .m
    金币: 2
    下载: 1 次
    发布日期: 2021-09-14
  • 语言: Matlab
  • 标签:

资源简介

计算图像水平方向,垂直,对角线方向的相关性,并绘制二维图,

资源截图

代码片段和文件信息

clear all;



%{

[filename pathname filter]=uigetfile(‘*.*‘‘图像文件‘);
if  filter==0
    return 
end 
img=fullfile(pathnamefilename);
a=imread(img);

%}
a=[0255; 0255]; 
[hw]=size(a)
%[hwc]=size(a);

%水平方向相关性分析  
for k=1:1000
    i=fix(rand*(w-1))+1;%i的取值范围为[0w-1]
    j=fix(rand*w)+1;   %j的取值为[0w]
    x(k)=a(ij);%
    y(k)=a(i+1j);
end
sum=0.0;
sum=double(sum);
for i=1:1000
    sum=sum+double(x(i));
end
ex=sum/1000;%求均值E(x)
sum=0.0;
sum=double(sum);
for i=1:1000
    sum=sum+double(y(i));
end
ey=sum/1000;%求均值E(y)
sum=0.0;
sum=double(sum);
for i=1:1000
    sum=sum+(double(x(i))-double(ex))*(double(x(i))-double(ex));
end
dx=double(sum/1000);
sum=0.0
sum=double(sum);
for i=1:1000
    sum=sum+(double(y(i))-double(ey))*(double(y(i))-double(ey));
end
dy=double(sum/1000);
sum=0.0
sum=double(sum);
for i=1:1000
    sum=sum+double(double(x(i))-double(ex))*double(double(y(i))-double(ey))
end
cov=double(sum/1000);
rela=cov/(sqrt(dx)*sqrt(dy));
rela

%绘制相关性分析图
figure
plot(xy‘.‘‘MarkerSize‘4);%marker是图上画上点的地方标上符号,size指标号的大小
xlabel(‘像素值(xy)‘);
ylabel(‘像素值(x+1y)‘);

%{
 %垂直方向相关性分析
for k=1:1000
    i=fix(rand*h)+1;
    j=fix(rand*(h-1))+1;
    x(k)=a(ij);
    y(k)=a(ij+1);
end
sum=0.0;
sum=double(sum);
for i=1:1000
    sum=sum+double(x(i));
end

ex=sum/1000;
sum=0.0;
sum=double(sum);
for i=1:1000
    sum=sum+double(y(i));
end
ey=sum/1000;
sum=0.0;
sum

评论

共有 条评论