8-bit vs 16-bit ip.set() and ip.get() speed

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

8-bit vs 16-bit ip.set() and ip.get() speed

Michael Doube
Dear all

I've rewritten an old plugin that finds the principal axes of a stack
and creates an aligned copy of the stack, so that it can handle more
than just 16-bit images.

To do that, I use

targetIP.set(x, y, sourceStack.getProcessor(zA).get(xA,yA));

But this seems to be much slower on 8-bit images than 16-bit images.
For a test 256 x 256 x 256 stack, the 16-bit image processes in 6
seconds, while the 8-bit image takes close to 2.5 minutes.

Is there a neat trick I can use to make my 8-bit images process as fast
as my 16-bit images?  The code is at:

http://github.com/mdoube/BoneJ/blob/master/src/Moments_3D.java

in alignToPrincipalAxes()

Cheers,

Michael
Reply | Threaded
Open this post in threaded view
|

Re: 8-bit vs 16-bit ip.set() and ip.get() speed

Albert Cardona-2
Michael,

This chunk:

sourceStack.getProcessor(zA)


... will result in the creation of a new processor for every call.
It's a very expensive method. See:

http://repo.or.cz/w/imageja.git/blob/d8c301fa7f114b5566c212a8211cbbfcdf4a6083:/ij/ImageStack.java#l232


You could go around by caching the processor in a variable for every zA.

Albert
Reply | Threaded
Open this post in threaded view
|

Re: 8-bit vs 16-bit ip.set() and ip.get() speed

Michael Doube
Albert,

Thanks for the excellent suggestion.  By caching as you suggest, 8-bit
processing is now much faster...

ImageProcessor[] sliceProcessors = new ImageProcessor[d + 1];
for (int z = 1; z <= d; z++) {
        sliceProcessors[z] = sourceStack.getProcessor(z);
}

then in the inner loop...

targetIP.set(x, y, sliceProcessors[zA].get(xA, yA));

Michael

Albert Cardona wrote:

> Michael,
>
> This chunk:
>
> sourceStack.getProcessor(zA)
>
>
> ... will result in the creation of a new processor for every call.
> It's a very expensive method. See:
>
> http://repo.or.cz/w/imageja.git/blob/d8c301fa7f114b5566c212a8211cbbfcdf4a6083:/ij/ImageStack.java#l232
>
>
> You could go around by caching the processor in a variable for every zA.
>
> Albert