histogram and intensity of images
9 views (last 30 days)
Show older comments
Hello. I have a tif image and plot the histogram (its generally 12 bit grayscale, max value =4095)
I want to be able to do 2 things that I am struggling with.
1: I use the following to obtain and count the number of "saturated pixels" . But how can i modify it to say count the number of pixels above a certain value i.e.3500 counts
[maxval1,idx]=max(IM(:))
[row,col]=ind2sub(size(image), idx)
%count elements
n=numel(row)
2: After plotting a histogram of the intensities using
[counts,x] = imhist(IM,maxval);
stem(x,counts,'b');
xlim([0 maxval]);
ylim([0 max(counts)]);
(where I have allowed the axes to scale automatically to the max values), how can I superimpose on top of this in a different colour only part of the histogram that has intensities 3500 to 4095?
Thanks for any help. Jason
3 Comments
Image Analyst
on 14 Feb 2014
You can simplify the first two lines to a single line by adding options to find() to extract the first element.
id = find(x>3700, 1, 'first');
Accepted Answer
Image Analyst
on 14 Feb 2014
Jason, you have to call bar() or stem() twice, with "hold on" in between, once for each color. Something like
bar(counts(1:binNumber), 'BarColor', 'r');
hold on;
bar(counts(binNumber+1), 'BarColor', 'b');
where binNumber is the index where 3500 occurs.
For the first question, I'd do
countMoreThan3500 = sum(counts(binNumber+1:end));
4 Comments
Sumera Yamin
on 13 Nov 2020
I have an image and i can calculate sum of intensities along x and y axis using following code. How can we plot sum of intensities on the image along x and y axis: many thanks for your help.
Image Analyst
on 13 Nov 2020
What I've done in this case is to have two additional axes, one on the left of the image axes, and one below it. I plot the vertical profile along the one on the left, with x and y switched, and the horizontal profile along the axes underneath the image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels == 3
grayImage = rgb2gray(grayImage);
end
verticalSum = sum(grayImage, 2);
horizontalSum = sum(grayImage, 1);
axes(handles.axesLeft); % Switch to the axes to the left of the image axes.
plot(verticalSum, 1:rows, 'b-', 'LineWidth', 2);
grid on;
axes(handles.axesBelow); % Switch to the axes below the image axes.
plot(1 : columns, horizontalSum, 'b-', 'LineWidth', 2);
grid on;
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!