[运算] 直方图等化彩图运算

楼主: kuc6811 (Mr.洋芋)   2014-12-06 16:16:58
下面这是一段直方图等化对彩色图像的运算
仅会秀出原图像及修改后图像
请问我要加上什么程式码
才能让程式多秀出等化后的直方图
感谢
sourcePic=imread('1.jpg');
[m,n,o]=size(sourcePic);
figure,imshow(sourcePic,[]);
%grayPic=rgb2gray(sourcePic);
grayPic=sourcePic(:,:,1);
gp=zeros(1,256); %计算各灰阶出现的机率
for i=1:256
gp(i)=length(find(grayPic==(i-1)))/(m*n);
end
newGp=zeros(1,256); %计算新的各灰阶出现的机率
S1=zeros(1,256);
S2=zeros(1,256);
tmp=0;
for i=1:256
tmp=tmp+gp(i);
S1(i)=tmp;
S2(i)=round(S1(i)*256);
end
for i=1:256
newGp(i)=sum(gp(find(S2==i)));
end
newGrayPic=grayPic; %填充各像素点新的灰阶值
for i=1:256
newGrayPic(find(grayPic==(i-1)))=S2(i);
end
nr=newGrayPic;
grayPic=sourcePic(:,:,2);
gp=zeros(1,256); %计算各灰阶出现的机率
for i=1:256
gp(i)=length(find(grayPic==(i-1)))/(m*n);
end
newGp=zeros(1,256); %计算新的各灰阶出现的机率
S1=zeros(1,256);
S2=zeros(1,256);
tmp=0;
for i=1:256
tmp=tmp+gp(i);
S1(i)=tmp;
S2(i)=round(S1(i)*256);
end
for i=1:256
newGp(i)=sum(gp(find(S2==i)));
end
newGrayPic=grayPic; %填充各像素点新的灰阶值
for i=1:256
newGrayPic(find(grayPic==(i-1)))=S2(i);
end
ng=newGrayPic;
grayPic=sourcePic(:,:,3);
gp=zeros(1,256); %计算各灰阶出现的机率
for i=1:256
gp(i)=length(find(grayPic==(i-1)))/(m*n);
end
newGp=zeros(1,256); %计算新的各灰阶出现的机率
S1=zeros(1,256);
S2=zeros(1,256);
tmp=0;
for i=1:256
tmp=tmp+gp(i);
S1(i)=tmp;
S2(i)=round(S1(i)*256);
end
for i=1:256
newGp(i)=sum(gp(find(S2==i)));
end
newGrayPic=grayPic; %填充各像素点新的灰阶值
for i=1:256
newGrayPic(find(grayPic==(i-1)))=S2(i);
end
nb=newGrayPic;
res=cat(3,nr,ng,nb);
figure,imshow(res,[]);

Links booklink

Contact Us: admin [ a t ] ucptt.com