Pipelining / Multithreading virtual stack processing?

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

Pipelining / Multithreading virtual stack processing?

JesperSP
Hi everyone.

I'm doing some analysis on a (virtual) stack of images with a simple ImageJ macro script. The analysis is pretty slow, so I was wondering if there is some simple way to utilize the dual core/ Hyperthreading of my I5 laptop? I have already read a post saying that it's possible to do multithreading in javascript (http://imagej.588099.n2.nabble.com/a-multithreaded-example-in-javascript-td1478623.html), but I was thinking about a different way of speeding up the processing by "pipelining" the instructions.

My script does the following:


        ID=getImageID();
        stackSize=nSlices;
        starttime = getTime();
        run("Clear Results");
        for (i=1;i<stackSize;i++) {
                selectImage(ID);
                setSlice(i);
                run("Duplicate...", "title=mask");
                run("Variance...", "radius=1");
                setThreshold(9,255);
                run("Convert to Mask");
                run("Close-");
                run("Fill Holes");
                run("Erode");
                run("Select All");
                run("Copy");
                close();
                setPasteMode("Transparent-white");
                selectImage(ID);
                run("Paste");
                setThreshold(19,255);
                run("Analyze Particles...", "size=8-Infinity circularity=0.00-1.00 show=Nothing display exclude include record");
                IJ.log("\\Update:frame:"+i+" fps:"+ 1000*i/(getTime()-starttime));
        }
        close();

The most CPU intensive steps are probably the "Variance" and the "Analyze Particles" steps, but in principle these do not need to be run in the same CPU core. For example the Variance could be run on image 2 in the stack by 2nd CPU core while 1st CPU core is still doing "Analyze Particles". Is there any (simple) way to program this in a macro/javascript, or will I have to make a real java plugin to do the trick? If anyone knows of another trick that might speed up the processing please let me know. My laptop is currently processing at a rate of 3.3 fps.

Cheers,
Jesper
Reply | Threaded
Open this post in threaded view
|

Re: Pipelining / Multithreading virtual stack processing?

Rasband, Wayne (NIH/NIMH) [E]
On Mar 21, 2011, at 6:27 AM, JesperSP wrote:

> Hi everyone.
>
> I'm doing some analysis on a (virtual) stack of images with a simple ImageJ
> macro script. The analysis is pretty slow, so I was wondering if there is
> some simple way to utilize the dual core/ Hyperthreading of my I5 laptop? I
> have already read a post saying that it's possible to do multithreading in
> javascript
> (http://imagej.588099.n2.nabble.com/a-multithreaded-example-in-javascript-td1478623.html),
> but I was thinking about a different way of speeding up the processing by
> "pipelining" the instructions.

Try using ImageJ 1.45c (or later). Thanks to Stephan Saalfeld and Michael Schmid, all commands in the Process>Filters menu, including Variance, are now multithreaded.

-wayne

> My script does the following:
>
>
> ID=getImageID();
> stackSize=nSlices;
> starttime = getTime();
> run("Clear Results");
> for (i=1;i<stackSize;i++) {
> selectImage(ID);
> setSlice(i);
> run("Duplicate...", "title=mask");
> run("Variance...", "radius=1");
> setThreshold(9,255);
> run("Convert to Mask");
> run("Close-");
> run("Fill Holes");
> run("Erode");
> run("Select All");
> run("Copy");
> close();
> setPasteMode("Transparent-white");
> selectImage(ID);
> run("Paste");
> setThreshold(19,255);
> run("Analyze Particles...", "size=8-Infinity circularity=0.00-1.00
> show=Nothing display exclude include record");
> IJ.log("\\Update:frame:"+i+" fps:"+ 1000*i/(getTime()-starttime));
> }
> close();
>
> The most CPU intensive steps are probably the "Variance" and the "Analyze
> Particles" steps, but in principle these do not need to be run in the same
> CPU core. For example the Variance could be run on image 2 in the stack by
> 2nd CPU core while 1st CPU core is still doing "Analyze Particles". Is there
> any (simple) way to program this in a macro/javascript, or will I have to
> make a real java plugin to do the trick? If anyone knows of another trick
> that might speed up the processing please let me know. My laptop is
> currently processing at a rate of 3.3 fps.
>
> Cheers,
> Jesper
>
> --
> View this message in context: http://imagej.588099.n2.nabble.com/Pipelining-Multithreading-virtual-stack-processing-tp6191721p6191721.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Pipelining / Multithreading virtual stack processing?

JesperSP
Thanks for your reply. I just updated ImageJ to version 1.45e, and it appears that analysis is a bit faster (4.2 fps compared to 3.3 with the old version). I had hoped for a bit more speed increase, but any speed increase is welcome. It looks like the macro uses about 40% CPU now.