Kohulan / DECIMER-Image-Segmentation

Chemical structure detection and segmentation tool for Journal articles.
https://decimer.ai
MIT License
81 stars 30 forks source link

Error with single page PDF at the get_mask_center function #63

Closed Iagea closed 1 year ago

Iagea commented 1 year ago

Hi,

the following error appears with the attached PDF document, do you know why?

Best, Isa.

Traceback (most recent call last): File "/Users/mag/UCMI/DECIMER-Image-Segmentation/segment_structures_in_document.py", line 45, in <module> main() File "/Users/mag/UCMI/DECIMER-Image-Segmentation/segment_structures_in_document.py", line 22, in main raw_segments = segment_chemical_structures_from_file(sys.argv[1]) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/decimer_segmentation.py", line 75, in segment_chemical_structures_from_file segments = segment_chemical_structures(images[0]) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/decimer_segmentation.py", line 100, in segment_chemical_structures masks = get_expanded_masks(image) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/decimer_segmentation.py", line 157, in get_expanded_masks expanded_masks = complete_structure_mask(image_array=image, mask_array=masks) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/complete_structure.py", line 451, in complete_structure_mask mask_array = np.stack(expanded_split_mask_arrays, -1) File "<__array_function__ internals>", line 180, in stack File "/Users/mag/opt/anaconda3/envs/DECIMER_IMGSEG/lib/python3.10/site-packages/numpy/core/shape_base.py", line 420, in stack arrays = [asanyarray(arr) for arr in arrays] File "/Users/mag/opt/anaconda3/envs/DECIMER_IMGSEG/lib/python3.10/site-packages/numpy/core/shape_base.py", line 420, in <listcomp> arrays = [asanyarray(arr) for arr in arrays] File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/complete_structure.py", line 399, in expansion_coordination seed_pixels = get_seeds(image_array, mask_array) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/complete_structure.py", line 297, in get_seeds x_center, y_center = get_mask_center(mask_array) File "/Users/mag/UCMI/DECIMER-Image-Segmentation/decimer_segmentation/complete_structure.py", line 280, in get_mask_center x_center = np.where(mask_array[y_center] == True)[0][0] IndexError: index 0 is out of bounds for axis 0 with size 0

105.pdf

Kohulan commented 1 year ago

This PDF also crashes decimer.ai

OBrink commented 1 year ago

Oh wow, sorry, I somehow forgot about this issue existing. I am on it now and will send a PR soon.

The problem seems to be that an empty mask is returned by the model and there are no seed pixels to be determined. This problem is not handled properly.

image

OBrink commented 1 year ago

PR #78 fixes this. Thank you @Iagea for reporting this problem, and sorry again for the late response!