crop the image and after cropping display the cropped image on axes

i have an image and i want to crop it i applied this code but its only cropping the image but not showing the cropped image on the axes :
I=imcrop(Iedge2);
pause(2)
imshow(I,'Parent',handles.axes2);
title('cropped image')
i want to show the message on the top of the axes area that "crop the image" when the crop process occurs and after selection of the area the cropped area will be shown to the `axes2 .some body please tell me is there is any function or method to do so?
thanks and regards`

Answers (1)

imshow() does not change the current axes if you specify a Parent axes, therefore title will display over the current axes, which might not be axes2. To avoid confusion, I always call axes() before doing anything with an axes. This will change the current axes and everything you do from then on (without specifically referring to an axes) will happen at the axes you just passed in to axes():
axes(handles.axes2); % Change current axes, gca, to handles.axes2
imshow(I, []); % No need to specify 'Parent' now.
title('Cropped Image', 'FontSize', 20);

8 Comments

thanks for your answer sir but sir it working same as the previous one i want to show the title "crop the image "on the top of my axes of gui when there is the crop window appears on the image and when the cropping is done or the sliding of crop box is done the cropped image will also be shown on the axes with a pause of two seconds "image after cropping"
Call imrect() with no arguments. Then you will get a box that you can drag the sides of. After the user double clicks inside the box to accept it, you can get the coordinates and call hPlot = plot(xBox, yBox) to replot the box on the image. Use pause(2) and delete(hPlot) to remove the box outline after 2 seconds. Then call cla('reset') and imshow(croppedImage) to show the cropped image.
i tred this but it's not working sir please suggest me where there is a need to correct the code
imrect(Iedge2)
hPlot = plot(xBox, yBox);
pause(2)
delete(hPlot)
cla('reset')
imshow(I, []); % No need to specify 'Parent' now.
title('Cropped Image', 'FontSize', 12);
@Image Analyst sir
a=imcrop(Iedge2);
pause(3)
axes(handles.axes2)
imshow(a, []); % No need to specify 'Parent' now.
title('Cropped Image', 'FontSize', 15);
sir this code is working as i want but how can i add title to the axes when the crop cursor on the image something like this :
a=imcrop(Iedge2, title 'please Crop the Image', 'FontSize', 15);
Try putting a title with instructions in it on the axes right after you call imshow() but before you call imrect(). Use title function:
title('Drag out a box. Adjust edges if needed. When ready, double-click inside it to accept it');
@Image Analyst sir sorry for asking again and again but sir i want to show that title with the crop function as u said it will show the title with cropped image but i want to show the title while crop window appears on the image. iam attaching the image in which there is no title on top while cropping what i want is to show an title on the axes while cropping
I think you're right. Now I seem to remember running across this before and I called the Mathworks about it. I think they might have given me some work around but I don't remember what it might have been. Try calling them. Alternatively you could just use text() to put some text into the overlay - see if that will remain after imcrop is called. Or (this I'm pretty sure will definitely work), just use GUIDE or uicontrol() to place a static text label somewhere on the figure window.
ok thank you sir :) i will try this

Sign in to comment.

Asked:

on 22 May 2016

Commented:

on 14 Jun 2016

Community Treasure Hunt

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

Start Hunting!