matlab彩色图像直方图均衡化
程序员文章站
2024-03-08 09:19:10
...
**
参考《数字图像处理基础》p44页直方图均衡化方法,从黑白图像转变彩色图像的均衡化处理
**
I=[1 3 9 9 8
2 1 3 7 3
3 6 0 6 4
6 8 2 0 5
2 9 2 6 0];
[M, N]=size(I);
h=zeros(1,10);
for i=1:M
for j=1:N
h(1,I(i,j)+1)=h(1,I(i,j)+1)+1;
end
end
I2=9*cumsum(h/25);
I2(1,1)=0;
I3=round(I2);
G=size(I);
for i=1:M
for j=1:N
for k=1:10
if (I(i,j)==k-1)
G(i,j)=I3(1,k);
end
end
end
end
按照书上的可知输出的G如书上或下图所示
彩色图像直方图均衡化如下
I=imread('c.jpg');
% f=rgb2gray(I);
% figure
subplot(121);
imshow(I);
[M,N,V]=size(I);
h1=zeros(1,256);
h2=zeros(1,256);
h3=zeros(1,256);
for i=1:M
for j=1:N
h1(1,I(i,j,1)+1)=h1(1,I(i,j,1)+1)+1;
end
end
for i=1:M
for j=1:N
h2(1,I(i,j,2)+1)=h2(1,I(i,j,2)+1)+1;
end
end
for i=1:M
for j=1:N
h3(1,I(i,j,3)+1)=h3(1,I(i,j,3)+1)+1;
end
end
I21=255*cumsum(h1/(M*N));
I21(1,1)=0;
I3(:,:,1)=round(I21);
I22=255*cumsum(h2/(M*N));
I22(1,1)=0;
I3(:,:,2)=round(I22);
I23=255*cumsum(h3/(M*N));
I23(1,1)=0;
I3(:,:,3)=round(I23);
G=size(I);
for i=1:M
for j=1:N
for u=1:V
for k=1:256
if (I(i,j,u)==k-1)
G(i,j,u)=I3(1,k,u);
end
end
end
end
end
G=uint8(G);
subplot(122);
imshow(G);