t1 = System.currentTimeMillis() for peak in peaks: sphere = sphereFactory.create( [int(peak[0]), int(peak[1]), int(peak[2])], radius, ra) s = sum(imap(FloatType.getRealFloat, sphere.cursor())) intensities1.append(float(s) / sphere.size()) t2 = System.currentTimeMillis() print "Elapsed time:", (t2 - t1), "ms" #print intensities1 # Try now with HyperSphereCursor hs = HyperSphere(copy2, Point(3), radius) size = hs.size() intensities2 = [] hsc = hs.cursor() t3 = System.currentTimeMillis() for peak in peaks: hsc.updateCenter([int(peak[0]), int(peak[1]), int(peak[2])]) s = sum(imap(FloatType.getRealFloat, hsc)) intensities2.append(float(s) / size) t4 = System.currentTimeMillis() print "Elapsed time:", (t4 - t3), "ms"
from net.imglib2 import Point from net.imglib2.algorithm.region.hypersphere import HyperSphere # create an empty image phantom = ops.create().img(array([xSize, ySize], 'l')) # use the randomAccess interface to place points in the image randomAccess = phantom.randomAccess() randomAccess.setPosition(array([xSize / 2, ySize / 2], 'l')) randomAccess.get().setReal(255.0) randomAccess.setPosition(array([xSize / 4, ySize / 4], 'l')) randomAccess.get().setReal(255.0) location = Point(phantom.numDimensions()) location.setPosition(array([3 * xSize / 4, 3 * ySize / 4], 'l')) hyperSphere = HyperSphere(phantom, location, 5) for value in hyperSphere: value.setReal(16) display.createDisplay("phantom", phantom) # create psf using the gaussian kernel op (alternatively PSF could be an input to the script) psf = ops.create().kernelGauss(array([10, 10], 'd')) # convolve psf with phantom convolved = ops.filter().convolve(phantom, psf) display.createDisplay("convolved", convolved)