Skip to content

Commit

Permalink
added tqdm to segmentation and using pre calculated BG image
Browse files Browse the repository at this point in the history
  • Loading branch information
ronshnapp committed Sep 7, 2024
1 parent 9576dd2 commit c9067b6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
12 changes: 10 additions & 2 deletions example/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,11 @@ def calculate_BG_image(dirname, extension):
msg = 'Image %s not found in the directory.'%in_
raise ValueError(msg)

if remove_BG==True:
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=None
Expand Down Expand Up @@ -774,7 +778,11 @@ def calculate_BG_image(dirname, extension):
msg = 'Image %s not found in the directory.'%in_
raise ValueError(msg)

if remove_BG==True:
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=None
Expand Down
3 changes: 2 additions & 1 deletion myptv/extendedZolof/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def calibrate(self):
XColumns = []
for Xi in self.X_list:
Xcol_i = self.cam.get_XCol(Xi)
for i in range(-7,0): Xcol_i[i] = 0
# (Here, -7 is for quadratic, and -13 is linear)
for i in range(-7,0): Xcol_i[i] = 0
XColumns.append(Xcol_i)

res = lstsq(XColumns, self.x_list, rcond=None)
Expand Down
36 changes: 27 additions & 9 deletions myptv/segmentation_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from scipy.ndimage.measurements import label, find_objects
from scipy.spatial import KDTree

import tqdm



class particle_segmentation(object):
Expand Down Expand Up @@ -439,7 +441,8 @@ def __init__(self, dir_name, extension='.tif',
images, defined as the median value of each pixel,
and then background_subtraction is done by taking
the difference from the median. If this is False,
then this operation is skipped.
then this operation is skipped. If this is a numpy
array, than it is used as the BG image.
The rest are parameters for the segmentation class.
'''
Expand All @@ -456,7 +459,21 @@ def __init__(self, dir_name, extension='.tif',
self.mass_limits = (min_mass, max_mass)
self.loc_filter = local_filter
self.method = method
self.BG_remove = remove_ststic_BG

# optionally using pre-calculated BG image:
if type(remove_ststic_BG) == bool:
self.BG_remove = remove_ststic_BG

else:
from numpy import ndarray
if type(remove_ststic_BG) == ndarray:
self.BG = remove_ststic_BG
self.BG_remove = False







def get_file_names(self):
Expand Down Expand Up @@ -517,18 +534,19 @@ def segment_folder_images(self):
else:
N = self.N_img

if self.BG_remove==True:
self.calculate_BG()
else:
self.BG = None
if type(self.BG_remove)==bool:
if self.BG_remove==True:
self.calculate_BG()
else:
self.BG = None

i0 = (self.image_start is not None) * self.image_start

blob_list = []
print('Starting loop segmentation.\n')
for i in range(N):
print('', end='\r')
print(' frame: %d'%(i+i0), end='\r')
for i in tqdm.tqdm(range(N)):
#print('', end='\r')
#print(' frame: %d'%(i+i0), end='\r')
im = imread(os.path.join(self.dir_name, self.image_files[i]))
ps = particle_segmentation(im,
sigma=self.sigma,
Expand Down

0 comments on commit c9067b6

Please sign in to comment.