Skip to content

Commit

Permalink
Allow blank images in training data set (#42)
Browse files Browse the repository at this point in the history
* Check length of points list before distance transform

* Add test case with no spots

* Add kwarg fill_value and pass in dtype

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>

---------

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
  • Loading branch information
elaubsch and rossbar committed Feb 4, 2023
1 parent c0fd598 commit a0a884d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions deepcell_spots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def subpixel_distance_transform(point_list, image_shape, dy=1, dx=1):
# index in point_list of point nearest to pixel
nearest_point = np.full(image_shape, np.nan)

# signed y distance to nearest point
delta_y = np.full(image_shape, fill_value=image_shape[1], dtype=np.float32)
# signed x distance to nearest point
delta_x = np.full(image_shape, fill_value=image_shape[0], dtype=np.float32)

if len(point_list) == 0:
return delta_y, delta_x, nearest_point

# dictionary to be filled s.t.: pixel_to_contained_point_ind[(i,j)] = k if point_list[k]
# is a point contained in pixel i,j of the image
pixel_to_contained_point_ind = {}
Expand All @@ -82,11 +90,6 @@ def subpixel_distance_transform(point_list, image_shape, dy=1, dx=1):
edt, inds = distance_transform_edt(
contains_point, return_indices=True, sampling=[dy, dx])

# signed y distance to nearest point
delta_y = np.full(image_shape, np.inf)
# signed x distance to nearest point
delta_x = np.full(image_shape, np.inf)

Ly, Lx = image_shape
for j in range(0, Lx):
for i in range(0, Ly):
Expand Down
14 changes: 14 additions & 0 deletions deepcell_spots/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def test_subpixel_distance_transform(self):
self.assertEqual(np.shape(delta_x), image_shape)
self.assertEqual(np.shape(nearest_point), image_shape)

# test image with no points
point_list = np.random.random((0, 2))
image_shape = (30, 30)
delta_y, delta_x, nearest_point = subpixel_distance_transform(
point_list, image_shape)

self.assertEqual(np.shape(delta_y), image_shape)
self.assertEqual(np.shape(delta_x), image_shape)
self.assertEqual(np.shape(nearest_point), image_shape)

self.assertAllEqual(delta_y, np.full(image_shape, image_shape[1]).astype(float))
self.assertAllEqual(delta_x, np.full(image_shape, image_shape[0]).astype(float))
self.assertAllEqual(nearest_point, np.full(image_shape, np.nan))

def test_generate_transformation_matrix(self):
transform_parameters = {
'theta': 0,
Expand Down

0 comments on commit a0a884d

Please sign in to comment.