Posted by
lechristophe on
Oct 24, 2006; 2:22pm
URL: http://imagej.273.s1.nabble.com/can-i-draw-cylinders-tp3701211p3701217.html
I tested your macro, and it worked with minor modifications (concerning
inverting luts and images). Thanks a lot for the idea of the distance
map, which is brilliant.
Here's the final macro for those who are interested :
a=getTitle();
setBatchMode(true);
run("Add to Manager ");
run("Select None");
mine=roiManager("Count");
run("Duplicate...", "title=test-1");
setBackgroundColor(0,0,0);
setForegroundColor(255,255,255);
run("Select All");
run("Clear");
run("Select None");
roiManager("Select", mine-1);
run("Fill");
run("Select None");
run("Invert");
run("Invert LUT");
run("Distance Map");
setThreshold(0, 15); // sets radius of line
run("Convert to Mask");
run("Create Selection");
roiManager("Add");
close();
selectImage(a);
roiManager("Select", mine);
// roiManager("Select", mine-1);
// roiManager("Delete");
setBatchMode(false);
The two commented-out lines at the end are used to optionnally remove
the original line selection if needed.
What would be nice is to have that wrapped as a tool, but instant update
of the tracings would be very ressource-consuming I think.
Christophe
Gabriel Landini wrote:
> 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
>