MATLAB Answers

Image Processing: Keep only highest "intensity" values

61 views (last 30 days)
Philip
Philip on 13 Sep 2011
Does anyone know of a way that I can reduce the following image to an image that only includes the highest intensities (for want of a better word)?? In other words, I would like to produce a second image that contains only the redest values, and discards all the others.
This image was produced using 'imagesc' so I am not sure if this is possible without thresholding the pixel values..?

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 13 Sep 2011
Something like this, in which I have coded an arbitrary 95% cutoff:
maxred = max(max(IMG(:,:,1)));
deep_red = IMG(:,:,1) .* (IMG(:,:,1) >= 0.95 * maxred);
deep_red(1,1,3) = 0; %extend to RGB image with G and B all 0
However, this algorithm as given has a limitation that as coded it cannot tell the difference between a point that is "deep red" and one that is "deep purple" or "bright white", because the algorithm is not paying attention to the green or blue content of pixels. This might or might not be a problem for your purposes.
I note that your image has some bright yellow pixels: bright yellow is low red with high green and high blue, so if you want to include the locations that are shown as yellow, then you cannot check only the red plane. If you do want to include them, then would you want them to show up in the original yellow in the processed image, or would you want them to show up recolored to bright red?
I have a suspicion that what you what is closer to this:
gscale = rgb2gray(IMG);
thresh = 0.95 * max(gscale(:));
deep_red = gscale .* (gscale >= thresh);
deep_red(1,1,3) = 0; %convert grayscale to redscale RGB

  4 Comments

Show 1 older comment
Philip
Philip on 13 Sep 2011
Actually - I will almost definitely need to save the imagesc output image anyway
Walter Roberson
Walter Roberson on 13 Sep 2011
As your original values are all in the range 0 to 1, you could remove the rgb2gray() and replace the gscale reference with a reference to your pixel values. You probably won't want to bother converting to RGB via the assignment of 0 to extend the matrix to 3D.
Please see some of my previous code for manually doing the calculations that imagesc does: http://www.mathworks.com/matlabcentral/answers/7396-how-to-print-a-matrix-as-an-uncompressed-image-file#answer_10377
and please be sure to do the correction noted in the comments there.
Philip
Philip on 14 Sep 2011
Your example works great, thank you!
The output images seem to be scaled differently to how imagesc scales (without defining limits)... The output actually seems to be comprised of two colors only, instead of imagesc that has a wider range... How can I change your code so that the scaling can be altered?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by