Contrast adjustment/pixel adjustment

Please I am still learning, I have a gray scale image with the intensity values ranges from 0 to 255. If I plot the histogram of the images, I was having some noises at both ends of the histogram. I like to refine the image pixels by ignoring the pixels that are below certain thresholds in order to have new minimum and maximum intensity values and of course to get rid of those noises at both ends. I also like to define my threshold as a function of the image size if possible. Can somebody please help me with the code? Thanks in advance.

 Accepted Answer

See my salt and pepper noise removal demos, attached. Of course they can easily be adapted to get rid of noise above and below thresholds instead of just exactly at 0 and 255.

3 Comments

Thanks very much Image Analyst but I dont think this code will solve my problem as I did not intend to remove the image noise really but interested in the image pixels.I have plotted a spectrum of the image which has some noises and I want to set an automatic threshold that will eliminate the noisy part of the graphs.
If you have noise at both ends of the intensity range and just want to get rid of bins with those values of intensity from the histogram but not from the image, you can just set the counts equal to zero. I often do this to see the histogram more clearly when there is a huge spike at some bin, like the zero bin because I've masked the image
[pixelCounts, grayLevels] = imhist(grayImage, 256);
% Suppress huge bin at zero
pixelCounts(1) = 0;
% Plot
bar(grayLevels, pixelCounts);
You can also set ranges of bins equal to zero
pixelCounts(1:30) = 0;
This will get rid of counts from the histogram but doesn't get rid of the noise from the image . To do that you'd need to do something like I attached originally, but you say you don't want to do that.
Thanks very much for your helps. This really helps.

Sign in to comment.

More Answers (0)

Asked:

on 29 May 2014

Commented:

on 30 May 2014

Community Treasure Hunt

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

Start Hunting!