Image Processing: Keep only highest "intensity" values

7 次查看(过去 30 天)
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..?

回答(1 个)

Walter Roberson
Walter Roberson 2011-9-13
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 个评论
Walter Roberson
Walter Roberson 2011-9-13
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 2011-9-14
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by