I am learning image processing as well as matlab. I have an image
which I read using
origimage=imread('filepath');
Now this has its graylevels clustered together, and so I have written a
code for histogram equalization that should replace each gray level by
some new gray level.
That function is given by say output. So output(128) is the gray level
which should replace the old gray level 128. Now I want to construct
the new image.
Using for loops its easy..
for k=1:1:no_of_points
newimage(k)=output(origimage(k));
end
But when I tried insted -
newimage=output(origimage)
The newimage matrix simply contains 1's and 0's. Can somebody explain
why this happens and an elegant way to optimise the above code.
Thanks a lot.
Moreover, I don't think histogram equalization is really necessary for
analysis. For example, you could pick a threshold on the original
image to find your blobs -- spreading the histogram out doesn't make it
any easier to find a threshold - it merely may pick a different
threshold and make the image easier to see but after thresholding you'd
have the very same blobs either way.
Since it makes the images look crummy and it's not necessary for
thresholding, it doesn't get used at all by me.
The only time (that I've ever encountered) that a specialized form of
histogram equalization may be a useful step is when you want to do
histogram matching - where you want the histogram of one image to match
that of another image. But in that case, you really need to get flat
histograms. The way to do that is to add noise (a uniform 1/2 gray
level) to each pixel before running it through your CDF function. If
you do this, you'll get a virtually flat and continuous histogram, not
one that has the same shape (bin heights) as your original just spread
out strangely. So you find out the transform (the CDF) to make your
"sample" histogram flat. Then you also find the transform to make your
"reference" histogram (the one you are trying to match) flat. Then you
transform your test image to have a flat histogram, then transform that
image using the inverse of the reference transform to take the image
from a flat histogram to one with your reference histogram. Works
pretty well. There are several papers on this.
Regards,
ImageAnalyst
=======================================
On Jan 23, 2:14 pm, "DSP" <dspho...@gmail.com> wrote:
On Jan 24, 8:17 am, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
> > > Thanks a lot.- Hide quoted text -- Show quoted text -
Program:
clear all;
a=imread('filepath');
b=imhist(a);
points=sum(b);
input_pmf=b/points;
output_x(1)=b(1);
for k=2:1:256
output_x(k)=output_x(k-1)+b(k);
end
output_x=max(0,round(output_x*256/points)-1);
c=a;
c(1:points)=output_x(a(1:points));
subplot(2,2,1);imshow(a);
subplot(2,2,2);stem(input_pmf);
subplot(2,2,3);imshow(c);
subplot(2,2,4);stem(output_x,input_pmf);
On Jan 24, 5:51 pm, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
> Yes there is. You must have missed my first message about using
> applylut. Use that. MATLAB has already optimized it for you. No need
> to do it yourself just as there is no need for you to "optimize" the
> "for" statement by delving into the Java, C, or whatever else they
> implemented the "for" macro statement in in MATLAB.
> Regards,
> ImageAnalyst
> ===================================
>
> On Jan 23, 10:37 pm, "DSP" <dspho...@gmail.com> wrote:
>
> > Hi..
> > Thanks for the insight. But still, since I am a undergrad student, it
> > would be better to learn by actually experimenting.
> > So, is there a way to optimise this code and avoid using the for loop?
>
> > On Jan 24, 8:17 am, "ImageAnalyst" <imageanal...@mailinator.com>
> > wrote:
>
> > > Just a side note: In my 27 years of image analysis I can't recall ever
> > > having simplehistogramequalization being really useful. It merely
> > > distributes the gray levels in a way that non-linearly spreads out the
> > >histogrambut doesn't flatten it and it usually produces an image that
> > > doesn't look good. Almost always (or maybe always) you get a better
> > > looking image just using linearhistogramstretching rather than simple
> > >histogramequalization.
>
> > > Moreover, I don't thinkhistogramequalization is really necessary for
> > > analysis. For example, you could pick a threshold on the original
> > > image to find your blobs -- spreading thehistogramout doesn't make it
> > > any easier to find a threshold - it merely may pick a different
> > > threshold and make the image easier to see but after thresholding you'd
> > > have the very same blobs either way.
>
> > > Since it makes the images look crummy and it's not necessary for
> > > thresholding, it doesn't get used at all by me.
>
> > > The only time (that I've ever encountered) that a specialized form of
> > >histogramequalization may be a useful step is when you want to do
> > >histogrammatching - where you want thehistogramof one image to match
> > > that of another image. But in that case, you really need to get flat
> > > histograms. The way to do that is to add noise (a uniform 1/2 gray
> > > level) to each pixel before running it through your CDF function. If
> > > you do this, you'll get a virtually flat and continuoushistogram, not
> > > one that has the same shape (bin heights) as your original just spread
> > > out strangely. So you find out the transform (the CDF) to make your
> > > "sample"histogramflat. Then you also find the transform to make your
> > > "reference"histogram(the one you are trying to match) flat. Then you
> > > transform your test image to have a flathistogram, then transform that
> > > image using the inverse of the reference transform to take the image
> > > from a flathistogramto one with your referencehistogram. Works
> > > pretty well. There are several papers on this.
> > > Regards,
> > > ImageAnalyst
>
> > > =======================================
> > > On Jan 23, 2:14 pm, "DSP" <dspho...@gmail.com> wrote:
>
> > > > Hello,
>
> > > > I am learning image processing as well as matlab. I have an image
> > > > which I read using
>
> > > > origimage=imread('filepath');
>
> > > > Now this has its graylevels clustered together, and so I have written a
> > > > code forhistogramequalization that should replace each gray level by