Clear Filters
Clear Filters

i want to use imfreehand on an image displayed on axes and display the selected area on clicking an button in the same axes in GUI but when i am done with imfreehand and while i am using imshow to display it i get error

1 view (last 30 days)
{ this the error i get:
Error using images.internal.imageDisplayParsePVPairs>parseParamValuePairs (line 150) Function IMAGEDISPLAYPARSEPVPAIRS expected an even number of parameter/value arguments.
Error in images.internal.imageDisplayParsePVPairs (line 133) [common_args,specific_args] = parseParamValuePairs(varargin(param1_index:end),valid_params,...
Error in images.internal.imageDisplayParseInputs (line 69) [common_args,specific_args] = images.internal.imageDisplayParsePVPairs(varargin{:});
Error in imshow (line 222) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in newGUI>pushbutton9_Callback (line 128) imshow(I,'parent');
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in newGUI (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)newGUI('pushbutton9_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback }
% --- 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)
{ This is the code:
axes(handles.axes7); % Assuming you want axes2 to be the one you draw in. handleToDrawing = imfreehand(handles.axes7); %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);
}

Answers (1)

Andrew Chen
Andrew Chen on 7 Mar 2019
Well almost a year later but if you still need an answer, here's something that worked for me:
Assume you have an image displayed on 'axis1' and want to push a button, use imfreehand() and then display the ROI of the image in a new axis, 'axis2'. Also lets say 'data' is whay is displayed in 'axis1'.
This should work for the pushbutton:
function DrawROIButton_Callback(hObject, eventdata, handles)
h = imfreehand(handles.axis1); %call imfreehand on what is displayed in axis1
handles.mask = h.createMask(); %create and store binary mask in handles.mask
axes(handles.axis2);
imshow(handles.mask.*handles.data); %Dispy the result of the original image and mask in axis2
guidata(hObject,handles);
Hope it helps, if you still need it

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!