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)
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)
# create an empty image phantom=ops.create().img([xSize, ySize, zSize]) # make phantom an ImgPlus phantom=ops.create().imgPlus(phantom); # use the randomAccess interface to place points in the image randomAccess= phantom.randomAccess() randomAccess.setPosition([xSize/2, ySize/2, zSize/2]) randomAccess.get().setReal(255.0) randomAccess.setPosition([xSize/4, ySize/4, zSize/4]) randomAccess.get().setReal(255.0) location = Point(phantom.numDimensions()) location.setPosition([3*xSize/4, 3*ySize/4, 3*zSize/4]) hyperSphere = HyperSphere(phantom, location, 5) for value in hyperSphere: value.setReal(16) phantom.setName("phantom") # create psf using the gaussian kernel op (alternatively PSF could be an input to the script) psf=ops.create().kernelGauss([5, 5, 5]) # convolve psf with phantom convolved=ops.filter().convolve(phantom, psf)
#@ UIService ui #@OUTPUT ImgPlus phantom #@OUTPUT ImgPlus convolved #@OUTPUT ImgPlus deconvolved1 #@OUTPUT ImgPlus deconvolved2 from net.imglib2 import Point from net.imglib2.algorithm.region.hypersphere import HyperSphere xSize = 200 ySize = 200 # create an empty image phantom = ops.create().img([xSize, ySize]) location = Point(phantom.numDimensions()) location.setPosition([xSize / 2, ySize / 2]) hyperSphere = HyperSphere(phantom, location, 20) for value in hyperSphere: value.setReal(16) ui.show("phantom", phantom) psf1 = ops.create().kernelGauss([2, 2]) psf2 = ops.create().kernelGauss([4, 4]) # convolve psf with phantom convolved = ops.filter().convolve(phantom, psf1)
from net.imglib2.algorithm.math.ImgMath import compute, gen from net.imglib2.img.display.imagej import ImageJFunctions as IL from net.imglib2.type.numeric.integer import UnsignedByteType from net.imglib2.img.array import ArrayImgs from net.imglib2.util import Intervals from net.imglib2 import KDTree, Point locations = [(10, 15), (25, 40), (30, 75), (80, 60)] points = [ Point.wrap([x, y]) for x, y in [(10, 15), (25, 40), (30, 75), (80, 60)] ] values = [UnsignedByteType(v) for v in [128, 164, 200, 255]] kt = KDTree(values, points) dimensions = [100, 100] op = gen(kt, 10) target = ArrayImgs.unsignedBytes( Intervals.dimensionsAsLongArray(op.getInterval())) compute(op).into(target) IL.wrap(target, "KDTree").show()