MATLAB Answers


How can I find minima in specific regions & closest bin to value in Histogram?

Asked by Joe Perkins on 8 Dec 2018
Latest activity Commented on by Joe Perkins on 10 Dec 2018
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


Sign in to comment.

1 Answer

Answer by Image Analyst
on 9 Dec 2018
 Accepted Answer

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);

  1 Comment

Works perfectly. Thank-you so much for your help!

Sign in to comment.