Whats wrong with coding

1 visualización (últimos 30 días)
Muhammad Ali Qadar
Muhammad Ali Qadar el 16 de Dic. de 2013
Editada: Muhammad Ali Qadar el 18 de Dic. de 2013
hi , I am trying to implement Image enhancement algorithm Dynamic Quadrant Histogram Equalization Plateau limit
I am trying to implement its first part please have a look on following code whats wrong in this code
clear;
clc;
p=imread('pout.tif');p=p(:,:,1);
h=imhist(p);
[m,n]=size(p);
Pic=zeros(m,n);
N=m*n;
max1=double(max(p(:)));
min1=double(min(p(:)));
aa=p;
ch=cumsum(h);
m0=min1;
m1=floor(0.25*(N));
m2=floor(0.5*(N));
m3=floor(0.75*(N));
m4=max1;
m=[m0 m1 m2 m3 m4];
L=256;
n0=0;
n1=m2*((m1-m0)/(m2-m0));
n2=m2;
n3=((L-1-m2)*((m3-m2)/(m4-m2)))+m2;
n4=L-1;
for j=0:4
a=sum(h(m(j):m(j+1)));
P(j)=a./(m(j+1)-m(j));
P(j)=h(h>P(j)); % clipped Histogram
M(j)=sum(P(m(j):m(j+1))); % total of Clipped histogram
Y(aa==j)=n(j+1)+(n(j+1)-n(j))*(P(j)./M(j)); %Transform function
end
imshow(Y)
following is the link to paper
  2 comentarios
Walter Roberson
Walter Roberson el 16 de Dic. de 2013
How does the output you get differ from your expectation? Are you receiving an error message? What does pout.tif look like?
Muhammad Ali Qadar
Muhammad Ali Qadar el 17 de Dic. de 2013
I am receiving error
Subscript indices must either be real positive integers or logicals.
Error in DQHE (line 32)
a=sum(h(m(jj):m(jj+1)));
Pout.tif should be somewhat enhanced than from original image in brightness and contrast. And actually I am not receiving output but error.

Iniciar sesión para comentar.

Respuestas (2)

David Sanchez
David Sanchez el 17 de Dic. de 2013
In your code
for j=0:4
a=sum(h(m(j):m(j+1)));
...
...
the index starts at j=0, which is not matlab's way of handling an array. It should start in 1.
m(j) for j=0, will return an error since m(0) (the 0th element of the array) does not exist.
  3 comentarios
Image Analyst
Image Analyst el 17 de Dic. de 2013
You will find out after you look at this. Basically it's saying that m is negative, zero, or have some fractional part and that it's not strictly integers like it should be. I don't know why - I didn't run the code - but you will after you look at the link I gave and step through your code line by line and examine variables.
Muhammad Ali Qadar
Muhammad Ali Qadar el 17 de Dic. de 2013
Editada: Muhammad Ali Qadar el 17 de Dic. de 2013
Thanks for The video, I try it but I can not figure it out
m=[25,15500,31000,46500,255]
for jj=1:length(m)
a=sum(h(m(jj:jj+1));
infact following equation in the paper
here m is the above matrix and h is the input histogram if I debug it is like that I am accessing element that is out of bounds e.g. h(53334) where numel(h)=255. So How can I solve this issue please see where I am wrong

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 17 de Dic. de 2013
Editada: Image Analyst el 17 de Dic. de 2013
OK, that's a different error than you originally had. If h is the histogram, then h has only 256 bins (elements). So why are you trying to set m=[25,15500,31000,46500,255]???? There is no 15500 bins so why are you trying to access it?
Try this:
m0=min1;
m1=floor(0.25*(max1-min1)+min1);
m2=floor(0.5*(max1-min1)+min1);
m3=floor(0.75*(max1-min1)+min1);
m4=max1;
  3 comentarios
Image Analyst
Image Analyst el 17 de Dic. de 2013
Try this:
m0=min1;
m1=floor(0.25*(max1-min1)+min1);
m2=floor(0.5*(max1-min1)+min1);
m3=floor(0.75*(max1-min1)+min1);
m4=max1;
Muhammad Ali Qadar
Muhammad Ali Qadar el 18 de Dic. de 2013
Editada: Muhammad Ali Qadar el 18 de Dic. de 2013
Analyst, can also see this that am I writing wrong or right here for the following
first Equation is for clipping the histogram, second is the transform function, and third is the total of clipped histogram
for jj=1:5
a=a+h(m(jj));
P(jj)=a./(m(jj));
h(h(jj)>P(jj))=P(jj); % Clipped Histogram
M(jj)=sum(h(h(jj)>P(jj)));%total of Clipped histogram
aa(p==jj)=n(jj)+(n(jj)-n(jj))*(P(jj)./M(jj)); %Transform function
end
following images are resultant if I do it with above coding I think Something Still wrong with my code first one Original and Last Equalized with algorithm,
However accoding paper result should be like this

Iniciar sesión para comentar.

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by