Problem with Imhist method

14 views (last 30 days)
Jason
Jason on 23 Oct 2014
Commented: Jason on 23 Oct 2014
I have an image Zoom:
Zoom =
326 313 269 237 255 329
332 271 304 256 332 302
330 320 265 215 274 316
233 219 218 224 221 224
260 224 203 226 193 210
272 231 219 227 205 227
when I perform
figure
imhist(Zoom)
the histogram is defaulting in the x-axis to x10^4
So the histogram is just a spike.
why does it not autorange the x-axis, and how too?
thanks Jason
  1 Comment
Jason
Jason on 23 Oct 2014
Just to add, I often use 12 bit images. Occasionally I will use the sum of 3, 12 bit images, so I need the capability to handle both. I would like to limit the number of bins to say 100, but have the x-axis represent the actual intensity, with the max of the x-axis being soemthing related to the max value of intensity in data set

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 23 Oct 2014
Edited: Image Analyst on 23 Oct 2014
It's using the max of the data type, which is uint16. You can set the x axis to the max of the image varaible after you call imhist() like this:
xlim([0, max(Zoom(:)));

Michael Haderlein
Michael Haderlein on 23 Oct 2014
The x scale depends on the data type of the image. I guess in your case, Zoom is of uint16? Then, the limits of the data are [0 65535] and that's the limits of the axes.
Now, the question is, how do to better in your case. Converting to the next smaller data type (uint8) won't help a lot as you have numbers too big for uint8 (must be max 255). Depending on your specific problem, I'd
- either normalize to max=1:
imhist(Zoom/max(Zoom(:)))
- or use the "normal" hist function:
hist(Zoom(:),1:max(Zoom(:)))
Best regards,
Michael
  1 Comment
Jason
Jason on 23 Oct 2014
OK, Im playing with the following, but its not quite there:
%Automate x-axis labels---------------------------------------
[maxval1,idx]=double(max(ROI(:)))
XTck=get(handles.axes6,'XTick');
t_lim = 1e3*ceil(maxval/1000) % get axis limit: 5000
t_ax = 0:t_lim;
n_int = 20; % define # of intervals
t_int = t_lim/n_int;
tt = t_ax(rem(t_ax,t_int)==0); % find tick locations
ttlab = num2cell(tt) % and generate tick labels
%---------------------------------------------------------------
[counts,x] = imhist(ROI,n_int);
set(handles.axes6,'XTick', tt,'XTickLabel',ttlab);
xlim([0 maxval])

Sign in to comment.


Adam
Adam on 23 Oct 2014
I'm not familiar with imhist, but from a quick look it appears to always use the data type limits for its histogram range so I guess you would need to scale your data up to make better use of the available data range for a histogram using imhist.
  2 Comments
Jason
Jason on 23 Oct 2014
But then, the histrogram doesn't tell me the frequency of the "actual" intesnity values?
Adam
Adam on 23 Oct 2014
It's just a linear mapping if you are scaling upwards which you would be doing for filling a data type range.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!