How to change the amount of the histogram?

Hello all,
I have an image and I want to plot the histogram of the image,but the histogram is unusual,maybe it is because lots of amount of the pixels have the value 1. Is there anything that I can do so that I can put the range of the histogram became between [2,989],, 989 is the maximum pixel value.for the histogram I use this command: I don't know why the amount of the value for the histogram are until 3*10^3 In the picture there are lots of value between [2,989],I don't know why it doesn't show them,how can I show the value for other pixel values in the histogram. figure,imhist(a)
<<
>>

回答 (3 件)

Image Analyst
Image Analyst 2014 年 2 月 25 日

1 投票

This is a double image, isn't it? Not an integer image. Do this:
class(a)
and tell me what it says. I suspect it's double, and that's the problem. If it's double, then imhist thinks that all the numbers should be between 0 and 1 and if you have any bigger than 1 it clips to 1. You'll have to use im2double() or just use hist instead of imhist:
pixelCounts = hist(a(:), 16384);
bar(pixelCounts, 'BarWidth', 1);

5 件のコメント

Faranak
Faranak 2014 年 2 月 26 日
for the class(a) it responds this : int16 what should I do now?
Faranak
Faranak 2014 年 2 月 26 日
I used the ''im2double()'' command and your other command for bar and it gives me this picture. I want my histogram show the variables of my picture,which is between 2 and 989 . I don't know why it shows the value 1800 and 3.5*10^4 .. I want the scale be [2:989] .
Jos (10584)
Jos (10584) 2014 年 2 月 26 日
Acopy = a ;
Acopy(a==1) = NaN
pixelCounts = hist(Acopy(:), 16384);
bar(pixelCounts, 'BarWidth', 1);
Faranak
Faranak 2014 年 2 月 26 日
it's not working. what is 16384 related to?
Image Analyst
Image Analyst 2014 年 2 月 26 日
Thats the number of bins. It's the mas to make sure you get just one graylevel per bin. If you don't put that then the default is only 10 bins I believe, which gives a pretty chunky histogram.

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

Jos (10584)
Jos (10584) 2014 年 2 月 25 日

0 投票

use HISTC to specify the bins

2 件のコメント

Faranak
Faranak 2014 年 2 月 26 日
it gives me this error .
Error using histc Not enough input arguments.
Jos (10584)
Jos (10584) 2014 年 2 月 26 日
Did you read the documentation of histc? It requires two arguments ...

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

Jos (10584)
Jos (10584) 2014 年 2 月 26 日

0 投票

I will spell it out for you, provided that you read the documentation , ok?
% let X be your image with values between 2 and M, and 1 being background
doc histc
maxX = max(X(:))
edges = 2:maxX ;
n = histc(X(:),2:maxX) ;
bar(edges,n) ;

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

質問済み:

2014 年 2 月 25 日

回答済み:

2014 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by