MATLAB Answers

I have a problem. Help me please! I want to show a size of a picture

1 ビュー (過去 30 日間)
thinh dang
thinh dang 2018 年 1 月 17 日
コメント済み: Walter Roberson 2018 年 1 月 18 日
% --- 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
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 件のコメント

thinh dang
thinh dang 2018 年 1 月 18 日
But it doesn't work guy! The problem is the link between two tag.:))
Image Analyst
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
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
thinh dang 2018 年 1 月 18 日
The exercise is to write guide to adjust picture that i multiselect. But now i running out of mind! The guide now is inextricable!

  1 件のコメント

Walter Roberson
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

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by