MATLAB Answers

Image not displayed properly in GUI

조회 수: 1(최근 30일)
Warid Islam
Warid Islam 2021년 4월 6일
댓글: Warid Islam 2021년 4월 6일
I have created a Matlab GUI where I would display multiple images from a folder in the image axes at GUI. I could read all the image files. Unfortunately, the image axes in the GUI is blank as shown in the figure below. Any help would be appreciated.
function varargout = dm(varargin)
% DM MATLAB code for dm.fig
% DM, by itself, creates a new DM or raises the existing
% singleton*.
%
% H = DM returns the handle to a new DM or the handle to
% the existing singleton*.
%
% DM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DM.M with the given input arguments.
%
% DM('Property','Value',...) creates a new DM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before dm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to dm_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help dm
% Last Modified by GUIDE v2.5 06-Apr-2021 01:25:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @dm_OpeningFcn, ...
'gui_OutputFcn', @dm_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before dm is made visible.
function dm_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to dm (see VARARGIN)
% Choose default command line output for dm
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes dm wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = dm_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myFolder = 'D:\regionGrowing_MLT\Images';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
axes(handles.axes1);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
handles.imageArray=imageArray;
end
% Update handles structure
guidata(hObject, handles);
  댓글 수: 3
Warid Islam
Warid Islam 2021년 4월 6일
Hi @Rik,
You are right. I was wrong images in the GUI. That was quite silly from me. My GUI now works fine.

댓글을 달려면 로그인하십시오.

답변(0개)

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by