How can I find minima in specific regions & closest bin to value in Histogram?
1 view (last 30 days)
Show older comments
Hi all,
As part of my work I am producing greyscale images that produce similar histogram profiles (see. fig). The information I am trying to obtain from each is
1) Peak count greyscale value
2) The greyscale value of the minima shown in region X
3) The closest greyscale value that corresponds to 25% of the peak pixel count in region Y. So for histogram shown in fig; the bin with value approx 3000000 in region Y (12000000* 0.25) .
Peak value I have already successfully calculated. Can anyone point me in the direction of how to tackle 2) & 3)? Any help would be greatly apprechiated.
Thanks, Joe

0 Comments
Accepted Answer
Image Analyst
on 9 Dec 2018
Try this:
% Read in image.
grayImage = imread('pout.tif');
imshow(grayImage, []);
% Get histogram
counts = imhist(grayImage);
plot(counts, '-', 'LineWidth', 2);
xlabel('Gray Level', 'FontSize', 15);
ylabel('Count', 'FontSize', 15);
title('Histogram', 'FontSize', 15);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Find max count and what gray level it's at.
[maxCount, glAtMaxCount] = max(counts)
% Find the min in region X
minCount = min(counts(1:glAtMaxCount-1))
glAtMinCount = find(counts(1:glAtMaxCount-1) <= minCount) % Might be more than one.
% Find the closest greyscale value that corresponds to 25% of the peak pixel count in region Y
temp = counts;
temp(1:glAtMaxCount) = maxCount;
gl25 = find(temp < 0.25 * maxCount, 1, 'first')
% Put red line there
hold on;
line([gl25, gl25], ylim, 'Color', 'r', 'LineWidth', 2);
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!