Does the im2gray function give greater 'weight' to red than green and blue?

조회 수: 13 (최근 30일)
Isaak 2023년 3월 21일
편집: DGM 2023년 3월 22일
I have the following colour coded echo strength image where the red indicates high levels of reflection, then yellow, then green:
I want to compare the actual image centroid with the weighted centroid and have done so using the following code:
clear all
% import the Image %
imdata = imread("RCS_Example3.bmp");
% Display the image %
% Convert to grayscale - Grayscale Images are 2D arrays because only
% need one value of intensity for each pixel %
RCSGray = im2gray(imdata);
title("RCS Gray Scale");
BW = RCSGray > 0;
title('Binary Image')
s = regionprops(BW,RCSGray,{'Centroid','WeightedCentroid'});
title('Weighted (red) and Unweighted (blue) Centroids');
hold on
numObj = numel(s);
for k = 1 : numObj
plot(s(k).WeightedCentroid(1), s(k).WeightedCentroid(2), 'r*')
plot(s(k).Centroid(1), s(k).Centroid(2), 'bo')
hold off
This produces the following figure (red star = weighted centroid, blue circle = actual centroid):
when converted to grayscale its hard to tell if the 'intensity' of the red spots on the original image is high and I want to know if the red spots are contributing a higher weighted value as they represent points of highest intensity reflection.
If this is correct, is there a way to work out how far apart the weighted and unweighted centroids are?
  댓글 수: 8
Stephen23 2023년 3월 22일
편집: Stephen23 2023년 3월 22일
@Isaak: the task is not clearly defined. Although you can use RGB2IND (as Image Analyst shows) to "undo" the pseudo-coloring, doing so requires knowing the colormap distribution, otherwise we simply do not know the scale of values that those colors represent. Are they a logarithmic scale, or evenly spaced, or unevenly spaced? We simply don't know.
For example, consider are the red pixels equally distant from green as green is from yellow? How far apart are light gray and dark gray values? What color is zero? The centroids will be essentially meaningless until this color scale is specified.
You might find this information in the documentation for the product/tool that generates that image, or perhaps online.
Isaak 2023년 3월 22일
Thanks @Stephen23 I think I understand what you're getting at. I'll need to go away and see if I can find the color map/ what scale the colours are assigned to from the software.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2023년 3월 22일
"I have the following colour coded echo strength image where the red indicates high levels of reflection, then yellow, then green"
What about gray and teal/aqua?
If you can, it's definitely best to get the original image values, not a pseudocolored image. Can you do that? If you can, it's easy. But WHY do you want the weighted centroid of this image when it looks like there are parts of the image that are clearly different and (perhaps) should not just be lumped in with the pixels of the entire image? I agree with Stephen that converting that to gray scale will not get you what you asked for (plus I'm not even sure what you're asking for is the proper thing to measure). What you would have to do, if you can't get the original image, is to use the colormap that was applied to this image to "undo" the pseudocoloring and get you back to the original values. It's what I do in the attached thermal image demo. What is your image of? It looks like maybe it's some kind of simulated inverse synthetic aperture radar image of a ship..
  댓글 수: 4
Stephen23 2023년 3월 22일
"Is there a way of assigning my own weighted values to colours so that matlab processes the r,g,b accordingly"
Yes, you would need to first specify the colormap (in order to correctly define the sequence and its distribution), then use RGB2IND (or DITHER or something similar) to "undo" the pseudo-coloring. This is what Image Analyst already showed you in their answer.
Simply multiplying the R,G,B, channels with some scalar values will not work.
DGM 2023년 3월 22일
편집: DGM 2023년 3월 22일
If the software provides you with a colorbar, you may be able to use that to get a rough estimate of the colormap. At that point, IA's demo would work. If you have to take a screenshot, save it as PNG, not JPG, as capturing the ends of the colorbar is important for scaling, and JPG will skew them.
If there's a chance that the mapping is nonlinear, then you'd have to figure out what it is.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by