Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Aug 10, 2011; 2:54pm
URL: http://imagej.273.s1.nabble.com/run-draw-slower-than-drawing-lines-with-drawLine-tp3683528p3683531.html
On Aug 10, 2011, at 9:57 AM, Emmanuel Levy wrote:
> Hi Wayne,
>
> Wow, that's indeed so much faster thanks!!
>
>> You can also use an overlay to draw the contours non-destructively, and in color:
>
> May I ask you what is the advantage of this option? Does it mean there
> a simple way to subsequently "remove" the lines drawn? (even after
> saving of the image?)
There are many advantages. The image data is not changed. You can remove the contour lines. You can add and remove numeric labels. You can change the line color and width. You can display color lines on a grayscale image. The overlay is saved in the TIFF header. The overlay can be rendered on the image or on another images.
> One small additional thing for which I'm sure there is a trick: I have
> to add a label to each object. At the moment I'm doing it this way:
>
> nObjects = roiManager("count");
> for (object=0; object<nObjects/2 ; object++){
> roiManager("Select", object);
> getSelectionBounds(x, y, width, height);
> setFont("Arial", 20, "antiliased");
> drawString(object+1, x+width/2 - 5, y+ height/2 + 10);
> }
>
> is there a way to do that without a loop to make it as fast as the
> drawing of boundaries?
You can add and remove numeric labels in an overlay using the "Show numeric labels" option in the Image>Overlay>Overlay Options dialog box. Here is an example that creates an overlay with labels:
run("Overlay Properties...", "stroke=yellow width=1 show");
run("From ROI Manager");
It requires the 1.45m daily build, which adds the Image>Overlay>Overlay Options command.
-wayne
>
> On 10 August 2011 09:30, Rasband, Wayne (NIH/NIMH) [E]
> <
[hidden email]> wrote:
>> On Aug 9, 2011, at 11:55 PM, Emmanuel Levy wrote:
>>
>>> Hi,
>>>
>>> I'm drawing a contour line around identified objects for quality
>>> control. Given that I have a lot of objects, I'm trying to improve the
>>> "drawing speed".
>>>
>>> I tried 3 options:
>>>
>>> 1.
>>> roiManager("Select", object);
>>> run("Draw");
>>
>> It is *much* faster to draw all the object contours at once:
>>
>> roiManager("Deselect");
>> roiManager("Draw");
>>
>> You can also use an overlay to draw the contours non-destructively, and in color:
>>
>> roiManager("Deselect");
>> roiManager("Set Color", "yellow");
>> run("From ROI Manager"); // Image>Overlay>From ROI Manager
>>
>> -wayne
>>
>>
>>>
>>> 2.
>>> roiManager("Select", object);
>>> run("Area to Line");
>>> run("Clear", "slice");
>>>
>>> 3.
>>> roiManager("Select", object);
>>> getSelectionCoordinates(xCoordinates, yCoordinates);
>>> for (pix =0; pix < xCoordinates.length-1; pix++){
>>> drawLine(xCoordinates[pix], yCoordinates[pix] ,xCoordinates[pix+1],
>>> yCoordinates[pix+1] );
>>> }
>>>
>>> Option 3 is the fastest of all! (this let me wonder if the method
>>> "draw" couldn't be improved?). Actually, this is quite a stupid
>>> question but ... where should I look for code of "built-in" functions?
>>>
>>> Thanks!
>>>
>>> Emmanuel
>>