Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix microservice paper bug #98

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions decimer_segmentation/complete_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ def get_mask_center(mask_array: np.array) -> Tuple[int, int]:
return None, None


def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, int]]:
def get_seeds(
image_array: np.array,
mask_array: np.array,
exclusion_mask: np.array,
) -> List[Tuple[int, int]]:
"""
This function takes an array that represents an image and a mask.
It returns a list of tuples with indices of seeds in the structure
Expand All @@ -295,6 +299,7 @@ def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, in
Args:
image_array (np.array): Image
mask_array (np.array): Mask
exclusion_mask (np.array): Exclusion mask

Returns:
List[Tuple[int, int]]: [(x,y), (x,y), ...]
Expand All @@ -312,32 +317,36 @@ def get_seeds(image_array: np.array, mask_array: np.array) -> List[Tuple[int, in
if not mask_array[y_center, x_center + n]:
up = False
if not image_array[y_center, x_center + n]:
seed_pixels.append((x_center + n, y_center))
up = False
if not exclusion_mask[y_center, x_center + n]:
seed_pixels.append((x_center + n, y_center))
up = False
# Check for seeds below center
if down:
if x_center - n >= 0:
if not mask_array[y_center, x_center - n]:
down = False
if not image_array[y_center, x_center - n]:
seed_pixels.append((x_center - n, y_center))
down = False
if not exclusion_mask[y_center, x_center - n]:
seed_pixels.append((x_center - n, y_center))
down = False
# Check for seeds left from center
if left:
if y_center + n < image_array.shape[0]:
if not mask_array[y_center + n, x_center]:
left = False
if not image_array[y_center + n, x_center]:
seed_pixels.append((x_center, y_center + n))
left = False
if not exclusion_mask[y_center + n, x_center]:
seed_pixels.append((x_center, y_center + n))
left = False
# Check for seeds right from center
if right:
if y_center - n >= 0:
if not mask_array[y_center - n, x_center]:
right = False
if not image_array[y_center - n, x_center]:
seed_pixels.append((x_center, y_center - n))
right = False
if not exclusion_mask[y_center - n, x_center]:
seed_pixels.append((x_center, y_center - n))
right = False
return seed_pixels


Expand Down Expand Up @@ -450,7 +459,9 @@ def expansion_coordination(
the mask expansion. It returns the expanded mask. The purpose of this function is
wrapping up the expansion procedure in a map function.
"""
seed_pixels = get_seeds(image_array, mask_array)
seed_pixels = get_seeds(image_array,
mask_array,
exclusion_mask)
if seed_pixels != []:
mask_array = expand_masks(image_array, seed_pixels, mask_array, exclusion_mask)
else:
Expand Down Expand Up @@ -498,7 +509,7 @@ def complete_structure_mask(

if mask_array.size != 0:
# Binarization of input image
binarized_image_array = binarize_image(image_array, threshold=0.85)
binarized_image_array = binarize_image(image_array, threshold=0.72)
# Apply dilation with a resolution-dependent kernel to the image
blur_factor = (
int(image_array.shape[1] / 185) if image_array.shape[1] / 185 >= 2 else 2
Expand Down
5 changes: 5 additions & 0 deletions decimer_segmentation/decimer_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def segment_chemical_structures(
if len(segments) > 0:
segments, bboxes = sort_segments_bboxes(segments, bboxes)

segments = [segment for segment in segments
if segment.shape[0] > 0
if segment.shape[1] > 0]

return segments


Expand Down Expand Up @@ -235,6 +239,7 @@ def get_expanded_masks(image: np.array) -> np.array:
image_array=image,
mask_array=masks,
max_depiction_size=size,
debug=False
)
return expanded_masks

Expand Down
Loading