Crop image from an axes used in a GUI

9 vues (au cours des 30 derniers jours)
JR
JR le 18 Fév 2015
Réponse apportée : JR le 20 Fév 2015
listBoxStrings = get(handles.listbox1,'String');
ListBoxValue = get(handles.listbox1,'Value');
if(find(strcmp(listBoxStrings,'Afghanistan')) == ListBoxValue)
set(handles.text3,'String','Processing image for Afghanistan, please wait!');
Rect = imrect(gca,[50 20 50 50]);
setColor(Rect,'green')
setFixedAspectRatioMode(Rect,1);
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(Rect,fcn);
pos = getPosition(Rect);
I2 = imcrop(handles.axes1,pos);
imshow(handles.axes1,I2);
This code is linked to a button, when I push the button it gives me the square white crop on top of the image. I get an error though:
I can't crop the image, due to this error. The image is a JPEG
Thanks.

Réponses (1)

JR
JR le 20 Fév 2015
listBoxStrings = get(handles.listbox1,'String');
ListBoxValue = get(handles.listbox1,'Value');
if(find(strcmp(listBoxStrings,'Afghanistan')) == ListBoxValue)
set(handles.text3,'String','Processing image for Afghanistan, please wait!');
Rect = imrect(gca,[50 20 50 50]);
setColor(Rect,'green')
setFixedAspectRatioMode(Rect,1);
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(Rect,fcn);
pos = getPosition(Rect);
Crop = imcrop();
imshow(Crop, 'Parent', handles.axes1);
guidata(hObject, handles);
axis(handles.axes1, 'image')
This code works and I can now crop, but I am using my own free hand crop rectangle. How would I be able to still crop, but using the box I have already made?

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by