From 86ebe30b7e164f62f45b96a02a120d844b350967 Mon Sep 17 00:00:00 2001 From: Ron Shnapp Date: Wed, 23 Oct 2024 09:20:17 +0300 Subject: [PATCH] workflow correction to BG image --- example/workflow.py | 12 +++++++++++- myptv/tracking_mod.py | 33 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 12 deletions(-) mode change 100644 => 100755 example/workflow.py diff --git a/example/workflow.py b/example/workflow.py old mode 100644 new mode 100755 index d5cf427..98dc255 --- a/example/workflow.py +++ b/example/workflow.py @@ -624,12 +624,22 @@ def calculate_BG_image(dirname, extension): # segmenting the image if there are more than 1 frames if N_img is None or N_img>1: + + if type(remove_BG)==str: + print('\n','using given background image') + BG = imread(remove_BG)*1.0 + elif remove_BG==True: + print('\n','calculating background image') + BG = calculate_BG_image(dirname, ext) + else: + BG=False + loopSegment = loop_segmentation(dirname, particle_size=p_size, extension=ext, image_start=image_start, N_img=N_img, - remove_ststic_BG=remove_BG, + remove_ststic_BG=BG, sigma=sigma, median=median, threshold=threshold, diff --git a/myptv/tracking_mod.py b/myptv/tracking_mod.py index 21799bb..dad9b99 100644 --- a/myptv/tracking_mod.py +++ b/myptv/tracking_mod.py @@ -983,6 +983,11 @@ def build_trajectories_from_frame(self, frame_num, backwards=False, If backwards=True then the tracking is backwards in time. ''' + + # ensure there are particles to track in this frame number + if frame_num not in list(self.particles.keys()): + return None + # a list to hold trajectories and trajectory particle identifiers trajs = [] @@ -990,9 +995,12 @@ def build_trajectories_from_frame(self, frame_num, backwards=False, NSRs = [] # 0) if above 20% of particles in the frame were used, clear them - uf = len(self.used_particles[frame_num])/len(self.particles[frame_num]) - if uf > 0.2: - self.clear_used_particles() + if frame_num in list(self.used_particles.keys()): + Nused = len(self.used_particles[frame_num]) + Nf = len(self.particles[frame_num]) + uf = Nused / Nf + if uf > 0.2: + self.clear_used_particles() # 1) building trajectories from particles in the given frame number if backwards==False: @@ -1380,14 +1388,17 @@ def smooth_trajectory(traj, Ns): # Tests: - -fname = '/home/ron/Desktop/Research/jetArrayTank/20240821/Rec2/particles' -max_dt = 3 -Ns = 11 -NSR_th = 0.25 -tmf = tracker_multiframe(fname, max_dt, Ns, d_max=0.5, dv_max=0.5, NSR_th=NSR_th) - -tmf.track_frames(f0=None, fe=None, frame_skips=5) +if __name__ == "__main__": + fname = '/home/ron/Desktop/Research/jetArrayTank/20241020_puffs/Rec18/particles' + max_dt = 3 + Ns = 11 + NSR_th = 0.25 + tmf = tracker_multiframe(fname, max_dt, Ns, d_max=0.5, dv_max=0.5, NSR_th=NSR_th) + + f0 = 134 + fe = None + frame_skips = 5 + tmf.track_frames(f0=f0, fe=fe, frame_skips=frame_skips)