필터 지우기
필터 지우기

Open an image in a GUI

조회 수: 2 (최근 30일)
Claire Redfield
Claire Redfield 2013년 2월 27일
Hello guys, I have
[f,p] = uigetfile({'*.png;*.jpg;*.bmp;*.tif','Supported images';...
'*.png','Portable Network Graphics (*.png)';...
'*.jpg','J-PEG (*.jpg)';...
'*.bmp','Bitmap (*.bmp)';...
'*.tif','Tagged Image File (*.tif,)';...
'*.*','All files (*.*)'});
x = imread([p f]);
himage=imshow(x);
title(f)
Which can open an image file and imshow it. My question is: How may i associate it with a button in a GUI ike
uicontrol('String', 'Original',...
'Callback', 'imshow(x);title Original;',...
'Units','normalized',...
'Position',[0 0 .15 .07]);

답변 (2개)

Jan
Jan 2013년 2월 27일
편집: Jan 2013년 2월 27일
You can store the code to select and display the image in the button's callback function:
uicontrol('String', 'Original', ...
'Callback', @myCallback);
function myCallback(ObjectH, EventData)
FigureH = ancestor(ObjectH, 'figure');
[f,p] = uigetfile(...);
x = imread(fullfile(p, f));
himage = imshow(x, 'Parent', FigureH);
title(f)
  댓글 수: 1
Claire Redfield
Claire Redfield 2013년 2월 27일
Thank you, i have saved the function but for uicontrol('String', 'Original', ... 'Callback', 'myCallback',... 'Units','normalized',... 'Position',[.80 0 .15 .07]); it just doesnt work...

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2013년 2월 27일
figure;
ax = axes;
figure; peaks %another figure
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.1 0.1 0.1 0.1],...
'String','Push Me!',...
'Callback',@(~,~)imshow(imread('cameraman.tif'),'parent',ax)); %first axes!!!
Specify the 'Parent' of the image in imshow(). This is explained in a Note in the doc for imshow
Note: If you are building a GUI where you want to control the figure and axes properties, be sure to use the imshow(..., 'Parent', ax) syntax.
  댓글 수: 2
Claire Redfield
Claire Redfield 2013년 2월 27일
imshow(imread('cameraman.tif') its just read a specific image while i want to open any image i choose, is there any way to do that?
Sean de Wolski
Sean de Wolski 2013년 2월 27일
All you have to do is change the string to whatever you selected with uigetfile. I was demonstrating how you put an image on a specific axes, which is what I thought you were having trouble with.
It look slike you have the imread part down so just pull that out of the callback for the pushbutton.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by