Removal of undesired peaks from Image Histogram

7 views (last 30 days)
Dear Community,
I am trying to remove undesirable peaks from an intensity histogram derived from a grayscale. My current code assigns the counts and bin# into two variables ("bin_counts", "bin_values")
I = imread('M1.tif');
histogram(I)
[bin_counts, bin_values] = imhist(I);
I would like to assing "bin_counts" and "bin_values" to a matrix, so I can after remove after the undesirable peaks. My ultimate goal is to get the FWHM, but if the 'dark' peaks with high counts are not removed, my calculation is faulty. See below part of my code
% Create histogram. If I is a grayscale image, imhist
% uses 256 bins as a default value.
[bin_counts, bin_values] = imhist(im_scaled);
bin_counts(bin_counts>150000)=0 % This does not work as counts vary depending on image
% Find indices of points where data intersects half maximum.
B = sort(bin_counts, 'descend');
halfmax = max(B)/2;
left_idx = find(bin_counts >= halfmax, 1, 'first');
right_idx = find(bin_counts >= halfmax, 1, 'last');
if right_idx==256
i=find(bin_counts >= halfmax)
right_idx=i(length(i)-1)
end
fwhm = bin_values(right_idx) - bin_values(left_idx);
Please refer to the enclosed image, where the undesirable peaks appear in the dark regions (approx. 1-3), and bright regions (254-256)

Answers (1)

Image Analyst
Image Analyst on 22 Sep 2021
[bin_counts, bin_values] = imhist(im_scaled);
% Set 254 - 255 bins to the last one before that
bin_counts(254 : end) = bin_counts(253);
% Set bin_counts(1:3) = bin_counts(4)
bin_counts(1 : 3) = bin_counts(4);

Community Treasure Hunt

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

Start Hunting!