clear all
data=imread('cameraman.tif');%¶ÁÈëÔʼͼÏñ
data=double(data);%ת»»Êý¾ÝΪdoubleÀàÐÍ
figure(1)
subplot(2,2,1)
imshow(uint8(data));
title('ÔͼÏñ');%Êä³öÔͼÏñ
subplot(2,2,2);
imhist(uint8(data));
title('1DÖ±·½Í¼');%Êä³öͼÏñµÄÖ±·½Í¼
[M N]=size(data);%¼ÆËãͼÏñÏñËØ´óС
[count,x]=imhist(uint8(data));
mima=find(count~=0);
V1=zeros(3);
V2=zeros(3);
U1=zeros(length(mima),3);
V1(1)=mima(round(rand(1)*(length(mima)/6))+1);
V1(2)=mima(round(length(mima)/2+rand(1)*(length(mima)/6))+1);
V1(3)=mima(round(length(mima)*2/3+2*rand(1)*(length(mima)/6))+1);
k=0;
while k==0
for j=1:length(mima)
if abs(mima(j)-V1(2))<abs(mima(j)-V1(1)) & abs(mima(j)-
V1(2))<abs(mima(j)-V1(3))
U1(j,1)=0.0;
U1(j,2)=1.0;
U1(j,3)=0.0;
else
if abs(mima(j)-V1(1))<abs(mima(j)-V1(2)) & abs(mima(j)-
V1(1))<abs(mima(j)-V1(3))
U1(j,1)=1.0;
U1(j,2)=0.0;
U1(j,3)=0.0;
else
if abs(mima(j)-V1(3))<abs(mima(j)-V1(2)) & abs(mima(j)-
V1(3))<abs(mima(j)-V1(1))
U1(j,1)=0.0;
U1(j,2)=0.0;
U1(j,3)=1.0;
end
end
end
end
tp1=0.0;
tp2=0.0;
tp3=0.0;
tp4=0.0;
tp5=0.0;
tp6=0.0;
for j=1:length(mima)
tp1=tp1+count(mima(j))*(mima(j)-1)*U1(j,1);
tp2=tp2+count(mima(j))*U1(j,1);
tp3=tp3+count(mima(j))*(mima(j)-1)*U1(j,2);
tp4=tp4+count(mima(j))*U1(j,2);
tp5=tp5+count(mima(j))*(mima(j)-1)*U1(j,3);
tp6=tp6+count(mima(j))*U1(j,3);
end
评论0