I have a problem. Help me please! I want to show a size of a picture
조회 수: 2 (최근 30일)
이전 댓글 표시
% --- Executes on button press in size.
function size_Callback(hObject, eventdata, handles)
% hObject handle to size (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
info = imfinfo(image);
s=strcat(info.Width,info.Height);
set(handles.text2,'string',num2str(s));
guidata(hObject, handles);
% --- Executes on button press in open.
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, path1 ]= uigetfile('*.*', 'MultiSelect', 'on');
image = imread(filename);
p=strcat(path1,filename);
axes(handles.axes1);
imshow(image);
guidata(hObject, handles);
set(handles.path,'string',p);
set(handles.text4,'string',filename);
댓글 수: 0
채택된 답변
Elias Gule
2018년 1월 17일
I guess you're not seeing the image info that you want because you of this line:
s=strcat(info.Width,info.Height);
The data returned by info.Height and info.Width of type 'double', so what happens is that you are concatenating non-string data, hence strcat converts each entry to a char, such that the command effectively responds as if you wrote:
s = strcat(char(info.Width),char(info.Height));
which is of course not what you wanted to do.
What you should do is to first convert each number to a string. So the following change should work:
s = sprintf('width = %d, height = %d',info.Width,info.Height); % output is: width = 30, height = 0 if inputs are 30 and 40.
OR
s = strcat(num2str(info.Width),num2str(info.Height)); % output is: 3040 if inputs are 30 and 40.
댓글 수: 2
Image Analyst
2018년 1월 18일
You forgot to show the error messages so how can we help you? Please copy and paste ALL THE RED TEXT.
추가 답변 (4개)
Walter Roberson
2018년 1월 18일
Your line
image = imread(filename);
does not affect anything in the handles structure.
You appear to have created an image object in GUIDE with the tag 'image' and that is what is being referred to when you call upon handles.image in gray_Callback
We can tell from the code that gray_Callback expects handles.image to be a uicontrol with style 'text' or 'edit' whose string property designates a file name. I would suggest that you do not use a tag named image, as it just gets too confusing considering that image() is the key MATLAB routine for displaying images. (imshow() uses image() to do its work -- image() is the primary image display routine.)
I do not know why you have an existing image object handles.image at that point.
I would suggest that to store the name of the image, that you use handles.filename or a similar name. Your code would look something like
[filename, path1] = uigetfile('*.*', 'multiselect', 'off'); %note change to 'off' from 'on' -- your code is not equipped to handle multiple images
filename = fullfile(path1, filename);
handles.filename = filename;
....
and gray_Callback would refer to handles.filename instead of handles.image
댓글 수: 0
thinh dang
2018년 1월 18일
댓글 수: 1
Walter Roberson
2018년 1월 18일
[filenames, path1] = uigetfile('*.*', 'multiselect', 'on');
filenames = cellstr(filenames); %if only a single result was returned make it cell anyhow
filenames = fullfile(path1, filenames); %now it is a cell array of file names
num_files = length(filenames);
for K = 1 : num_files
thisname = filenames{K};
....
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!