필터 지우기
필터 지우기

How to display image information using a pushbutton in GUI ?

조회 수: 2 (최근 30일)
MashalS
MashalS 2021년 8월 1일
댓글: Image Analyst 2021년 8월 1일
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에서 File Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by