I have a problem. Help me please! I want to show a size of a picture
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
thinh dang
el 17 de En. de 2018
Comentada: Walter Roberson
el 18 de En. de 2018
% --- 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 comentarios
Respuesta aceptada
Elias Gule
el 17 de En. de 2018
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 comentarios
Image Analyst
el 18 de En. de 2018
You forgot to show the error messages so how can we help you? Please copy and paste ALL THE RED TEXT.
Más respuestas (4)
Walter Roberson
el 18 de En. de 2018
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 comentarios
thinh dang
el 18 de En. de 2018
1 comentario
Walter Roberson
el 18 de En. de 2018
[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
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!