1 function [Boundary1, Inner1, Boundary2, Inner2] = ...
\r
2 Cut_boundary(Region, Dense_pts)
\r
4 Min_x = min([Region.Shifts(1, 1), Dense_pts(1, :)]);
\r
5 Min_y = min([Region.Shifts(2, 1), Dense_pts(2, :)]);
\r
6 Max_x = max([Region.Shifts(1, 2), Dense_pts(1, :)]);
\r
7 Max_y = max([Region.Shifts(2, 2), Dense_pts(2, :)]);
\r
8 Image = zeros(Max_x-Min_x+1, Max_y-Min_y+1);
\r
10 Image(sub2ind(size(Image), ...
\r
11 Region.Boundary(1, :)-Min_x+1, Region.Boundary(2, :)-Min_y+1)) = 1;
\r
12 Image(sub2ind(size(Image), Dense_pts(1,:)-Min_x+1, Dense_pts(2,:)-Min_y+1)) = 1;
\r
14 % take the inner points to be close to midpoint of the line, on both sides
\r
15 Ldp = size(Dense_pts, 2);
\r
16 Midpt = Dense_pts(:, floor(Ldp/2)) + [1-Min_x; 1-Min_y];
\r
17 Normal = [Dense_pts(2, Ldp)-Dense_pts(2, 1); Dense_pts(1, 1)-Dense_pts(1, Ldp)];
\r
18 Normal = Normal/norm(Normal);
\r
19 Inner1 = Midpt + floor(5*Normal);
\r
20 Inner2 = Midpt - floor(5*Normal);
\r
22 Image1 = double(bwfill(Image, Inner1(2), Inner1(1)));
\r
23 Image2 = bwfill(Image, Inner2(2), Inner2(1));
\r
24 % not Image has zeros at the position of boundary and cutting line.
\r
25 % thickening nearly restores the original image boundary
\r
26 Boundary1 = Extract_region_reg(bwmorph(Image1¬(Image),'thicken'), 1);
\r
27 Boundary2 = Extract_region_reg(bwmorph(Image2¬(Image),'thicken'), 1);
\r
29 Boundary1 = Boundary1 + [Min_x-1; Min_y-1]*ones(1, size(Boundary1, 2));
\r
30 Boundary2 = Boundary2 + [Min_x-1; Min_y-1]*ones(1, size(Boundary2, 2));
\r
31 Inner1 = Inner1 + [Min_x-1; Min_y-1];
\r
32 Inner2 = Inner2 + [Min_x-1; Min_y-1];
\r