Fast Math Operations on Images
Posted by haider on Sep 01, 2014; 11:47pm
URL: http://imagej.273.s1.nabble.com/Fast-Math-Operations-on-Images-tp5009453.html
Hello everyone
I have been looking at ways to do mathematical operations on an ImageStack in the most optimized way in ImageJ possible. The first method is to simply iterate through every pixel of every slice of the image (two for loops). I perform three operations on the pixels of two identical size image stacks: add (3/8) , square root , multiply by 2 . There are 8388608 x 2 elements and it takes like 11 seconds to modify the two image stacks simultaneously. The next thing I tried using was the internal ImageJ commands:
IJ.run( ing, "Add...", "value= 0.4" )
IJ.run( img, "Square Root", "")
IJ.run( img, "Multiply...", "value=2")
This seems much faster but the problem is that only the square root operation is performed on the whole image stack (I get a prompt where I conform that the square root should be performed on the whole stack). The other two operations only get performed on the first slice of the stack. The other issue with this approach is that I can not add (3/8) to each pixel because the pixels are stores as int . And adding (3/8) has no effect. Is there a way to perform adding and multiplying with the internal ImageJ commands such that they get performed on the whole stack. Also, how would I get floating point precision using these internal commands.
Thanks
Haider