How to block possibility to edit/drag impoly in matlab?

跟風遠走 提交于 2019-12-14 03:57:58

问题


I create a polygon on image_area in matlab. I used impoly. But after creation polygon. I need to block possibility to move and drag impoly (ROI is already created). I don't know how I should do it ?

I would appreciate for any help please.


回答1:


You can set the makeConstrainToRectFcn such that it is a rectangle encompassing your ROI, then whenever you try to move the latter it won't work. You can also, after creating the ROI, set the setVerticesDraggable method to false in order to prevent vertices from being dragged.

Sample code (adapted from example by the Mathworks):

clc
clear

figure
imshow('gantrycrane.png');
h = impoly(gca, [188,30; 189,142; 93,141; 13,41; 14,29]);

%// Get currentposition
Pos = getPosition(h);

%// Prevent draggable vertices
setVerticesDraggable(h,0);

%// Set up rectangle to prvent movement of ROI
fcn = makeConstrainToRectFcn('impoly', [min(Pos(:,1)) max(Pos(:,1))], [min(Pos(:,2)) max(Pos(:,2))]);

%// Apply function
h.setPositionConstraintFcn(fcn);

which results in this kind of situation (with red rectangle for illustration):



来源:https://stackoverflow.com/questions/38377867/how-to-block-possibility-to-edit-drag-impoly-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!