def withVirtualStack(time_window=None, subsample=None):
    with open(os.path.join(baseDir, csvFilename), 'r') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='"')
        header = reader.next()
        peaks = [
            RealPoint.wrap(imap(float, peak.split('::')))
            for peak in islice(header, 1, None)
        ]
        frames = [
            virtualPointsRAI(peaks,
                             radius,
                             interval,
                             inside=to8bitRange(
                                 map(float, islice(row, 1, None))))
            for row in reader
        ]
        if time_window:
            first, last = time_window
            frames = frames[first:last + 1]
        img4D = Views.stack(frames)
        # Scale by a factor of 'subsample' in every dimension by nearest neighbor, sort of:
        if subsample:
            img4D = Views.subsample(img4D, subsample)
        imp = ImagePlus("deltaF/F", ImageJVirtualStackUnsignedByte.wrap(img4D))
        imp.setDimensions(1, img4D.dimension(2), img4D.dimension(3))
        imp.setDisplayRange(0, 255)
        com = CompositeImage(imp, CompositeImage.GRAYSCALE)
        com.show()
        univ = Image3DUniverse(512, 512)
        univ.show()
        univ.addVoltex(com)
Exemplo n.º 2
0
def pyramidAreaAveraging(img,
                         top_level,
                         min_width=32,
                         sumType=UnsignedLongType,
                         mathType=UnsignedLongType,
                         converter=Util.genericIntegerTypeConverter()):
  """ Return a list of image views, one per scale level of the image pyramid,
      except for level zero (the first image) which is the provided img.
      All images are of the same type as the source img.
      Based on an integral image for fast computation.
  """

  img_type = img.randomAccess().get().createVariable()
  
  # Create an integral image in longs
  alg = IntegralImg(img, sumType(), converter)
  alg.process()
  integralImg = alg.getResult()

  # Create an image pyramid as views, with ImgMath and imglib2,
  # which amounts to scale area averaging sped up by the integral image
  # and generated on demand whenever each pyramid level is read.
  width = img.dimension(0)
  imgE = Views.extendBorder(integralImg)
  blockSide = 1
  level_index = 1
  # Corners for level 1: a box of 2x2
  corners = [[0, 0], [1, 0], [0, 1], [1, 1]]
  pyramid = [img]

  while width > min_width and level_index <= top_level:
    blockSide *= 2
    width /= 2
    # Scale the corner coordinates to make the block larger
    cs = [[c * blockSide for c in corner] for corner in corners]
    blockRead = div(block(imgE, cs), pow(blockSide, 2)) # the op
    # a RandomAccessibleInterval view of the op, computed with shorts but seen as bytes
    view = blockRead.view(mathType(), img_type.createVariable())
    # Views.subsample by 2 will turn a 512-pixel width to a 257 width,
    # so crop to proper interval 256
    level = Views.interval(Views.subsample(view, blockSide),
                           [0] * img.numDimensions(), # min
                           [img.dimension(d) / blockSide -1
                            for d in xrange(img.numDimensions())]) # max
    pyramid.append(level)
    level_index += 1 # for next iteration

  return pyramid
Exemplo n.º 3
0
# Corners for level 1: a box of 2x2
corners = [[0, 0], [1, 0], [0, 1], [1, 1]]
pyramid = []  # level 0 is the image itself, not added

while width > min_width:
    blockSide *= 2
    width /= 2
    # Scale the corner coordinates to make the block larger
    cs = [[c * blockSide for c in corner] for corner in corners]
    blockRead = div(block(imgE, cs), pow(blockSide, 2))  # the op
    # a RandomAccessibleInterval view of the op, computed with shorts but seen as bytes
    view = blockRead.view(UnsignedShortType(), UnsignedByteType())
    # Views.subsample by 2 will turn a 512-pixel width to a 257 width,
    # so crop to proper interval 256
    level = Views.interval(
        Views.subsample(view, blockSide),
        [0] * img.numDimensions(),  # min
        [
            img.dimension(d) / blockSide - 1
            for d in xrange(img.numDimensions())
        ])  # max
    pyramid.append(level)
"""
for i, level in enumerate(pyramid):
  imp_level = IL.wrap(level, str(i+1))
  imp_level.show()
  win = imp.getWindow().getCanvas().
"""

from java.lang import Runnable
from javax.swing import SwingUtilities
Exemplo n.º 4
0
from net.imglib2.view import Views

baseDir = "/home/albert/shares/cardonalab/Albert/2017-05-10_1018/"
srcDir = baseDir + "deconvolved/"
n5dir = os.path.join(srcDir, "n5")
dataset_name = "2017-5-10_1018_0-399_X203_Y155_Z65"

# Load entire 4D IsoView deconvolved and registered data set
img4D = readN5(n5dir, dataset_name)

# A mask: only nuclei whose x,y,z coordinate has a non-zero value in the mask will be considered
mask = None

# Split CM00+CM01 (odd) from CM02+CM03 (even) into two series
series = ["CM00-CM01", "CM02-CM03"]
img4Da = Views.subsample(img4D,
                         [1, 1, 1, 2]) # step
img4Db = Views.subsample(Views.interval(img4D, [0, 0, 0, 1], Intervals.maxAsLongArray(img4D)),
                         [1, 1, 1, 2]) # step

showStack(img4Da, title="%s registered+deconvolved" % series[0])
showStack(img4Db, title="%s registered+deconvolved" % series[1])

calibration = [1.0, 1.0, 1.0]
somaDiameter = 8 * calibration[0]

# Parameters for detecting nuclei with difference of Gaussian
params = {
 "frames": 5, # number of time frames to average, 5 is equivalent to 3.75 seconds: 0.75 * 5
 "calibration": calibration, # Deconvolved images have isotropic calibration
 "somaDiameter": somaDiameter, # in pixels
 "minPeakValue": 50, # determined by hand: the bright peaks