How to fix coordinates of a ROI using Imrect
조회 수: 4 (최근 30일)
이전 댓글 표시
h = imrect(handles.axes1, p);
p = wait(h);
p = h.getPosition();
assignin('base','p',round(p))
addNewPositionCallback(h,@(p)assignin('base','p',p));
Hello. im using the imrect tool to be able to select a region of interest on an image (the image is on an axes component).
p = [leftColumn, topRow, width, height];
p1=evalin('base','p');
%Get x & y coordinates
sp(1) = round(p(1)); %xmin
sp(2) = round(p(2)); %ymin
sp(3) = round(p(1))+round(p(3)); %xmax
sp(4) = round(p(2))+round(p(4)); %ymax
ROI = IM(sp(2):sp(4), sp(1): sp(3),:); % This is the ROI (indexing is (ymin:ymax, xmin:xmax)
Once I have defined the ROI once, sometimes I want the ability for it not to change. So when I load up different images i am always looking at the same part. I have tried the following but I cant get it working. (I use a radio button to toggle between keeping it fixed or not fixed). the current X and Y values of the ROI are already written to edit boxes.
if (get(handles.rButtonFix,'Value') == get(handles.rButtonFix,'Min'))
ROI = IM(sp(2):sp(4), sp(1): sp(3),:); % This is the ROI (indexing is (ymin:ymax, xmin:xmax)
else
sp(2)=num2str(get(handles.editY,'String'))
sp(1)=num2str(get(handles.editX,'String'))
ROI = IM(sp(2):sp(4), sp(1): sp(3),:);
end
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!