コード例 #1
0
n_channels = 1
n_slices = 1  # Z slices
n_frames = 1  # time frames
# Get current image
image = IJ.getImage()
# Check that we have correct dimensions
stack_size = image.getImageStackSize()  # raw number of images in the stack
if n_channels * n_slices * n_frames == stack_size:
    image.setDimensions(n_channels, n_slices, n_frames)
else:
    IJ.log('The product of channels (' + str(n_channels) + '), slices (' +
           str(n_slices) + ')')
    IJ.log('and frames (' + str(n_frames) + ') must equal the stack size (' +
           str(stack_size) + ').')
# Set calibration
pixel_width = 1
pixel_height = 1
pixel_depth = 1
space_unit = 'µm'
frame_interval = 1
time_unit = 's'
calibration = Calibration()  # new empty calibration
calibration.pixelWidth = pixel_width
calibration.pixelHeight = pixel_height
calibration.pixelDepth = pixel_depth
calibration.frameInterval = frame_interval
calibration.setUnit(space_unit)
calibration.setTimeUnit(time_unit)
image.setCalibration(calibration)
image.repaintWindow()
コード例 #2
0
                imp.setDisplayMode(IJ.COLOR)
                imp.setC(color)
                # imp.setDisplayRange(0.0, 3.0)
                # imp.show()

                log_info += 'frames: ' + str(imp.getNFrames()) + '\n'
                log_info += 'width: ' + str(imp.getWidth()) + '\n'
                log_info += 'height: ' + str(imp.getHeight()) + '\n'

                cal = Calibration()
                cal.setUnit('micron')
                cal.pixelHeight = resolution
                cal.pixelWidth = resolution
                cal.pixelDepth = 0.
                cal.fps = 1
                cal.frameInterval = 1
                imp.setCalibration(cal)

                #-------------------------
                # Instantiate model object
                #-------------------------

                model = Model()
                model.setPhysicalUnits('micron', 'frames')

                # Set logger
                model.setLogger(Logger.IJ_LOGGER)

                #------------------------
                # Prepare settings object
                #------------------------
コード例 #3
0
# Set dimensions
n_channels  = 1
n_slices  = 1    # Z slices
n_frames  = 1    # time frames
# Get current image
image = IJ.getImage()
# Check that we have correct dimensions
stack_size = image.getImageStackSize() # raw number of images in the stack
if n_channels * n_slices * n_frames == stack_size:
  image.setDimensions(n_channels, n_slices, n_frames)
else:
  IJ.log('The product of channels ('+str(n_channels)+'), slices ('+str(n_slices)+')')
  IJ.log('and frames ('+str(n_frames)+') must equal the stack size ('+str(stack_size)+').')
# Set calibration
pixel_width   = 1
pixel_height  = 1
pixel_depth   = 1
space_unit    = 'µm'
frame_interval  = 1
time_unit     = 's'
calibration = Calibration() # new empty calibration
calibration.pixelWidth    = pixel_width
calibration.pixelHeight   = pixel_height
calibration.pixelDepth    = pixel_depth
calibration.frameInterval   = frame_interval
calibration.setUnit(space_unit)
calibration.setTimeUnit(time_unit)
image.setCalibration(calibration)
image.repaintWindow()

コード例 #4
0
def process(srcDir, dstDir, currentDir, fileName, keepDirectories):
    print "Processing:"

    # Opening the image
    print "Open image file", fileName
    imp = IJ.openImage(os.path.join(currentDir, fileName))

    #Here we make sure the calibration are correct
    units = "pixel"
    TimeUnit = "unit"

    newCal = Calibration()
    newCal.pixelWidth = 1
    newCal.pixelHeight = 1
    newCal.frameInterval = 1

    newCal.setXUnit(units)
    newCal.setYUnit(units)
    newCal.setTimeUnit(TimeUnit)
    imp.setCalibration(newCal)
    cal = imp.getCalibration()

    dims = imp.getDimensions()  # default order: XYCZT

    if (dims[4] == 1):
        imp.setDimensions(1, 1, dims[3])

# Start the tracking

    model = Model()

    #Read the image calibration
    model.setPhysicalUnits(cal.getUnit(), cal.getTimeUnit())

    # Send all messages to ImageJ log window.
    model.setLogger(Logger.IJ_LOGGER)

    settings = Settings()
    settings.setFrom(imp)

    # Configure detector - We use the Strings for the keys
    # Configure detector - We use the Strings for the keys
    settings.detectorFactory = DownsampleLogDetectorFactory()
    settings.detectorSettings = {
        DetectorKeys.KEY_RADIUS: 2.,
        DetectorKeys.KEY_DOWNSAMPLE_FACTOR: 2,
        DetectorKeys.KEY_THRESHOLD: 1.,
    }

    print(settings.detectorSettings)

    # Configure spot filters - Classical filter on quality
    filter1 = FeatureFilter('QUALITY', 0, True)
    settings.addSpotFilter(filter1)

    # Configure tracker - We want to allow merges and fusions
    settings.trackerFactory = SparseLAPTrackerFactory()
    settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap(
    )  # almost good enough
    settings.trackerSettings['LINKING_MAX_DISTANCE'] = LINKING_MAX_DISTANCE
    settings.trackerSettings['ALLOW_TRACK_SPLITTING'] = ALLOW_TRACK_SPLITTING
    settings.trackerSettings['SPLITTING_MAX_DISTANCE'] = SPLITTING_MAX_DISTANCE
    settings.trackerSettings['ALLOW_TRACK_MERGING'] = ALLOW_TRACK_MERGING
    settings.trackerSettings['MERGING_MAX_DISTANCE'] = MERGING_MAX_DISTANCE
    settings.trackerSettings[
        'GAP_CLOSING_MAX_DISTANCE'] = GAP_CLOSING_MAX_DISTANCE
    settings.trackerSettings['MAX_FRAME_GAP'] = MAX_FRAME_GAP

    # Configure track analyzers - Later on we want to filter out tracks
    # based on their displacement, so we need to state that we want
    # track displacement to be calculated. By default, out of the GUI,
    # not features are calculated.

    # The displacement feature is provided by the TrackDurationAnalyzer.

    settings.addTrackAnalyzer(TrackDurationAnalyzer())
    settings.addTrackAnalyzer(TrackSpeedStatisticsAnalyzer())

    filter2 = FeatureFilter('TRACK_DISPLACEMENT', 10, True)
    settings.addTrackFilter(filter2)

    #-------------------
    # Instantiate plugin
    #-------------------
    trackmate = TrackMate(model, settings)

    #--------
    # Process
    #--------

    ok = trackmate.checkInput()
    if not ok:
        sys.exit(str(trackmate.getErrorMessage()))

    ok = trackmate.process()
    if not ok:
        sys.exit(str(trackmate.getErrorMessage()))

#----------------
# Display results
#----------------
    if showtracks:
        model.getLogger().log('Found ' +
                              str(model.getTrackModel().nTracks(True)) +
                              ' tracks.')
        selectionModel = SelectionModel(model)
        displayer = HyperStackDisplayer(model, selectionModel, imp)
        displayer.render()
        displayer.refresh()


# The feature model, that stores edge and track features.
    fm = model.getFeatureModel()

    with open(dstDir + fileName + 'tracks_properties.csv', "w") as file:
        writer1 = csv.writer(file)
        writer1.writerow([
            "track #", "TRACK_MEAN_SPEED (micrometer.secs)",
            "TRACK_MAX_SPEED (micrometer.secs)", "NUMBER_SPLITS",
            "TRACK_DURATION (secs)", "TRACK_DISPLACEMENT (micrometer)"
        ])

        with open(dstDir + fileName + 'spots_properties.csv',
                  "w") as trackfile:
            writer2 = csv.writer(trackfile)
            #writer2.writerow(["spot ID","POSITION_X","POSITION_Y","Track ID", "FRAME"])
            writer2.writerow(
                ["Tracking ID", "Timepoint", "Time (secs)", "X pos", "Y pos"])

            for id in model.getTrackModel().trackIDs(True):

                # Fetch the track feature from the feature model.
                v = (fm.getTrackFeature(id, 'TRACK_MEAN_SPEED') *
                     Pixel_calibration) / Time_interval
                ms = (fm.getTrackFeature(id, 'TRACK_MAX_SPEED') *
                      Pixel_calibration) / Time_interval
                s = fm.getTrackFeature(id, 'NUMBER_SPLITS')
                d = fm.getTrackFeature(id, 'TRACK_DURATION') * Time_interval
                e = fm.getTrackFeature(
                    id, 'TRACK_DISPLACEMENT') * Pixel_calibration
                model.getLogger().log('')
                model.getLogger().log('Track ' + str(id) +
                                      ': mean velocity = ' + str(v) + ' ' +
                                      model.getSpaceUnits() + '/' +
                                      model.getTimeUnits())

                track = model.getTrackModel().trackSpots(id)
                writer1.writerow(
                    [str(id), str(v),
                     str(ms), str(s),
                     str(d), str(e)])

                for spot in track:
                    sid = spot.ID()
                    x = spot.getFeature('POSITION_X')
                    y = spot.getFeature('POSITION_Y')
                    z = spot.getFeature('TRACK_ID')
                    t = spot.getFeature('FRAME')
                    time = int(t) * int(Time_interval)
                    writer2.writerow(
                        [str(id), str(t),
                         str(time), str(x),
                         str(y)])