how make x and y -axis labels(titles) for histogram of an image?

45 views (last 30 days)
i execute the following matlab code to display histogram of gray scale image with x-axis and y-axis names but i didnot get names in x-axis and y-axis labels.
k=imhist(image)
xlabel('grayscale range')
ylabel('intensity values range');

Accepted Answer

Image Analyst
Image Analyst on 2 May 2015
Your code should have worked. Try my boilerplate code snippet:
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
bar(grayLevels, pixelCount); % Plot it as a bar chart.
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlabel('Gray Level', 'FontSize', fontSize);
ylabel('Pixel Count', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

More Answers (1)

Ahmet Cecen
Ahmet Cecen on 2 May 2015
Edited: Ahmet Cecen on 2 May 2015
This sometimes happens to me too. The problem is xlabel sometimes get stuck BEHIND the imhist colorbar at the bottom. To fix it you can use this instead (may need to play around with the values for your liking):
xlabel('grayscale range')
xl = get(gca,'XLabel');
set(xl,'Position',get(xl,'Position') - [0 60000 0])
And Image Analyst's solution would also work because it gets rid of the default bar at the bottom. Take your pick.

Community Treasure Hunt

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

Start Hunting!