1 function [ ] = histChange( A ) 2 %histChange 此处显示有关此函数的摘要 3 %对输入图像矩阵进行灰度直方图均衡化,若输入为RGB图像矩阵,则自动转换为灰度图像进行处理 4 % 5 [M,N,a]=size(A); 6 if a == 3 7 B=rgb2gray(A); 8 else 9 B=A; 10 end 11 x=0:255; 12 y=zeros(1,256); 13 s=zeros(1,256); 14 subplot(2,2,1); 15 total=0; 16 for k=1:M 17 for p=1:N 18 y(B(k,p)+1)=y(B(k,p)+1)+1; 19 total=total+1; 20 end 21 end 22 23 bar(x,y); 24 y=y/total; 25 for k=1:256 26 for m=1:k 27 s(k)=s(k)+y(m); 28 end 29 end 30 s=s*255; 31 subplot(2,2,2); 32 imshow(B); 33 for k=1:M 34 for p=1:N 35 B((k),(p))=s(B(k,p)+1); 36 end 37 end 38 subplot(2,2,4); 39 imshow(B); 40 u=zeros(1,256); 41 for k=1:M 42 for p=1:N 43 u(B(k,p)+1)=u(B(k,p)+1)+1; 44 end 45 end 46 subplot(2,2,3); 47 bar(x,u); 48 end
转载请注明来源