Why is the horizontal axis 0 to 1 in a histogram for a rgb image?

for my code I am trying to determine intensitiy of the connect components and plot histograms:
for k = 1:numZones
...
zoneMask = zoneMask .* im2double(edgesClean) .* DD;
% Calculate connected components in this zone
cc = bwconncomp(zoneMask);
% Calculate region properties for each connected component in this zone
statscc = regionprops(cc, 'Area', 'Centroid', 'Eccentricity', 'Perimeter', 'MajorAxisLength', 'MinorAxisLength', 'Circularity', 'MaxFeretProperties', 'MinFeretProperties');
% Calculate features for this zone
numObjects = cc.NumObjects;
if numObjects > 0
profileCounts(k) = numObjects;
end
% Create a histogram of the intensities
figure;
imhist(intensities);
grid on;
But sometimes the values on x axis are strange (i.e. not 0 to 256 for a rgb image I have) why is this? is my code errousnous? please help me to fix so that i have accurately determined histogram of connected components intensity.

 채택된 답변

Image Analyst
Image Analyst 2023년 5월 25일

0 개 추천

Please attach one of your images and code to read it in. Evidently your image got converted to floating point. And there is no reason that your image should span the full dynamic range unless you forced it to or it was naturally like that for some reason. Usually images don't span the full dynamic range.

댓글 수: 6

for k = 1:numZones
% Create a binary mask for this zone
if k == 1
% Create a mask for the first zone based on distance from center
zoneMask = sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(1);
else
% Create a mask for this zone based on distance from center
zoneMask = (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) > radii(k-1)) & (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(k));
end
areaOfEachZone(k) = sum(zoneMask, 'all') * pixelSize^2;
zoneMask = zoneMask .* im2double(edgesClean) .* DD;
% Calculate connected components in this zone
cc = bwconncomp(zoneMask);
% Calculate region properties for each connected component in this zone
statscc = regionprops(cc, 'Area', 'Centroid', 'Eccentricity', 'Perimeter', 'MajorAxisLength', 'MinorAxisLength', 'Circularity', 'MaxFeretProperties', 'MinFeretProperties');
% Calculate number of connected components for this zone
numObjects = cc.NumObjects;
% Calculate the histogram for the connected components in each zone
% % Calculate the intensity values of the connected components (mitochondria) in this zone
intensities = cellfun(@(x) mean(mean(imageData(x))), cc.PixelIdxList);
% Create a new figure for the histogram
figure;
histogram(intensities, 'BinEdges', 0:1:256);
grid on;
flippedZone = numZones - k + 1;
title(['Histogram of Mitochondria Intensity in Zone ' num2str(flippedZone)], 'FontSize', fontSize);
xlabel('Intensity');
ylabel('Frequency');
@Image Analyst from the intensities line i used histogram() to plot the histogram of the intensities of the connected component for the respective zone (for k = 1:numZone), in principal is this correct? imageData is the full image (all zones).
imageData = imread(MyRGBImage);
@Image Analyst I agree regarding the dynamic range. However, wouldn't the axis still span from 0 to 250 if its the histogram of the rgb image? Moreover, even if its a segment of that rgb image. Please confirm or elaborate. Thanks
Why are you doing this cryptic, complicated thing
intensities = cellfun(@(x) mean(mean(imageData(x))), cc.PixelIdxList);
instead of simply asking regionprops to get it for you
props = regionprops(cc, imageData, 'MeanIntensity');
intensities = [props.MeanIntensity];
histogram() uses it's own judgement where to put the left bar and the right bar. It may or may not be at the limits of your data, and probably won't span the limits of possible values for your variable's class.
imhist() should have a bar chart that goes from the lowest value possible (0) to the highest one possible for that class (255 for uint8, 65535 for uint16, and 1 for floating point images where MATLAB expects all floating point values to be in the range of 0-1).
If you have any more questions, then attach your image and code to read it in with the paperclip icon after you read this:
You answered my question, @Image Analyst its just because of the conditions of my code its not obvious how to set up MeanIntensity hence why i made the complicated cellfun equation as a substitute. If I may I would like to ask if despite it being complicated does the cellfun work for the purposes intended?
Also from what you're saying it sounds like imhist() is better but since my cellfun is a floating point the horizontal axis will reflect this 0 to 1 not 0 to 256.
I don't know. I just always use regionprops because it's so much easier and it lets you get lots of other measurements at the same time. You can compare your two intensity arrays just as well as I can.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2023년 5월 25일

댓글:

2023년 5월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by