I should also add that I went through Mathworks' GUI tutorial video and the plot the sample GUI is supposed to produce also appears in a new window and is not affected by the surf, mesh, or contour buttons.
Why is my image appearing in a new figure rather than its designated GUI axis?
2 views (last 30 days)
Show older comments
My program allows the user to select an image using uigetfile and should then immediately display it within the GUI. Instead, the image appears in a new figure without error messages. I am using Matlab 6.0 Student Edition without any toolboxes and have added no code to the opening function. This is the callback function for the load operation:
function varargout = loadbutton_Callback(h, eventdata, handles, varargin)
location=uigetfile;
set(handles.filename,'String', location);
%Calls image data and converts to double because I need to do math on the image matrix in other functions. location is the string containing the file location, A is the matrix that represents the image. sampleimage is the tag of my axis.
handles.A=imread(location);
handles.A=double(handles.A);
%Converts image to a two dimensional, gray scale matrix
R=handles.A(:,:,1);
G=handles.A(:,:,2);
B=handles.A(:,:,3);
handles.A=0.2989 * R + 0.5870 * G + 0.1140 * B;
%Defines image location
handles.sampleimage;
%Displays image using imagesc
imagesc(handles.A);
%Updates handles
guidata(h,handles);
Why is my image appearing in a new figure rather than its designated GUI axis?
Accepted Answer
Tom
on 6 Mar 2014
1 Comment
Image Analyst
on 6 Mar 2014
Well that's bizarre. I use GUIDE all the time and display things into axes all the time and I've never had to do that.
More Answers (1)
Image Analyst
on 6 Mar 2014
You're going to have to cast the (badly-named) A into uint8 and you're going to have to direct imagesc which axes to display in:
grayImage = uint8(handles.A);
axes(handles.axesImage); % Switch to the "axesImage" axes control.
imagesc(grayImage);
colormap(gray(256)); % Get rid of any screwy colormap imagesc uses.
title('Gray Scale Image', 'FontSize', 25);
See Also
Categories
Find more on Display Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!