clc
close all
Img1=imread('C1R1EAID.TIF');
Img=Img1(1:512,1:512);
%图像分成mxn块
m1=16;
n1=16;
[sample_h sample_w]=size(Img);%读入图像的高和宽 512 512
sample_h
sample_w
region_h=floor(sample_h/m1);%每个区域的高 32
region_w=floor(sample_w/n1);%每个区域的宽 32
plot_num=1;
figure
imshow(Img)
title('原图像')
Img2 = zeros(512,512);
for i2 = 1:sample_h
for j2 = 1:sample_w
for n = 1:256/16
if (n-1)*16<=Img(i2,j2)&Img(i2,j2)<=(n-1)*16+15
Img2(i2,j2) = n-1;
end
end
end
end
figure
for i=1:m1
for j=1:n1
temp=Img2((i-1)*region_h+1:i*region_h,(j-1)*region_w+1:j*region_w);%每个区域的信息
subplot(16,16,plot_num);
imshow(uint8(temp))
P = zeros(16,16);
for m2 = 1:16
for n2 = 1:16
for i1 = 1:32
for j1 = 1:32
if j1<32&temp(i1,j1)==m2-1&temp(i1,j1+1)==n2-1
P(m2,n2) = P(m2,n2)+1;
P(n2,m2) = P(m2,n2);
end
end
end
if m2==n2
P(m2,n2) = P(m2,n2)*2;
end
end
end
P(:,:) = P(:,:)/sum(sum(P(:,:)));
E(plot_num) = sum(sum(P(:,:).^2));
E(plot_num)
if E(plot_num)<0.3000
Img((i-1)*region_h+1,(j-1)*region_w+1:j*region_w)=255;
Img(i*region_h,(j-1)*region_w+1:j*region_w)=255;
Img((i-1)*region_h+1:i*region_h,(j-1)*region_w+1)=255;
Img((i-1)*region_h+1:i*region_h,j*region_w)=255;
end
plot_num=plot_num+1;
end
end
figure
imshow(Img)下载本文