필터 지우기
필터 지우기

Histogram from imhist does not mach histogram from imtool

조회 수: 3 (최근 30일)
Florian Mayerle
Florian Mayerle 2019년 1월 3일
답변: Image Analyst 2019년 1월 4일
Hi,
I want to extract information out of an uint16 picture due to analyze the histogram.
But when I try to plot the Histogramm with " imhist "- funktion it does not mach the histogram from " imtool "- funktion at all.
Can anyone melp me?
As attached
img ---> 1024x1024 uint16
left picture --> imhist(img) right picture --> imtool(img,[])

답변 (1개)

Image Analyst
Image Analyst 2019년 1월 4일
The problem is your values only go up to 2243 and it's 16 bits. The default number of bins for imhist() is 256 which means that all your counts fall into the leftmost 10 bins. If you want, you can try histogram() instead of imhist(), though you need to specify 256 bins or 65535 bins. If you specify 65535 bins, so that each gray level gets it's own bin, AND then scale your x axis so that it goes from 0 to 2243, then you can see the full shape of the histogram. Try to follow the illustrative code below.
Try this:
maxValue = max(A(:))
subplot(1, 3, 1);
imshow(A, [])
subplot(1, 3, 2);
% Call imhist with default 256 bins,
% so that all the image gray levels will be only in the 10 darkest bins.
[counts, grayLevels] = imhist(A);
bar(grayLevels, counts, 'BarWidth', 1);
title('Histogram with 256 bins', 'FontSize', 15);
% Values only go to 2243, not 65535 so histogram is
% all squished up on the left end. Only 10 bins are used.
% Use xlim() to set the x range so we can see it better.
xlim([1, grayLevels(10)]);
grid on;
% Try again with 65535 bins:
subplot(1, 3, 3);
[counts, grayLevels] = imhist(A, 65535);
bar(grayLevels, counts, 'BarWidth', 1);
% Scale to last value
lastIndex = find(counts > 0, 1, 'last');
xlim([1, grayLevels(lastIndex)]);
grid on;
title('Histogram with 65535 bins', 'FontSize', 15);
0000 Screenshot.png

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by