Login  Register

Pipelining / Multithreading virtual stack processing?

Posted by JesperSP on Mar 21, 2011; 10:27am
URL: http://imagej.273.s1.nabble.com/Pipelining-Multithreading-virtual-stack-processing-tp3684999.html

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