How can i remove the crop mark in gui?
Show older comments
Hi, i have a crop button in the GUI, and i can click the button and then to crop the image displayed in axes. How do i remove the crop mark if i want to recrop again? I want to clear the crop mark if there is any in the image once i click the button.
function BtnCrop_Callback(hObject, eventdata, handles)
handles.output = hObject;
handles.currentAxes = get(handles.Axes,'Children');
if isempty(handles.currentAxes) == false
promptMesg = sprintf('Are you sure to crop the image?');
button = questdlg(promptMesg, 'Crop the image','Yes','No','Yes');
if strcmpi(button,'Yes')
handles.k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint');
handles.finalRect = rbbox;
point2 = get(gca,'CurrentPoint');
point1 = point1(1,1:2);
point2 = point2(1,1:2);
p1 = min(point1,point2);
offset = abs(point1-point2);
handles.x = round([p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)]);
handles.y = round([p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)]);
handles.cropSuccess = true;
hold on
axis manual
plot(handles.x,handles.y) ;
% pause(2)
% delete(hPlot);
else
handles.cropSuccess = false;
end
else
errordlg('No image is selected!');
end
guidata(hObject,handles);
The delete(hPlot) i tried is not exactly what i want. What i want is every time i click the button, it will check is there any crop mark in the image, if there is, then it will be removed (handles.x and hanles.y will also be deleted); if not, then i can start the new cropping.
Thanks a lot.
Accepted Answer
More Answers (1)
Image Analyst
on 19 Jun 2014
I don't see any cropping going on. No indexing, no calling imcrop(), nothing. Using hPlot to get the handle to the line you plotted, and then deleting that handle will remove the line that you just drew from the image. It will not remove the x and y fields from handles like you said. The x and y fields will still be there, though the box in the overlay is gone.
You should probably put the delete(hPlot) before the call to plot:
if exist('hPlot', 'var')
delete(hPlot);
end
hPlot = plot(handles.x, handles.y)
croppedImage = imcrop(originalImage, handles.finalRect);
2 Comments
Elsie
on 19 Jun 2014
Image Analyst
on 19 Jun 2014
Explain how. You're just defining a box but nothing gets cropped . No image gets cropped, no matrix gets cropped, at least not in the code you showed.
Categories
Find more on Detect, Extract, and Match Features 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!