Skip to content

Commit fe96aa9

Browse files
committed
fix: don't use pixels from exclusion mask as seed pixels
1 parent 1242a67 commit fe96aa9

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

decimer_segmentation/complete_structure.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ def get_mask_center(mask_array: np.array) -> Tuple[int, int]:
286286
return None, None
287287

288288

289-
def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, int]]:
289+
def get_seeds(
290+
image_array: np.array,
291+
mask_array: np.array,
292+
exclusion_mask: np.array,
293+
) -> List[Tuple[int, int]]:
290294
"""
291295
This function takes an array that represents an image and a mask.
292296
It returns a list of tuples with indices of seeds in the structure
@@ -295,6 +299,7 @@ def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, in
295299
Args:
296300
image_array (np.array): Image
297301
mask_array (np.array): Mask
302+
exclusion_mask (np.array): Exclusion mask
298303
299304
Returns:
300305
List[Tuple[int, int]]: [(x,y), (x,y), ...]
@@ -312,32 +317,36 @@ def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, in
312317
if not mask_array[y_center, x_center + n]:
313318
up = False
314319
if not image_array[y_center, x_center + n]:
315-
seed_pixels.append((x_center + n, y_center))
316-
up = False
320+
if not exclusion_mask[y_center, x_center + n]:
321+
seed_pixels.append((x_center + n, y_center))
322+
up = False
317323
# Check for seeds below center
318324
if down:
319325
if x_center - n >= 0:
320326
if not mask_array[y_center, x_center - n]:
321327
down = False
322328
if not image_array[y_center, x_center - n]:
323-
seed_pixels.append((x_center - n, y_center))
324-
down = False
329+
if not exclusion_mask[y_center, x_center - n]:
330+
seed_pixels.append((x_center - n, y_center))
331+
down = False
325332
# Check for seeds left from center
326333
if left:
327334
if y_center + n < image_array.shape[0]:
328335
if not mask_array[y_center + n, x_center]:
329336
left = False
330337
if not image_array[y_center + n, x_center]:
331-
seed_pixels.append((x_center, y_center + n))
332-
left = False
338+
if not exclusion_mask[y_center + n, x_center]:
339+
seed_pixels.append((x_center, y_center + n))
340+
left = False
333341
# Check for seeds right from center
334342
if right:
335343
if y_center - n >= 0:
336344
if not mask_array[y_center - n, x_center]:
337345
right = False
338346
if not image_array[y_center - n, x_center]:
339-
seed_pixels.append((x_center, y_center - n))
340-
right = False
347+
if not exclusion_mask[y_center - n, x_center]:
348+
seed_pixels.append((x_center, y_center - n))
349+
right = False
341350
return seed_pixels
342351

343352

@@ -450,7 +459,9 @@ def expansion_coordination(
450459
the mask expansion. It returns the expanded mask. The purpose of this function is
451460
wrapping up the expansion procedure in a map function.
452461
"""
453-
seed_pixels = get_seeds(image_array, mask_array)
462+
seed_pixels = get_seeds(image_array,
463+
mask_array,
464+
exclusion_mask)
454465
if seed_pixels != []:
455466
mask_array = expand_masks(image_array, seed_pixels, mask_array, exclusion_mask)
456467
else:
@@ -498,7 +509,7 @@ def complete_structure_mask(
498509

499510
if mask_array.size != 0:
500511
# Binarization of input image
501-
binarized_image_array = binarize_image(image_array, threshold=0.85)
512+
binarized_image_array = binarize_image(image_array, threshold=0.72)
502513
# Apply dilation with a resolution-dependent kernel to the image
503514
blur_factor = (
504515
int(image_array.shape[1] / 185) if image_array.shape[1] / 185 >= 2 else 2

0 commit comments

Comments
 (0)