how does line to area work?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how does line to area work?

Jeff Spector-2
Greetings,
 I am trying to convert segmented lines with a line width of 5 from line to
area. When I use the line to area command, the area is not correct. See
example macro here :


//setTool("polyline");
makeLine(242,91,242,96);
roiManager("Add");
run("Measure");
roiManager("Select", 0);
run("Line to Area");
roiManager("Add");
roiManager("Select", 1);
run("Measure");
//setTool("line");
makeLine(242, 90, 242, 95);
roiManager("Add");
roiManager("Select", 2);
run("Measure");
run("Line to Area");
roiManager("Add");
roiManager("Select", 3);
run("Measure");

For the segmented line I get Area 30 ( the line should by 5 x 5 = 25 pixels
For the segmented line to area I get Area 46
For the straight line tool I get area 25 in both cases.

It appears that line to area acts funny on segmented lines. I've also
noticed that the segmented line always starts in the upper lefthand corner
of a pixel where as the straight line tool will start where I click within
a pixel. Is there some kind of interpolation going on? I can work with
straight lines for now but just wanted to bring this up in case there are
people using line to area on segmented lines and weren't aware of this
behavior. Can someone please let me know why this is happening?

Thanks,
-Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does line to area work?

Michael Schmid-3
Hi Jeff,

in your macro, the setTool commands are commented out, so they have no
effect.
In any case, makeLine with four arguments always creates a straight line.

Also, it seems you have set the line thickness to 5 for the effects you
describe. Sometimes the macro recorder records essentially the same, but
not exactly the same as what you are doing manually...

Therefore, with your macro and a line thickness 5, I get an area of 25
for all four measurements, because it is a straight line in any case.

To create a polyline with makeLine, you could enter a point in between, e.g.
     makeLine(242,91,242,92,242,96);

With a real polyline, I get an area of 30. The reason is that the
polyline with a line width>1 uses the Straightener
(Edit>Selection>Straighten), because polylines can be curved (splines)
and this is a way to get subpixel resolution. This means that it
subdivides the original line in 1-pixel intervals, which results in 6
points (with five intervals in between). Then it creates an own image of
the straightened line, horizontally one pixel for each of the 6 points
mentioned above. The result has a length of 6 pixels.

With a polyline and "Line to area", the line is drawn with a circular
brush, so it gets extended by half circles at the ends, which results in
an area of 46 in the current case. Unfortunately, in addition to this
inconsistency, it is also rather inaccurate if the coordinates are not
integer (still a remainder from the old days when there were only
integer selection coordinates in ImageJ).

In any case, even if ImageJ were perfect, you should not expect
consistency between these measurements: E.g. if a polyline line folds
back onto itself (acute angle) or crosses itself, the Straightener knows
nothing about this intersection and will return line width*length or
linewidth*(length+1), as above. In other words, if the polygon sweeps
over an area twice, it will count that area trice. Line to Area will
count the areas where the polygon passes twice or more times only once.


Michael
________________________________________________________________


On 17.12.19 16:57, Jeff Spector wrote:

> Greetings,
>   I am trying to convert segmented lines with a line width of 5 from line to
> area. When I use the line to area command, the area is not correct. See
> example macro here :
>
>
> //setTool("polyline");
> makeLine(242,91,242,96);
> roiManager("Add");
> run("Measure");
> roiManager("Select", 0);
> run("Line to Area");
> roiManager("Add");
> roiManager("Select", 1);
> run("Measure");
> //setTool("line");
> makeLine(242, 90, 242, 95);
> roiManager("Add");
> roiManager("Select", 2);
> run("Measure");
> run("Line to Area");
> roiManager("Add");
> roiManager("Select", 3);
> run("Measure");
>
> For the segmented line I get Area 30 ( the line should by 5 x 5 = 25 pixels
> For the segmented line to area I get Area 46
> For the straight line tool I get area 25 in both cases.
>
> It appears that line to area acts funny on segmented lines. I've also
> noticed that the segmented line always starts in the upper lefthand corner
> of a pixel where as the straight line tool will start where I click within
> a pixel. Is there some kind of interpolation going on? I can work with
> straight lines for now but just wanted to bring this up in case there are
> people using line to area on segmented lines and weren't aware of this
> behavior. Can someone please let me know why this is happening?
>
> Thanks,
> -Jeff
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does line to area work?

Wayne Rasband-2
In reply to this post by Jeff Spector-2
> On Dec 17, 2019, at 10:57 AM, Jeff Spector <[hidden email]> wrote:
>
> Greetings,
> I am trying to convert segmented lines with a line width of 5 from line to
> area. When I use the line to area command, the area is not correct.

This bug should be fixed in the latest ImageJ daily build (1.52t15), thanks to new line to area conversion code from Michael Schmid.

-wayne


> See
> example macro here :
>
>
> //setTool("polyline");
> makeLine(242,91,242,96);
> roiManager("Add");
> run("Measure");
> roiManager("Select", 0);
> run("Line to Area");
> roiManager("Add");
> roiManager("Select", 1);
> run("Measure");
> //setTool("line");
> makeLine(242, 90, 242, 95);
> roiManager("Add");
> roiManager("Select", 2);
> run("Measure");
> run("Line to Area");
> roiManager("Add");
> roiManager("Select", 3);
> run("Measure");
>
> For the segmented line I get Area 30 ( the line should by 5 x 5 = 25 pixels
> For the segmented line to area I get Area 46
> For the straight line tool I get area 25 in both cases.
>
> It appears that line to area acts funny on segmented lines. I've also
> noticed that the segmented line always starts in the upper lefthand corner
> of a pixel where as the straight line tool will start where I click within
> a pixel. Is there some kind of interpolation going on? I can work with
> straight lines for now but just wanted to bring this up in case there are
> people using line to area on segmented lines and weren't aware of this
> behavior. Can someone please let me know why this is happening?
>
> Thanks,
> -Jeff
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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