阅读背景:

【图像处理】彩色直方图均衡

来源:互联网 
sourcePic=imread('D:\Images\pic_loc70358810205041517.jpg');
[m,n,o]=size(sourcePic);
grayPic=rgb2gray(sourcePic);
figure,imshow(sourcePic);
figure,imshow(grayPic);
 
gp=zeros(1,256); %计算各灰度出现的概率
for i=1:256
	gp(i)=length(find(grayPic==(i-1)))/(m*n);
end
figure,bar(0:255,gp);
title('原图像直方图');
xlabel('灰度值');
ylabel('出现概率');
 
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
figure,bar(0:255,newGp);
title('均衡化后的直方图');
xlabel('灰度值');
ylabel('出现概率');
 
newGrayPic=grayPic; %填充各像素点新的灰度值
for i=1:256
	newGrayPic(find(grayPic==(i-1)))=S2(i);
end
figure,imshow(newGrayPic);sourcePic=imread('D:\Images\pic_loc703



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: