Login  Register

Re: Strange results after "Fit Spline"

Posted by vischer on Oct 15, 2013; 9:49pm
URL: http://imagej.273.s1.nabble.com/Strange-results-after-Fit-Spline-tp5005151p5005192.html

Hi Michael,

yes, I assumed that an established algorithm was used, probably the same one as on:

http://mbostock.github.io/protovis/ex/splines.html

The problem is that some of the behaviour is not expected by the user;
obviously this happens when lengths of two adjacent segments differ by more than factor 5.
For example, at factor = 9, the length error is +5% (see macro below)

This is my observation:

1. line length is over-estimated  (see macro "Length Deviation" to create an error plot)
2. if factor > 5, artificial loops or u-turns are inserted
3. if factor > 5, the fitted line does not represent intuitive smoothing
4. getProfile silently does or does not invoke "fit Spline", depending on line width > 1
5. automatic smoothing of "getProfile" and "Straighten" can be avoided e.g. by run("Interpolate", "interval=0.1");

So far, I don't have a constructive suggestion, but for I now want to make aware of these pitfalls.

Norbert




//Length deviation of a straight line (100 px) consisting of 3 points
close("Line*");
run("Set Measurements...", "perimeter");
newImage("Line-spline-test", "8-bit ramp", 500, 200, 1);

totalLen = 100;
xx = newArray(0, 0,totalLen);
yy = newArray(90, 90, 90);
lengths = newArray(totalLen/2);//;left half only
run("Line Width...", "line=2");//profile then will employ smoothing
for (xPos = 0; xPos <totalLen/2; xPos++){
        xx[1] = xPos;
        makeSelection("polyline", xx, yy);
        pr = getProfile;
        run("Fit Spline");
        List.setMeasurements;
        lengths[xPos] = List.getValue("Length");
}
Plot.create("Fit Spline Error" ,"Position of 2nd point of 3-point-line (len=100 px)", "Measured length", lengths);
Plot.show;


>
>
>
> On 14. Oct 2013, at 11:02, Michael Schmid <[hidden email]> wrote:
>
> Hi Norbert,
>
> the way how spline fitting works in ImageJ is the following:
> There are two splines, one for the x coordinates and one for the y coordinates, each as a function of point number.
>
> You can see the x spline if you change the y coordinates to
>  yy = newArray(10, 20, 30, 40);
>
> As there are two independent splines for x and y, the x values stay unchanged if the y values collapse to a single value, as in your example.
>
> A fundamental change to how the splines work might break established procedures or macros, so I would tend to leave this unchanged.
>
> Michael
> ________________________________________________________________
> On Oct 12, 2013, at 22:51, Norbert Vischer wrote:
> Hello All,
>
> The "Fit Spline" algorithm gives strange results for segmented lines consisting of long and short segments. The macro below is an extreme example: Four points are  arranged as straight horizontal line, thus one would expect that fitting a straight line would not change anything.
> However, the fitting procedure extends the line with U-turns: the measured length jumps from 201 to 300.3 pix, and the profile (which automatically employs fitting) includes two peaks that are not on the line.
>
> Meanwhile I found out that I can avoid the problem by uncommenting the line containing "Interpolate". But possibly ImageJ could avoid such unexpected behaviour in the first place.
> By the way, the problem above also occurs if an end-point is recorded twice (replace 101 by 100 in the demo).
>
> Norbert
>
>
>
> close("spline-test");
> newImage("spline-test", "8-bit ramp", 500, 500, 1);
> makeRectangle(80, 50, 4, 100);
> changeValues(0, 255, 255);
>
> xx = newArray(100, 101, 300, 301);
> yy = newArray(90, 90, 90, 90);
> makeSelection("polyline", xx, yy);
> waitForUser;
> run("Set Measurements...", "perimeter");
> run("Clear Results");
>
> run("Measure");
> //run("Interpolate", "interval=0.1");
> run("Measure");
>
> run("Fit Spline");
> run("Measure");
> run("Plot Profile");

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Norbert Vischer
Research Engineer
Centre for Advanced Microscopy
Swammerdam Institute for Life Sciences (SILS)
University of Amsterdam
Science Park 904
1098 XH Amsterdam, the Netherlands

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html