Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from ij import IJ, Prefs
from ij.gui import Roi
from pta import PTA
from pta.gui import ShowPdata
from pta.track import DetectParticle
from pta.data import PtaParam
from java.util import ArrayList
from ij.plugin.frame import ThresholdAdjuster
from ij.process import ImageProcessor
# set data path
#datafilepath = "/Users/miura/Dropbox/20130805_Osaka/data/transferrin-movement/tconc1_3.tif"
datafilepath = "/Users/miura/Dropbox/20130805_Osaka/data/transferrin-movement/tconc10_16.tif"
# load data as an ImagePlus object
imp = IJ.openImage(datafilepath)
# default ROI = full frame
scanAreaRoi = Roi(0,0,imp.getWidth(),imp.getHeight())
# set intensity threshold to the iamge
ip = imp.getProcessor()
Prefs.blackBackground = True
ht = ip.getAutoThreshold()
ip.setThreshold(ht, ip.getMax(), ImageProcessor.RED_LUT)
# **** Set PTA parameters ****
PTA.setDetectionState(True)
#PTA.setDebugMode()
# set no GUI mode
PTA.setNoGUI(True)
# set Detection Parameters.
# PtaParam.Builder(int roiSizex,int roiSizey,boolean do2dGaussfit)
ptap = PtaParam.Builder(12,12, False).build()
### more ways to customize paramters
#ptap.setDo2dGaussfit(False)
#ptap.setDo2dGaussfit(True)
#ptap.setMinIntensity(100.0)
#ptap.setSearchPointIncrement(1)
# **** Tracking ****
# instantiate a DetectParticle object
# DetectParticle(PtaParam ptap, ij.ImagePlus imp, ij.gui.Roi scanRoi, boolean nogui)
dp = DetectParticle(ptap,imp,scanAreaRoi, True)
# set range of frames to analyze
dp.setStackRange(1, imp.getStackSize())
# start threads.
dp.start()
# wait till the processing finishes
dp.join()
# stop the thread.
dp.interrupt()
PTA.setDetectionState(False)
# **** output results ****
# show detection results
imp.show()
# Particle lists
#ll = dp.getalldplist()
#print ll
# track lists
tracks = dp.getLinkedPointList()
print "=== tracks ==="
for t in tracks:
if len(t) > 2:
print t
# MSD analysis
# if "Linear", then y = a + bx
msds = dp.getMSDres(5.0, True)
print "msd data size", msds.size()
for msd in msds:
print "ID", msd.getID(), "A", msd.getA(), \
"B", msd.getB(), "Res", msd.getR()
# TODO: write MSD values in a csv file.
# http://cmci.embl.de/documents/120206pyip_cooking/python_imagej_cookbook#saving_csv_file_data_table
# discard the DetextParticle Object
dp = None
##Back to the GUI mode: without this line, PTA GUI will not showup from next time.
PTA.setNoGUI(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.