i made an gui and displayed an image now i want to use imfreehand to crop the image and update it at the same axes.

1 次查看(过去 30 天)
function varargout = newGUI(varargin)
% NEWGUI MATLAB code for newGUI.fig
% NEWGUI, by itself, creates a new NEWGUI or raises the existing
% singleton*.
%
% H = NEWGUI returns the handle to a new NEWGUI or the handle to
% the existing singleton*.
%
% NEWGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NEWGUI.M with the given input arguments.
%
% NEWGUI('Property','Value',...) creates a new NEWGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before newGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to newGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help newGUI
% Last Modified by GUIDE v2.5 24-Feb-2018 00:28:02
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @newGUI_OpeningFcn, ...
'gui_OutputFcn', @newGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before newGUI is made visible.
function newGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to newGUI (see VARARGIN)
% Choose default command line output for newGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes newGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = newGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file path] = uigetfile({'*.jpg;*.jpeg;*.jpe;*.jfif','JPEG (.jpg;.jpeg;.jpe;.jfif)';'*.png','PNG (.png)';'*.tif;*.tiff','TIF (.tif;.tiff)';'*.jpg;*.jpeg;*.jpe;*.jfif;*.png;*.tif;*.tiff','All Picture Files'
'*.*','All Files' },'Select Image To Search');
I=imread([path file])
set(handles.axes7,'Units','pixels');
resizePos = get(handles.axes7,'Position');
myImage= imresize(I, [resizePos(3) resizePos(3)]);
axes(handles.axes7);
imshow(I);
set(handles.axes7,'Units','normalized');
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes7); % Assuming you want axes2 to be the one you draw in.
i = imfreehand();
%i=imfreehand;
%position = wait(i);
M = ~i.createMask();
mask(:,:,1)=M;
mask(:,:,2)=M;
mask(:,:,3)=M;
I(mask)=255;
axes(handles.axes7);
imshow(I,'parent');
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by