Beispiel #1
0
 def Track(self, Folder):
     db_name = self.name_from_path(Folder)
     db_path = os.path.sep.join(Folder.split(os.path.sep)[:-1] + [""])
     if not os.path.exists(db_path + db_name + ".cdb"):
         self.CreateDB(Folder, self.MatchedFiles[Folder])
     db = DataFileExtended(db_path + db_name + ".cdb")
     print([i.sort_index for i in db.getImageIterator()])
     TCell_Analysis.Track(db, progress_bar=self.Bar3)
Beispiel #2
0
def AnalyzeDB(db_str):
    db = DataFileExtended(db_str)
    time_step = 110
    v_fac = 0.645 / (time_step / 60.)
    perc = 30
    step = 20
    type = 'PT_Track_Marker'
    Frame_list = []
    for f in db.getImageIterator():
        Frame_list.append(f.sort_index)
    Frames = np.max(Frame_list)

    timer()
    Tracks = TCell_Analysis.load_tracks(db_str, type)
    timer("Loading Tracks")

    Z_posis = TCell_Analysis.getZpos(Tracks, v_fac)
    timer("Fetching Z")

    Z_posis = np.asarray(Z_posis)
    tracks_to_delete = TCell_Analysis.get_Tracks_to_delete(Z_posis, perc)
    timer("Getting Tracks to delete")

    ###
    list2 = TCell_Analysis.create_list2(db)  # Create List for true dist
    timer("Creating List2")

    drift, drift_list, missing_frame = TCell_Analysis.Drift(
        Frames, list2, 5)  # Create List with offsets
    timer("Getting Drift")

    list2 = TCell_Analysis.list2_with_drift(
        db, drift, tracks_to_delete,
        del_track=True)  # Create list for true dist with drift_cor
    timer("List2 with drift")

    list = TCell_Analysis.create_list(
        Frames, db, drift=drift, Drift=True,
        Missing=missing_frame)  # Create List for analysis
    timer("Create List")
    ### For Deleting Tracks above and below
    list_copy = list[:]
    for l, m in enumerate(list):
        keys = m.keys()
        for k, j in enumerate(keys):
            if j in tracks_to_delete:
                del list_copy[l][j]
    timer("Stuff")

    ###
    print("bla")
    directions, velocities, dirt, alternative_vel, vel_mean, dir_mean, alt_vel_mean = TCell_Analysis.measure(
        step, time_step, list, Frames)  # Calculate directions and velocities
    timer("Measure")

    motile_percentage, mean_v, mean_dire, number, len_count, mo_p_al, me_v_al, me_d_al = TCell_Analysis.values(
        directions,
        velocities,
        db,
        dirt,
        alternative_vel,
        tracks_to_delete,
        del_Tracks=True)
    timer("Values")
    motile_per_true_dist, real_dirt = TCell_Analysis.motiletruedist(list2)
    timer("Motile True Dist")

    if not os.path.exists(db_str[:-4] + "_analyzed.txt"):
        with open(db_str[:-4] + "_analyzed.txt", "w") as f:
            f.write(
                'Day       \t\t\tData                              \t\t\tMotile % true dist\t\t\tMotile in %\t\t\tMean velocity\t\t\tMean Directionality\t\t\tMean vel dt1\t\t\t#Tracks\t\t\t#Evaluated Tracks\t\t\t#Dirt\n'
            )

    Day = getDateFromPath(db_str).strftime("%Y-%M-%d")
    if db_str.count('TCell') or db_str.count('T-Cell'):
        TCell_Analysis.Colorplot(
            directions,
            velocities,
            db_str,
            path=os.path.sep.join(db_str.split(os.path.sep)[:-1]),
            Save=True)  # Save the velocity vs directionality picture
        with open(db_str[:-4] + "_analyzed.txt", "ab") as f:
            f.write(
                '%s\t\t\t%34s\t\t\t%18f\t\t\t%11f\t\t\t%13f\t\t\t%19f\t\t\t%12f\t\t\t%7d\t\t\t%17d\t\t\t%5d\n'
                % (Day, db_str, motile_per_true_dist, motile_percentage,
                   mean_v, mean_dire, me_v_al, number, len_count, real_dirt))
    elif db_str.count('NKCell'):
        TCell_Analysis.Colorplot(directions,
                                 velocities,
                                 db_str,
                                 path=os.path.sep.join(
                                     db_str.split(os.path.sep)[:-1]),
                                 Save=True)
        with open(db_str[:-4] + "_analyzed.txt", 'ab') as f:
            f.write(
                '%s\t\t\t%34s\t\t\t%18f\t\t\t%11f\t\t\t%13f\t\t\t%19f\t\t\t%12f\t\t\t%7d\t\t\t%17d\t\t\t%5d\n'
                % (Day, db_str, motile_per_true_dist, motile_percentage,
                   mean_v, mean_dire, me_v_al, number, len_count, real_dirt))
    db.db.close()

    timer("Write")
Beispiel #3
0
import scipy.stats as ss

# Load Database
# file_path = "/home/birdflight/Desktop/PT_Test.cdb"
file_path = "/mnt/mmap/Starter_Full.cdb"
# file_path = "/mnt/mmap/PT_Test3.cdb"
# file_path = "/mnt/mmap/PT_Test4.cdb"

global db
db = DataFileExtended(file_path,"w")

db_start = DataFileExtended("/home/birdflight/Desktop/Starter.cdb")
# images = db_start.getImageIterator(start_frame=2490-30, end_frame=2600)
# images = db_start.getImageIterator(start_frame=1936-210, end_frame=2600)
images = db_start.getImageIterator(start_frame=700)
# images = db_start.getImageIterator(start_frame=1936-20-90, end_frame=2600)
# images = db_start.getImageIterator(start_frame=1500, end_frame=2600)

# images = db_start.getImageIterator()
def getImage():
    im = images.next()
    fname = im.filename
    from datetime import datetime
    d = datetime.strptime(fname[0:15], '%Y%m%d-%H%M%S')
    time_unix = np.uint32(time.mktime(d.timetuple()))
    time_ms = np.uint32(fname[16:17])*100
    meta = {'time': time_unix,
            'time_ms': time_ms,
            'file_name': fname,
            'path': im.path.path}
file_path = "/home/user/Desktop/PT_Test_full_n3_r7_A20.cdb"
c = 20
# file_path = "/mnt/mmap/PT_Test3.cdb"
# file_path = "/mnt/mmap/PT_Test4.cdb"

global db
db = DataFileExtended(file_path, "w")

db_start = DataFileExtended(input_file)
# images = db_start.getImageIterator(start_frame=2490-30, end_frame=2600)
# images = db_start.getImageIterator(start_frame=1936-210, end_frame=2600)
# images = db_start.getImageIterator(end_frame=52)
# images = db_start.getImageIterator(start_frame=1936-20-90, end_frame=2600)
# images = db_start.getImageIterator(start_frame=1500, end_frame=2600)

images = db_start.getImageIterator()


def getImage():
    try:
        im = images.next()
    except StopIteration:
        print("Done! First!")
        return None, None
    # im.data = rgb2gray(im.data)
    fname = im.filename
    from datetime import datetime
    # d = datetime.strptime(fname[0:15], '%Y%m%d-%H%M%S')
    d = im.timestamp
    time_unix = np.uint32(time.mktime(d.timetuple()))
    time_ms = 0  #np.uint32(fname[16:17])*100
State_Dist = ss.multivariate_normal(
    cov=Q)  # Initialize Distributions for Filter
Meas_Dist = ss.multivariate_normal(
    cov=R)  # Initialize Distributions for Filter

MultiKal = HungarianTracker(
    KalmanFilter,
    model,
    np.diag(Q),
    np.diag(R),
    meas_dist=Meas_Dist,
    state_dist=State_Dist,
    measured_variables=["PositionX", "VelocityX", "PositionY", "VelocityY"])
MultiKal.LogProbabilityThreshold = log_prob_threshold

images = db.getImageIterator(start_frame=220)
# images = db.getImageIterator(start_frame=0, end_frame=220)
image = next(images)
# image_data = image.data#[200:400, 0:200]
# image_int = rgb2gray(image_data)
# FD.update(np.ones_like(image_int, dtype=bool), image_int)
i = 0
db_model, db_tracker = db.init_tracker(model, MultiKal)
ED = EmperorDetector(image.data, luminance_threshold=1.8)
for image in images:
    MultiKal.predict(i=i)
    # image_data = image.data#[200:400,0:200]
    # image_int = rgb2gray(image_data)
    # flow = FD.segmentate(image_int)
    # FD.update(np.ones_like(image_int, dtype=bool), image_int)
    measurements = ED.detect(image.data)  #[200:300, 750:1000])
Beispiel #6
0
    marker_type4 = db.setMarkerType(name="PT_Stitch_Marker", color="#FF8800", mode=db.TYPE_Track)

# Delete Old Tracks
db.deleteMarkers(type=marker_type)
db.deleteMarkers(type=marker_type2)
db.deleteMarkers(type=marker_type3)
db.deleteMarkers(type=marker_type4)

db.deleteTracks(type=marker_type2)
db.deleteTracks(type=marker_type4)



# Start Iteration over Images
print('Starting Iteration')
images = db.getImageIterator(start_frame=20)#start_frame=start_frame, end_frame=3)
# images = db.getImageIterator(start_frame=10272, end_frame=10311)#start_frame=start_frame, end_frame=3)

start = time()
for image in images:
    print(time()-start)
    start = time()
    i = image.get_id()

    # Prediction step
    MultiKal.predict(u=np.zeros((model.Control_dim,)).T, i=i)

    # Segmentation step
    SegMap = VB.detect(image.data, do_neighbours=False)

    print(time()-start)
Beispiel #7
0
                                             color="#FF0000",
                                             style='{"scale":1.2}')
    db.deleteMarkers(type=detection_marker_type)
    track_marker_type = db.setMarkerType(name="Track_Marker",
                                         color="#00FF00",
                                         mode=db.TYPE_Track)
    db.deleteMarkers(type=track_marker_type)
    prediction_marker_type = db.setMarkerType(name="Prediction_Marker",
                                              color="#0000FF")
    db.deleteMarkers(type=prediction_marker_type)
    # Delete Old Tracks
    db.deleteTracks(type=track_marker_type)

    # Start Iteration over Images
    print('Starting Iteration')
    images = db.getImageIterator()
    for image in images:

        i = image.sort_index
        # Prediction step, without applied control(vector of zeros)
        MultiKal.predict(i=i)

        # Detection step
        SegMap = TS.detect(image.data)
        Positions, Mask = AD.detect(image.data, SegMap)
        print("Found %s Objects!" % len(Positions))

        # Write Segmentation Mask to Database
        db.setMask(image=image, data=(~SegMap).astype(np.uint8))
        print("Mask save")