Image Processing: Keep only highest "intensity" values

8 views (last 30 days)
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..?

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
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!