Re: snake ROIs (was: can i draw cylinders!)
Posted by Gabriel Landini on Oct 24, 2006; 12:06pm
URL: http://imagej.273.s1.nabble.com/can-i-draw-cylinders-tp3701211p3701216.html
On Tuesday 24 October 2006 10:51, Christophe Leterrier wrote:
> Thank you for your advices, but maybe I wasn't clear enough :
> I don't want to paint on my image, I want to define ROIs.
I think that the difference is trivial. The painted image can be a new
duplicated one and the ROI extracted from it. You can run that in batch mode,
so it is transparent (see macro below).
> For freehand lines I agree you can define circle at each point of the
> line, but what about segmented lines ? What a waste of processing time
> to interpolate all the coordinates between the extremities of each
> segment and draw a circle centered on each point
Once you know the start and end of the line segment, the interpolation (this
is Bresenham's algorithm) is extremely quick. You could do that in a macro
and still would be fast. I think that the circular ROI drawing would be the
slow steo.
BTW, the distance transform to get the desired thickened line is fine for not
so large images (about than 1000x1000), but gets slower with larger ones. The
macro below expects the line or area selection already drawn (yes, it works
with areas, too):
a=getTitle();
setBatchMode(true);
run("Add to Manager ");
run("Select None");
mine=roiManager("Count");
run("Duplicate...", "title=test-1");
roiManager("Select", mine-1);
run("Fill");
run("Select None");
run("Invert");
run("Distance Map");
setThreshold(0, 15); // sets radius of line
run("Convert to Mask");
run("Create Selection");
roiManager("Add");
selectImage(a);
roiManager("Select", mine);
setBatchMode(false);
I am using white foreground with black background, I haven't tested with those
inverted. Let me know if that does not work.
> Much better would be
> to incrementally define a ROI by adding elements : circle at the first
> point followed by rectangle along first segment, followed circle at the
> second point, repeat for each angle point of the segmented line until
> you reach the last point.
That only works for segmented lines, not freehand ones, I think.
Cheers,
Gabriel