1
function rect = dic_calc_rects(xy,halfwidth,img)
3
% Calculate rectangles so imcrop will return image with xy coordinate inside center pixel
5
default_width = 2*halfwidth;
6
default_height = default_width;
8
% xy specifies center of rectangle, need upper left
9
upperleft = round(xy) - halfwidth;
11
% need to modify for pixels near edge of images
12
upper = upperleft(:,2);
13
left = upperleft(:,1);
14
lower = upper + default_height;
15
right = left + default_width;
16
width = default_width * ones(size(upper));
17
height = default_height * ones(size(upper));
19
% check edges for coordinates outside image
20
[upper,height] = adjust_lo_edge(upper,1,height);
21
[dum,height] = adjust_hi_edge(lower,size(img,1),height);
22
[left,width] = adjust_lo_edge(left,1,width);
23
[dum,width] = adjust_hi_edge(right,size(img,2),width);
25
% set width and height to zero when less than default size
26
iw = find(width<default_width);
27
ih = find(height<default_height);
28
idx = unique([iw; ih]);
32
rect = [left upper width height];
34
%-------------------------------
36
function [coordinates, breadth] = adjust_lo_edge(coordinates,edge,breadth)
38
indx = find( coordinates<edge );
40
breadth(indx) = breadth(indx) - abs(coordinates(indx)-edge);
41
coordinates(indx) = edge;
44
%-------------------------------
46
function [coordinates, breadth] = adjust_hi_edge(coordinates,edge,breadth)
48
indx = find( coordinates>edge );
50
breadth(indx) = breadth(indx) - abs(coordinates(indx)-edge);
51
coordinates(indx) = edge;