Why is my image appearing in a new figure rather than its designated GUI axis?

2 views (last 30 days)
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?
  1 Comment
Tom
Tom on 6 Mar 2014
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.
Link to tutorial video: tutorial

Sign in to comment.

Accepted Answer

Tom
Tom on 6 Mar 2014
I found the issue. Should your code be sound and your plots are not present on your GUI, open guide and go to Tools-> Application Options-> Set Command Line Accessibility to On.
  1 Comment
Image Analyst
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.

Sign in to comment.

More Answers (1)

Image Analyst
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);
  1 Comment
Tom
Tom on 6 Mar 2014
Replaced the last three lines in my original code with:
grayimage=uint8(handles.A);
axes(handles.sampleimage);
imagesc(grayimage);
colormap(gray(256));
title('Gray Scale Image', 'FontSize', 25);
The image still opens in a new figure.

Sign in to comment.

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!