Can i adjust each thickness of each histogram bar of an image differently ? and can i plot or extract an exact value of the x axis in the histogram ?

8 ビュー (過去 30 日間)
Yassine Zaafouri
Yassine Zaafouri 2016 年 10 月 17 日
編集済み: dpb 2016 年 10 月 19 日
I want to make the histogram of an Image but i want to focus on a specific zone ( around the value 2048 in the x axis) . So can i plot the histogram and adjust the bars so i can see clearly this value ? and i want the bars around this value to be narrower then the others .
Can anyone help me please because i have been trying without getting the result that i want. Thank you

回答 (2 件)

dpb
dpb 2016 年 10 月 17 日
編集済み: dpb 2016 年 10 月 19 日
The bar chart in Matlab is extraordinarily difficult to do anything with that's "out of the box".
To your specific question, the bars are a single object for each column so the width is a fixed single value for the series. The only way I can think to change this without writing something specific would be to use the ability of bar to treat NaN values as placeholders. To do this you would take the range of bins that are wanted to be different and substitute NaN for their values in one column and then do the obverse in a second vector--keep those values in their bins and replace all other with NaN. Then use bar twice, with hold on between the two calls and you'll have two bar plots on the same axes that can set the properties on to differentiate.
>> y=randn(1,1000); % sample data
>> [n,x]=hist(y,20); % get hist data
>> ix=[8:12]; % center bins to accentuate in histogram
>> n=[n; nan(size(n))]; % make second set same size
>> n(2,ix)=n(1,ix); % second is center section values
>> n(1,ix)=nan; % clear first center section (NaN)
>> hB=bar(x,n(1,:)); % outer portion normal bars
>> hold on % get ready to add center
>> hB(2)=bar(x,n(2,:),0.5); % with narrower bars
>>
ADDENDUM Per the comment following IA's alternative, I did a File Exchange search and found <fileexchange/1420-scatterbar3> "SCATTERBAR3(X,Y,Z,WIDTH) draws 3-D bars of height Z at locations X and Y with width WIDTH."
ADDENDUM 2 Following up the discussion there wherein it (finally) dawns on me that 2D histogram is bogus, I think the solution you're looking for is
[n,x]=hist(YourImageArray(:),nBins);
and then follow the above example to emphasize chosen area(s).
  2 件のコメント
Yassine Zaafouri
Yassine Zaafouri 2016 年 10 月 17 日
thank you for your time . The Problem is that i'am working with an image so the matrix is 2 dimensional so when i want to apply your idea it doesn't work properly . what do you think ?
dpb
dpb 2016 年 10 月 17 日
You'll have to use hist3 and bar3 then, with the desired bins in the two dimensions set as above. I've got meetings; gotta' run so can't try to do a demo now but same idea should work with some extra effort to keep track of "who's who in the zoo" as far as intersecting bin locations.

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


Image Analyst
Image Analyst 2016 年 10 月 17 日
As an alternative, if you want, you can color each bar independently, like you can make one particular bar red and the others blue, or whatever. Demo attached.
  10 件のコメント
Yassine Zaafouri
Yassine Zaafouri 2016 年 10 月 19 日
Good morning gentlemens, So i tried your code above dpb and i adjusted it to fit with my image matrix and it actually worked . But i want to have more precison so how can i define the centers of the bins ? i have a vector with some defined values and i want to use them as centers . So how can i do that by changing the option nBins with the vector of the centers because i actually do not know how many bins i want to plot in general. When I tried to do that i got an erreur : X and Y must have the same size.
dpb
dpb 2016 年 10 月 19 日
編集済み: dpb 2016 年 10 月 19 日
The syntax
n = hist(Y,x)
where x is a vector, uses N=length(x) bins centered at x i. In that case, use your x in bar, too, and don't need to return the centers as I did in the example where I just gave a count.

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

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by