Displaying Histogram IN GUI AXES using imhist

6 views (last 30 days)
I am trying to display the histogram of an image in a GUI using GUIDE. The Gui has two AXIS the first axis displays the image and the second Axis is meant to display the Histogram, however whenever i run the call back the histogram figure will appear correctly but not in the axis. I'm not sure if the handles.axes2 is in the right place, however i have tried it in all other logical (to my mind) places within the code. Any Advice would be very appreciated.
Code below
Many Thanks
Luke
a=imread('Im2.png');
agray=rgb2gray(a);
x=agray;
figure, imshow(x);
handles.axes2;
figure, imhist(x);

Answers (2)

Sankarshan Bangaloree
Sankarshan Bangaloree on 6 Feb 2017
I created a fcn from axes guide then i used this you can try this it worked for me
function axes3_CreateFcn(hObject, eventdata, handles)
I=imread('Im2.png');
I=rgb2gray(I);
imhist(I)
axes(handles.axes3);

Geoff Hayes
Geoff Hayes on 5 Mar 2016
Edited: Geoff Hayes on 5 Mar 2016
Luke - I am unsure about the line of code
handles.axes2;
What is the intent of this line? If you wish to set this to be the current axes, then you should do this as
axes(handles.axes2);
However, I don't know if that will be sufficient as I don't have the Image Processing Toolbox to verify.
If the above doesn't work, then see the documentation for imhist. There isn't an input parameter indicating the target axes upon which to draw the histogram, so you may have to draw it yourself using the output from imhist as
[counts,binLocations] = imhist(x);
stem(handles.axes2,binLocations,counts);

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!