How to display image information using a pushbutton in GUI ?

3 次查看(过去 30 天)
CODE :
function Display_Information_Callback(hObject, eventdata, handles)
% hObject handle to Display_Information (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename pathname]=uigetfile({' *.jpg';'*.png'},'File Select');
image=strcat(pathname,filename);
[pathstr,name ,ext ,versn]=fileparts(filename);
fileinfo=imfinfo(image);
FileSize1=fileinfo.FileSize(1,1);
sizew=fileinfo.Width(1,1);
sizeh=fileinfo.Height(1,1);
axes(handles.axes2)
imshow(image)
set(handles.edit5,'string',name);
set(handles.edit7,'string',sizew);
set(handles.edit8,'string',sizeh);
set(handles.edit6,'string',FileSize1);
set(handles.edit9,'string',ext);
set(handles.edit11,'string',image);
GUI Designed :
ERROR :
Error using
fileparts
Too many
output
arguments.
Error in
userspecified>Display_Information_Callback
(line 160)
[pathstr,name
,ext
,versn]=fileparts(filename);
Error in
gui_mainfcn
(line 95)
feval(varargin{:});
Error in
userspecified
(line 42)
gui_mainfcn(gui_State,
varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)userspecified('Display_Information_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

采纳的回答

Image Analyst
Image Analyst 2021-8-1
fileparts() does not report version number. Try this (with a number of other imnprovements):
[filename, pathname] = uigetfile({' *.jpg';'*.png'},'File Select');
fullFileName = fullfile(pathname,filename);
[folder, baseFileNameNoExt, ext] = fileparts(fullfileName);
fileinfo = imfinfo(fullFileName);
FileSize1 = fileinfo.FileSize(1,1);
axes(handles.axes2)
theImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(theImage);
imshow(theImage);
handles.edit5.String = baseFileNameNoExt;
handles.edit7.String = columns;
handles.edit8.String = rows;
handles.edit6.String = FileSize1;
handles.edit9.String = ext;
handles.edit11.String = fullFileName;
  4 个评论
MashalS
MashalS 2021-8-1
I could'nt understand.Kindly see the GUI below. For example, i have browsed this image, when i shall click 'display information', it should only display the information ,without selecting the image again.That's what i want to do.
Image Analyst
Image Analyst 2021-8-1
Have two functions, each one a callback for the corresponding button. One button to read in the image and display it's information, and the other button to simply display the image but not read it in again with imread().
%=====================================================================
% Button callback function to read in image and display information.
function Read_Info_and_Display_Information_Callback(hObject, eventdata, handles)
% Read in image and display info.
handles = Read_Info_and_Display_Information(handles, true);
% Update handles structure
guidata(hObject, handles);
return; % from Read_Info_and_Display_Information_Callback()
%=====================================================================
% Button callback function to display existing information only.
function Display_Information_Callback(hObject, eventdata, handles)
% Don't read in image (assume it's been done already).
% Just display information again.
handles = Read_Info_and_Display_Information(handles, false);
% Update handles structure
guidata(hObject, handles);
return; % from Display_Information_Callback()
%=====================================================================
% Function to optionally read in image,
% and to display information about the image.
function handles = Read_Info_and_Display_Information(handles, readFromDisk)
if readFromDisk
[filename pathname]=uigetfile({' *.jpg';'*.png'},'File Select');
[filename, pathname] = uigetfile({' *.jpg';'*.png'},'File Select');
fullFileName = fullfile(pathname,filename);
handles.fullFileName = fullFileName;
end
fullfileName = handles.fullfileName;
[folder, baseFileNameNoExt, ext] = fileparts(fullfileName);
fileinfo = imfinfo(fullFileName);
FileSize1 = fileinfo.FileSize(1,1);
axes(handles.axes2)
theImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(theImage);
imshow(theImage);
handles.edit5.String = baseFileNameNoExt;
handles.edit7.String = columns;
handles.edit8.String = rows;
handles.edit6.String = FileSize1;
handles.edit9.String = ext;
handles.edit11.String = fullFileName;
return; % from Read_Info_and_Display_Information()

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by