フィルターのクリア

Weird Imhist beahviour seen

5 ビュー (過去 30 日間)
Jason
Jason 2014 年 11 月 21 日
コメント済み: DGM 2024 年 5 月 20 日
Hi, ive been tearing my hair out all morning. I want to plot the histogram of an image. I normally use im hist. My images are 3 12 bit images that are summed, hence the max value can be 3*4095=12285. It appears my histogram is defaulting to 16 bit values.
This is my code:
IM = imread(file);
IM1=double(IM);
[maxval,idx]=max(IM1(:)) % determine number of bins (of width = unity)
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
figure
stem(x,counts,'b', '.');
counts(maxval) %check the max intensity
First of all, counts(maxval) returns zero, and here is the histogram stem plot - defaulting to 65535 levels. I want to have 1-12285 levels.

採用された回答

Image Analyst
Image Analyst 2014 年 11 月 21 日
Try this:
grayImage = imread(file);
maxGrayLevel = max(grayImage(:)) % determine max gray level.
[counts, grayLevels] = imhist(grayImage);
bar(grayLevels, counts, 'Color', 'b');
xlim([0, maxGrayLevel)]; % Specify range of x axis.
Let me know how it works.
  2 件のコメント
Jason
Jason 2014 年 11 月 21 日
OK, so you don't suppress the unwanted gray levels, but use display via xlim to view only whats wanted.
Yes this works, thanks IA!
Image Analyst
Image Analyst 2014 年 11 月 21 日
You're welcome. Can you go ahead and officially mark the answer as "Accepted" then? Thanks in advance.

サインインしてコメントする。

その他の回答 (1 件)

DGM
DGM 2024 年 5 月 20 日
I don't know where everyone is getting uint12-scale images, but I guess it's a thing. I posted an example which demonstrates three ways of representing improperly scaled images (uint12 in uint16, and int12 in int16) using imhist() and other tools.
  2 件のコメント
Jason
Jason 2024 年 5 月 20 日
Thankyou!
DGM
DGM 2024 年 5 月 20 日
Oh wow. I didn't even notice both threads were yours. I certainly didn't expect a prompt reply!
You're welcome.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by