1 function J=DrawSegmentedArea2D(P,Isize)
\r
2 % Draw the contour as one closed line in a logical image,
\r
3 % and make the inside of the contour true with imfill
\r
5 % J=DrawSegmentedArea2D(P,Isize)
\r
8 % P : The list with contour points 2 x N
\r
9 % Isize : The size of the output image [x y]
\r
12 % J : The binary image with the contour filled
\r
15 % y=[182 233 251 205 169];
\r
16 % x=[163 166 207 248 210];
\r
19 % J=DrawSegmentedArea(P,[400 400]);
\r
20 % figure, imshow(J);
\r
21 % hold on; plot([P(:,2);P(1,2)],[P(:,1);P(1,1)]);
\r
23 % Function is written by D.Kroon University of Twente (July 2010)
\r
27 % Loop through all line coordinates
\r
28 x=round([P(:,1);P(1,1)]); x=min(max(x,1),Isize(1));
\r
29 y=round([P(:,2);P(1,2)]); y=min(max(y,1),Isize(2));
\r
30 for i=1:(length(x)-1)
\r
31 % Calculate the pixels needed to construct a line of 1 pixel thickness
\r
32 % between two coordinates.
\r
33 xp=[x(i) x(i+1)]; yp=[y(i) y(i+1)];
\r
34 dx=abs(xp(2)-xp(1)); dy=abs(yp(2)-yp(1));
\r
36 if(xp(2)>xp(1)), xline=xp(1):xp(2); else xline=xp(1):-1:xp(2); end
\r
37 if(yp(2)>yp(1)), yline=yp(1):yp(2); else yline=yp(1):-1:yp(2); end
\r
39 if(xp(2)>xp(1)), xline=xp(1):xp(2); else xline=xp(1):-1:xp(2); end
\r
40 yline=linspace(yp(1),yp(2),length(xline));
\r
42 if(yp(2)>yp(1)), yline=yp(1):yp(2); else yline=yp(1):-1:yp(2); end
\r
43 xline=linspace(xp(1),xp(2),length(yline));
\r
45 % Insert all pixels in the fill image
\r
46 J(round(xline+1)+(round(yline+1)-1)*size(J,1))=1;
\r
48 J=bwfill(J,1,1); J=~J(2:end-1,2:end-1);