def findPeaks(img4D, params): """ img4D: a 4D RandomAccessibleInterval params["frames"]: the number of consecutive time points to average towards detecting peaks with difference of Gaussian. Returns a list of lists of peaks found, one list per time point. """ frames = params["frames"] # Work image: the current sum sum3D = ArrayImgs.unsignedLongs([img4D.dimension(d) for d in [0, 1, 2]]) peaks = [] # Sum of the first set of frames compute(add([Views.hyperSlice(img4D, 3, i) for i in xrange(frames)])).into(sum3D) # Extract nuclei from first sum3D peaks.append(doGPeaks(sum3D, params)) # Running sums: subtract the first and add the last for i in xrange(frames, img4D.dimension(3), 1): compute(add(sub(sum3D, Views.hyperSlice(img4D, 3, i - frames)), Views.hyperSlice(img4D, 3, i))) \ .into(sum3D) # Extract nuclei from sum4D peaks.append(doGPeaks(sum3D, params)) return peaks
def testASMLongs(): img2 = ArrayImgs.unsignedLongs(dimensions) ImgUtil.copy( ImgView.wrap( Converters.convertRandomAccessibleIterableInterval( img1s, sampler_conv_longs), img1.factory()), img2)
from net.imglib2.algorithm.math.ImgMath import compute, block, div, offset, add from net.imglib2.img.display.imagej import ImageJFunctions as IL from net.imglib2.img.array import ArrayImgs from net.imglib2.type.numeric.real import FloatType from net.imglib2.view import Views from net.imglib2.util import Intervals from ij import IJ imp = IJ.getImage() # an 8-bit image img = IL.wrap(imp) # Create the integral image of an 8-bit input, stored as 64-bit target = ArrayImgs.unsignedLongs(Intervals.dimensionsAsLongArray(img)) # Copy input onto the target image compute(img).into(target) # Extend target with zeros, so that we can read at coordinate -1 imgE = Views.extendZero(target) # Integrate every dimension, cummulatively by writing into # a target image that is also the input for d in xrange(img.numDimensions()): coord = [0] * img.numDimensions() # array of zeros coord[d] = -1 # Cummulative sum along the current dimension # Note that instead of the ImgMath offset op, # we could have used Views.translate(Views.extendZero(target), [1, 0])) # (Notice though the sign change in the translation) integral = add(target, offset(imgE, coord)) compute(integral).into(target) # The target is the integral image integralImg = target