-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update requirements, stop installing dependencies twice and add…
…ed decimer segmentation
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import cv2 | ||
from decimer_segmentation import segment_chemical_structures_from_file | ||
from DECIMER import predict_SMILES | ||
|
||
def getPredictedSegments(path:str): | ||
"""Takes an image filepath and returns a set of paths of segmented images | ||
Args: | ||
input_path (str): path of an image | ||
Returns: | ||
segment_paths (list): a list of paths of segmented images. | ||
""" | ||
smiles_predicted = [] | ||
image_name = os.path.split(path)[1] | ||
segments = segment_chemical_structures_from_file(path) | ||
if len(segments) == 0: | ||
smiles = predict_SMILES(path) | ||
return smiles | ||
else: | ||
for segment_index in range(len(segments)): | ||
segmentname = f"{image_name[:-5]}_{segment_index}.png" | ||
segment_path = os.path.join(segmentname) | ||
cv2.imwrite(segment_path, segments[segment_index]) | ||
smiles = predict_SMILES(segment_path) | ||
smiles_predicted.append(smiles) | ||
os.remove(segment_path) | ||
return '.'.join(smiles_predicted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters