run("draw") slower than drawing lines with drawLine

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

run("draw") slower than drawing lines with drawLine

Emmanuel Levy
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");

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
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Emmanuel Levy
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?)

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?

Thanks for any hint!

Emmanuel




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
>
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Rasband, Wayne (NIH/NIMH) [E]
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
>>
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Emmanuel Levy
> 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.

I didn't know that, it is great. I have to say, up to now I converted
TIF to PNG for archiving because the compression is lossless and it
takes less space (sometimes over 10x less with very dark images).
However the advantages you describe below made me use TIF instead. I
like very much the idea of not having duplicate images for quality
control.

> 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:

That's great, I've done it and it works perfectly. This let me think
that I should use the same strategy to annotate my images - however it
looks like only numeric labels can be added. Is there a way to bybass
this?

Thanks again for your help!

Emmanuel



> -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
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Rasband, Wayne (NIH/NIMH) [E]
On Aug 11, 2011, at 6:17 PM, Emmanuel Levy wrote:

>> 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.
>
> I didn't know that, it is great. I have to say, up to now I converted
> TIF to PNG for archiving because the compression is lossless and it
> takes less space (sometimes over 10x less with very dark images).
> However the advantages you describe below made me use TIF instead. I
> like very much the idea of not having duplicate images for quality
> control.

You can save in TIFF format using compression by using the File>Save As>ZIP command, which saves the image as a ZIP-compressed TIFF file.

>> 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:
>
> That's great, I've done it and it works perfectly. This let me think
> that I should use the same strategy to annotate my images - however it
> looks like only numeric labels can be added. Is there a way to bybass
> this?

ImageJ uses ROI names as overlay labels when you check "Show names" in the Image>Overlay>Overlay Options dialog box, a feature that was added in the latest 1.45m daily build. You can set and view ROI names by pressing "y" (Edit>Selection>Properties). In a macro, use setSelectionName() to set the name and selectionName() to retrieve it.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: run("draw") slower than drawing lines with drawLine

Emmanuel Levy
> You can save in TIFF format using compression by using the File>Save As>ZIP command, which saves the image as a ZIP-compressed TIFF file.

That's very useful, I'll try it tomorrow - it looks faster than saving
as png, which is often the slowest step in my scripts.

> ImageJ uses ROI names as overlay labels when you check "Show names" in the Image>Overlay>Overlay Options dialog box, a feature that was added in the latest 1.45m daily build. You can set and view ROI names by pressing "y" (Edit>Selection>Properties). In a macro, use setSelectionName() to set the name and selectionName() to retrieve it.

That's great thanks! Actually I saw some examples (plugins -> examples
-> macros) where text is overlayed by transforming it into a ROI first
using maketext. I wonder if it this option wouldn't be better than
"show names", which works fine, but it seems that when I use the
"overlay to ROI" option (after saving and re-opening the image), ROI
names come back as sequential numbers.

Thanks for your help!

Emmanuel



>
> -wayne
>