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

### Joe Perkins (view profile)

on 8 Dec 2018 at 17:10
Latest activity Commented on by Joe Perkins

### Joe Perkins (view profile)

on 10 Dec 2018 at 18:05

### Image Analyst (view profile)

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

R2018b

### Image Analyst (view profile)

on 9 Dec 2018 at 0:29

Try this:
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);

Joe Perkins

### Joe Perkins (view profile)

on 10 Dec 2018 at 18:05
Works perfectly. Thank-you so much for your help!