barchart not appearing as it should

3 Ansichten (letzte 30 Tage)
Jason
Jason am 25 Nov. 2014
Kommentiert: Jason am 26 Nov. 2014
Why does my bar chart appear black and not blue as instructed to?
[maxval,idx]=max(IM(:));
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
bar(x,counts,'b');
thanks Jason
  1 Kommentar
Andrew Reibold
Andrew Reibold am 25 Nov. 2014
It is blue for me using 2014a.
Try another color to make sure its not just that blue is similar to black on your monitor or something.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Nov. 2014
Jason, It shows up as blue for me in R2014b. But if your IM is uint8 or uint16, your call to imhist is wrong - it will be aliased and you will have a false spike in the middle. Just run this to see it:
IM = uint8(randi(255, 256,256));
[maxval,idx]=max(IM(:));
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
bar(x,counts,'b');
To fix, do this:
IM = uint8(randi(255, 256,256));
[maxval,idx]=max(IM(:));
maxval= double(maxval);
[counts,x] = imhist(IM,maxval+1);
bar(x,counts,'b');
The reason is you need a bin for intensity 0. If you don't, and you have let's say values of 0-255 and you're using 255 bins, one of the bins has to be doubled up because you're using only 255 bins instead of 256 bins.
If you have a really old version of MATLAB, you can try the 'Color' option, which a lot of MATLAB functions still use:
bar(x,counts, 'Color', 'b');
Again, not necessary in R2014b, and may not even work for older releases either, but it's easy enough to try.
  8 Kommentare
Image Analyst
Image Analyst am 26 Nov. 2014
Just use cumsum() and find():
cdf = cumsum(counts); % Cumulative Distribution Function.
cdf = cdf / cdf(end); % Normalize to 0-1.
% Find index of 95%
index95 = find(cdf > 0.95, 1, 'first');
% Find gray level of 95%
grayLevel95 = x(index95);
Jason
Jason am 26 Nov. 2014
Thankyou

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by