/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dic_calc_rects.m

  • Committer: Suren A. Chilingaryan
  • Date: 2009-01-15 13:50:29 UTC
  • Revision ID: csa@dside.dyndns.org-20090115135029-wleapicg9a4593tp
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function rect = dic_calc_rects(xy,halfwidth,img)
 
2
 
 
3
% Calculate rectangles so imcrop will return image with xy coordinate inside center pixel
 
4
 
 
5
default_width = 2*halfwidth;
 
6
default_height = default_width;
 
7
 
 
8
% xy specifies center of rectangle, need upper left
 
9
upperleft = round(xy) - halfwidth;
 
10
 
 
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));
 
18
 
 
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);
 
24
 
 
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]);
 
29
width(idx) = 0;
 
30
height(idx) = 0;
 
31
 
 
32
rect = [left upper width height];
 
33
 
 
34
%-------------------------------
 
35
%
 
36
function [coordinates, breadth] = adjust_lo_edge(coordinates,edge,breadth)
 
37
 
 
38
indx = find( coordinates<edge );
 
39
if ~isempty(indx)
 
40
    breadth(indx) = breadth(indx) - abs(coordinates(indx)-edge);
 
41
    coordinates(indx) = edge;
 
42
end
 
43
 
 
44
%-------------------------------
 
45
%
 
46
function [coordinates, breadth] = adjust_hi_edge(coordinates,edge,breadth)
 
47
 
 
48
indx = find( coordinates>edge );
 
49
if ~isempty(indx)
 
50
    breadth(indx) = breadth(indx) - abs(coordinates(indx)-edge);
 
51
    coordinates(indx) = edge;
 
52
end