blogtng:2012-10-28:imglib2_first_test
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
blogtng:2012-10-28:imglib2_first_test [2012/10/30 14:31] – kota | blogtng:2012-10-28:imglib2_first_test [2016/05/24 12:46] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== ImgLib2, first test ====== | ||
+ | I pretty much enjoyed [[http:// | ||
+ | |||
+ | One of the core topic there was [[http:// | ||
+ | After coming back home, I tested ImgLib2 with the Jython code below. | ||
+ | |||
+ | Results were: | ||
+ | Started testImgLib2.py at Sun Oct 28 16:41:57 CET 2012 | ||
+ | * ImgLib2 cursor 333 millisec | ||
+ | * ImgLib2 for : 138 millisec | ||
+ | * ImagePlus 152 millisec | ||
+ | * ImageProcessor 114 millisec | ||
+ | * Pixel Array 59 millisec | ||
+ | for loop using Img iterator is a bit faster than going through ImagePlus using classic nested for-loop. Even with the classic nested for-loop, using ImageProcessor was a bit faster than Img. The fastest is of course accessing pixels via pixel array. I only did this via ImagePlus, but there should be also some methods to extract an array from Img, which I did not test. | ||
+ | |||
+ | Addendum: See also proper benchmark in the following link in ImageJ2 site: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | Thanks to Albert Cardona for commenting on this. | ||
+ | |||
+ | <sxh python> | ||
+ | # first trial with ImageLib2 | ||
+ | # iterations | ||
+ | |||
+ | from net.imglib2.img import ImagePlusAdapter | ||
+ | |||
+ | imp = IJ.openImage(" | ||
+ | img = ImagePlusAdapter.wrapReal(imp) | ||
+ | |||
+ | # accessing via ImagePlus | ||
+ | t3 = System.currentTimeMillis() | ||
+ | for i in range(imp.getHeight()): | ||
+ | for j in range(imp.getWidth()): | ||
+ | # print imp.getPixel(j, | ||
+ | imp.getPixel(j, | ||
+ | |||
+ | t4 = System.currentTimeMillis() | ||
+ | |||
+ | # accessing via ImageProcessor | ||
+ | t5 = System.currentTimeMillis() | ||
+ | ip = imp.getProcessor() | ||
+ | for i in range(imp.getHeight()): | ||
+ | for j in range(imp.getWidth()): | ||
+ | # print ip.getPixelValue(j, | ||
+ | ip.getPixelValue(j, | ||
+ | |||
+ | t6 = System.currentTimeMillis() | ||
+ | |||
+ | # ImgLib2 cursor | ||
+ | t1 = System.currentTimeMillis() | ||
+ | cursor = img.cursor() | ||
+ | cursor.fwd() | ||
+ | while cursor.hasNext(): | ||
+ | cursor.next() | ||
+ | # print cursor.get() | ||
+ | cursor.get() | ||
+ | |||
+ | t2 = System.currentTimeMillis() | ||
+ | |||
+ | t7 = System.currentTimeMillis() | ||
+ | for t in img: | ||
+ | # print t.get() | ||
+ | t.get() | ||
+ | |||
+ | t8 = System.currentTimeMillis() | ||
+ | |||
+ | # pixel array | ||
+ | t9 = System.currentTimeMillis() | ||
+ | pix = imp.getProcessor().getPixels() | ||
+ | for i in pix: | ||
+ | i = i | ||
+ | # print i | ||
+ | |||
+ | t10 = System.currentTimeMillis() | ||
+ | |||
+ | print ' | ||
+ | print ' | ||
+ | print ' | ||
+ | print ' | ||
+ | print 'Pixel Array', | ||
+ | |||
+ | </ |