-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleofInterest.m
More file actions
32 lines (23 loc) · 1.22 KB
/
RectangleofInterest.m
File metadata and controls
32 lines (23 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% x and y are the original x and y coordinate, w is width, h is height,
% in case of more iterations, m is magnification factor, dx and dy are
% offests in the x and y
function RectangleofInterest(pos,m,dx,dy,k)
if (pos(3)*m+dx)/k(2) > 1
annotation('textarrow',[0.45 0.5],[0.45 0.5],...
'String','the x coordinate window is too large.','FontSize',12);
elseif (pos(4)*m+dy)/k(1) > 1
annotation('textarrow',[0.45 0.5],[0.45 0.5],...
'String','the x coordinate window is too large.','FontSize',12);
else
j = [(pos(1)+dx) (pos(2)+dy) (pos(3)*m+dx) (pos(4)*m+dy)];
h = imrect(gca, j);
setResizable(h,1)
%annotation('rectangle',[(pos(1)+dx)/k(1) (pos(2)+dy)/k(2) (pos(3)*m+dx)/k(1) (pos(4)*m+dy)/k(2)])
addNewPositionCallback(h,@(p) title(mat2str(p,3)));
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(h,fcn);
%annotation('textarrow',[(pos(1)+(pos(3)/2))/k(2) (pos(3)+dx)*0.5/k(2)],[(pos(2)+(pos(4)/2))/k(1) (pos(4)+pos(2))/k(1)],...
% 'String','We are here.','FontSize',14);
end
%imwrite(j,'box.png','png')
csvwrite('box.txt',[(pos(1)+dx) (pos(2)+dy) (pos(3)*m+dx) (pos(4)*m+dy)])