cleanup: now the debug images are only outputted in debug mode

also removed debugging traces
This commit is contained in:
Guillaume Raffy 2022-11-30 18:44:46 +01:00
parent 0d41944c2a
commit efade89a57
1 changed files with 14 additions and 14 deletions

View File

@ -71,7 +71,7 @@ def hdf5_to_trac_data(hdf5_file_path: Path):
date = f.attrs['date'] # noqa date = f.attrs['date'] # noqa
trac_data.num_frames = f.attrs['nFrames'] trac_data.num_frames = f.attrs['nFrames']
trac_data.image_size = f.attrs['size'] trac_data.image_size = f.attrs['size']
print(type(trac_data.image_size)) # print(type(trac_data.image_size))
# f.attrs['size'] = I0f.shape # f.attrs['size'] = I0f.shape
# for items in th[0].keys(): # for items in th[0].keys():
# f.attrs['th:' + items] = th[0][items] # f.attrs['th:' + items] = th[0][items]
@ -97,11 +97,10 @@ class SlopeFinder():
isbead_image = SlopeFinder.create_isbead_image(trac_data, frame_index, self.beads_radius) isbead_image = SlopeFinder.create_isbead_image(trac_data, frame_index, self.beads_radius)
mo_pro_listener.onImage(isbead_image, 'isbead') mo_pro_listener.onImage(isbead_image, 'isbead')
mo_pro_listener.onBaseImage(isbead_image, 'isbead') mo_pro_listener.onBaseImage(isbead_image, 'isbead')
cv2.imwrite('isbead_%04d.tif' % frame_index, isbead_image)
if False: if False:
kernel = np.ones((15, 15), np.uint8) kernel = np.ones((15, 15), np.uint8)
closing = cv2.morphologyEx(isbead_image, cv2.MORPH_CLOSE, kernel) closing = cv2.morphologyEx(isbead_image, cv2.MORPH_CLOSE, kernel)
cv2.imwrite('closing_%04d.tif' % frame_index, closing) mo_pro_listener.onImage(closing, 'closing')
# remove the jumping beads # remove the jumping beads
# apply connected component analysis to the thresholded image # apply connected component analysis to the thresholded image
# thresh = cv2.threshold(isbead_image, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] # thresh = cv2.threshold(isbead_image, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
@ -109,35 +108,36 @@ class SlopeFinder():
connectivity = 4 connectivity = 4
output = cv2.connectedComponentsWithStats(thresh, connectivity, cv2.CV_32S) output = cv2.connectedComponentsWithStats(thresh, connectivity, cv2.CV_32S)
(num_labels, labels_image, stats, centroids) = output (num_labels, labels_image, stats, centroids) = output
print('num_labels: ', num_labels) # print('num_labels: ', num_labels)
print('labels_image: ', labels_image) # print('labels_image: ', labels_image)
print('stats: ', stats) # print('stats: ', stats)
print('centroids: ', centroids) # print('centroids: ', centroids)
cv2.imwrite('labels_%04d.tif' % frame_index, labels_image) mo_pro_listener.onImage(labels_image, 'labels')
is_non_jumping_bead_image = np.zeros(shape=labels_image.shape, dtype=np.uint8) is_non_jumping_bead_image = np.zeros(shape=labels_image.shape, dtype=np.uint8)
bead_area = math.pi * self.beads_radius * self.beads_radius bead_area = math.pi * self.beads_radius * self.beads_radius
for label in range(1, num_labels): # ignore the first label, as it's the background for label in range(1, num_labels): # ignore the first label, as it's the background
area = stats[label][4] area = stats[label][4]
if area > bead_area * 1.1: if area > bead_area * 1.1:
is_non_jumping_bead_image[labels_image == label] = 255 is_non_jumping_bead_image[labels_image == label] = 255
cv2.imwrite('non_jumping_beads_%04d.tif' % frame_index, is_non_jumping_bead_image) mo_pro_listener.onImage(is_non_jumping_bead_image, 'non_jumping_beads')
# extract the surface points # extract the surface points
surface_y = np.ndarray(shape=(is_non_jumping_bead_image.shape[1],), dtype=int) surface_y = np.ndarray(shape=(is_non_jumping_bead_image.shape[1],), dtype=int)
surface_y.fill(is_non_jumping_bead_image.shape[0]) surface_y.fill(is_non_jumping_bead_image.shape[0])
contours, hierarchy = cv2.findContours(is_non_jumping_bead_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours, hierarchy = cv2.findContours(is_non_jumping_bead_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
print('num contours: ', len(contours)) # print('num contours: ', len(contours))
assert(len(contours) == 1) assert(len(contours) == 1)
contour = contours[0] contour = contours[0]
for point in contour: for point in contour:
x, y = point[0] x, y = point[0]
surface_y[x] = min(surface_y[x], y) surface_y[x] = min(surface_y[x], y)
print(surface_y) # print(surface_y)
surface_pts = [] surface_pts = []
for x in range(len(surface_y)): for x in range(len(surface_y)):
y = surface_y[x] y = surface_y[x]
if y != is_non_jumping_bead_image.shape[0]: if y != is_non_jumping_bead_image.shape[0]:
surface_pts.append((x, y)) surface_pts.append((x, y))
print(surface_pts) # print(surface_pts)
x = [pt[0] for pt in surface_pts] x = [pt[0] for pt in surface_pts]
y = [pt[1] for pt in surface_pts] y = [pt[1] for pt in surface_pts]
lin_regress_result = scipy.stats.linregress(x, y) lin_regress_result = scipy.stats.linregress(x, y)
@ -151,12 +151,12 @@ class SlopeFinder():
@staticmethod @staticmethod
def create_isbead_image(trac_data: TracData, frame_index: int, particle_radius: float): def create_isbead_image(trac_data: TracData, frame_index: int, particle_radius: float):
image = np.zeros(shape=trac_data.image_size, dtype=float) image = np.zeros(shape=trac_data.image_size, dtype=float)
print(trac_data.pts) # print(trac_data.pts)
frame_pts = trac_data.pts[trac_data.pts[:, 0] == frame_index] frame_pts = trac_data.pts[trac_data.pts[:, 0] == frame_index]
for x in frame_pts[:, 2:4]: for x in frame_pts[:, 2:4]:
center_coordinates = (int(x[0]), int(x[1])) center_coordinates = (int(x[0]), int(x[1]))
# center_coordinates = (10,10) # center_coordinates = (10,10)
print(center_coordinates) # print(center_coordinates)
cv2.circle(image, center_coordinates, int(particle_radius), color=1.0, thickness=-1) cv2.circle(image, center_coordinates, int(particle_radius), color=1.0, thickness=-1)
return image return image