histogram (specification or macthing) work but there is a wrong thing
Mostrar comentarios más antiguos
hi
i have this code that do histogram (specification or matching) it work well for some image and for many time there is white block appear
why this happen
here as my result
here is my code
please any help
clc; clear all;
colormap('gray');
%%%requiredhist
img=imread('requiredhist.png');
figure(1);
imshow(img);
img=double(img); %input image
hist1=zeros(1,256);
[m n]=size(img);
for i=1:m
for j=1:n
hist1(img(i,j)+1)=hist1(img(i,j)+1)+1;
end
end
PDF=hist1/(m*n);
CDF(1)=PDF(1);
for k=2:256
CDF(k)=CDF(k-1)+PDF(k);
end
L=256;
x1=imread('light52.png');
figure(2)
imshow(x1);
x0=double(x1); %input image
[m,n]=size(x0);
len=m*n; %number of pixels
x=reshape(x0,len,1); %convert to [len:1]
xpdf=hist(x,[0:L-1]); % pdf, 1 x L
xpdf=xpdf/len;%Normalize it to get nk/n (eq 3.3-7)....(lenis equal to sum(xpdf), number %of pixels...)
sk=xpdf*triu(ones(L));%CDF (eq 3.3-8), (eq 3.3-13)
zk=CDF;
mapping=zeros(256);
z0=zeros(m,n);
for q=1:L
for p=mapping(q)+1:L
if (zk(p)>=sk(q))
mapping(q) = p;
list=find(x0 == q-1); a=size(list);%find value
%in input image
z0(list)=p; %map sk value for each k valued
%pixel
break;
end
end
end
z0=uint8(z0);
figure(3)
imshow(z0);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Histograms en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!