Brett ]]>

The edited version does indeed look better. Perhaps Dirk can chime in, if he has any thoughts on potential gotchas from making that change.

Thanks! Love this thread!

Brett

]]>I suggest changing two lines in Dirk code:

DT(:,1)=DT(:,1)./max(LL.^2,eps); DT(:,2)=DT(:,2)./max(LL.^2,eps);

into:

DT(:,1)=DT(:,1)./max(LL,eps); DT(:,2)=DT(:,2)./max(LL,eps);

Check out the difference by evaluating an example:

xy = [1 1; 1 4; 8 1; 3 6; 2 7; 2 9; 4 10; 5 10; 5 8; 7 8; 7 10; 8 10; 10 10; 10 3]; old_1 = xy - LineNormals2D(xy); old_2 = xy + LineNormals2D(xy); new_1 = xy - LineNormals2D_edited(xy); new_2 = xy + LineNormals2D_edited(xy); figure('Units', 'normalized', 'OuterPosition', [.1 .1 .8 .8]); subplot(1, 2, 1); plot( xy(:, 1), xy(:, 2), 'ro:', ... old_1(:, 1), old_1(:, 2), 'g*-', ... old_2(:, 1), old_2(:, 2), 'b*-'); axis([-1 12 -1 12]); title('original'); subplot(1, 2, 2); plot( xy(:, 1), xy(:, 2), 'ro:', ... new_1(:, 1), new_1(:, 2), 'g*-', ... new_2(:, 1), new_2(:, 2), 'b*-'); axis([-1 12 -1 12]); title('edited');

Unfortunately it doesn’t fix the problem with changing thickness …

]]>Also, I love your email signature. ;)

Brett

]]>The benefit of this method is a smoother mask that handles the corners in a more intuitive way.

]]>Sven, can you send your address, please, to:

char(cumsum([98 16 -13 15 0 -70 69 -11 7 -10 7 7 -4 -1 -46 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2]))

Brett

]]>dxy = sqrt(sum(diff(xy,[],1).^2,2));]]>

If the desired output is the thin mask (without the polygon boundary used to get it), then it would be possible to do something like this:

xy = getPosition(h); % Calculate the cumulative pixel distance along line dxy = sum(diff(xy,[],1).^2,2); cs = cat(1,0,cumsum(dxy)); % Resample at sub-pixel intervals sampCs = linspace(0,cs(end),ceil(cs(end)/0.5)); sampXy = interp1(cs,xy,sampCs); sampXyRnd = round(sampXy); % Mask 'on' pixels along the way imSize = size(lily); sampInds = sub2ind(imSize(1:2), sampXyRnd(:,2), sampXyRnd(:,1)); mask = false(imSize); mask(sampInds) = true; % Show the result ax(2) = subplot(1,2,2); imshow(mask) title('Lovely Lily Mask')

This would create a single-pixel (within rounding) thin mask along the drawn polyline which could be dilated if you needed a thicker line mask.

Nevertheless, it’s a little “hacky” and the method you showed using line normals is still preferable in my book.

Thanks,

Sven.

It lists some JSON libraries:

– JSONlab (Matlab)

– org.json (Java)

– Json.NET (.NET)

– fastJSON (.NET) ]]>