diff options
Diffstat (limited to 'inst/polynomialCurves2d/polynomialCurveSetFit.m')
-rw-r--r-- | inst/polynomialCurves2d/polynomialCurveSetFit.m | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/inst/polynomialCurves2d/polynomialCurveSetFit.m b/inst/polynomialCurves2d/polynomialCurveSetFit.m index 4d36370..bfcc507 100644 --- a/inst/polynomialCurves2d/polynomialCurveSetFit.m +++ b/inst/polynomialCurves2d/polynomialCurveSetFit.m @@ -56,17 +56,18 @@ function [coefs lblBranches] = polynomialCurveSetFit(seg, varargin) seg(:, [1 end]) = 1; # skeletise le segmentat - seg = bwmorph(seg, 'shrink', Inf); + seg = bwmorph (seg, 'shrink', Inf); # compute image of multiple points (intersections between curves) - imgNodes = imfilter(double(seg), ones([3 3])) .* seg > 3; + imgNodes = imfilter (double (seg), ones ([3 3])) .* seg > 3; # compute coordinate of nodes, as c entroids of the multiple points - lblNodes = bwlabel(imgNodes, 8); - struct = regionprops(lblNodes, 'Centroid'); - nodes = zeros(length(struct), 2); - for i=1:length(struct) - nodes(i, [2 1]) = struct(i).Centroid; + lblNodes = bwlabel (imgNodes, 8); + strct = regionprops (lblNodes, 'Centroid'); + + nodes = zeros (length (strct), 2); + for i = 1:length (strct) + nodes(i, [2 1]) = strct(i).Centroid; end # debug @@ -87,7 +88,7 @@ function [coefs lblBranches] = polynomialCurveSetFit(seg, varargin) # Isolate the branches imgBranches = seg & ~imgNodes; - lblBranches = bwlabel(imgBranches, 8); + lblBranches = bwlabel (imgBranches, 8); # # donne une couleur a chaque branche, et affiche # map = colorcube(max(lblBranches(:))+1); @@ -95,11 +96,11 @@ function [coefs lblBranches] = polynomialCurveSetFit(seg, varargin) # imshow(rgbBranches); # number of curves - nBranches = max(lblBranches(:)); + nBranches = max (lblBranches(:)); # allocate memory - coefs = cell(nBranches, 1); - bnds = cell(nBranches, 1); + coefs = cell (nBranches, 1); + bnds = cell (nBranches, 1); # For each curve, find interpolated polynomial curve for i = 1:nBranches @@ -108,14 +109,14 @@ function [coefs lblBranches] = polynomialCurveSetFit(seg, varargin) points = chainPixels (imgBranch); # check number of points is sufficient - if size(points, 1) < max(deg+1-2, 2) + if size (points, 1) < max (deg+1-2, 2) # find labels of nodes - inds = unique(lblNodes(imdilate(imgBranch, true (3,3)))); + inds = unique (lblNodes(imdilate(imgBranch, true (3,3)))); inds = inds(inds ~= 0); - if length(inds) < 2 + if length (inds) < 2 warning ("geometry:poylnomialCurveSetFit", ... - ['Could not find extremities of branch number ' num2str(i)]); + "Could not find extremities of branch number %d\n", i); continue; end @@ -138,18 +139,18 @@ function [coefs lblBranches] = polynomialCurveSetFit(seg, varargin) end # find nodes closest to first and last points of the current curve - [dist, ind0] = minDistancePoints(points(1, :), nodes); ##ok<*ASGLU> - [dist, ind1] = minDistancePoints(points(end, :), nodes); + [dist, ind0] = minDistancePoints (points(1, :), nodes); ##ok<*ASGLU> + [dist, ind1] = minDistancePoints (points(end, :), nodes); # add nodes to the curve. points = [nodes(ind0,:); points; nodes(ind1,:)]; ##ok<AGROW> # parametrization of the polyline - t = parametrize(points); - t = t / max(t); + t = parametrize (points); + t = t / max (t); # fit a polynomial curve to the set of points - [xc yc] = polynomialCurveFit(... + [xc yc] = polynomialCurveFit (... t, points, deg, ... 0, {points(1,1), points(1,2)},... 1, {points(end,1), points(end,2)}); @@ -246,17 +247,20 @@ function points = chainPixels(img, varargin) endfunction +#FIXME not the best photo %!demo %! try %! pkg load image %! catch %! error ('You need the image package'); %! end +%! disp ('Affected by bug https://savannah.gnu.org/bugs/?49757'); %! %! [m, cmap] = imread ("default.img"); %! m = ind2gray (m, cmap); %! mbw = im2bw(m, graythresh(m)*1.3); %! +%! warning ("off", "geometry:poylnomialCurveSetFit", "local"); %! [c t] = polynomialCurveSetFit (mbw); %! %! figure(1) @@ -268,5 +272,4 @@ endfunction %! drawPolynomialCurve ([0 1], c{i}); %! endif %! endfor -%! %! hold off |