CellProfiling / HPA-Cell-Segmentation

Apache License 2.0
95 stars 26 forks source link

label_cell2 utility function throws NameError #21

Closed milotoor closed 1 year ago

milotoor commented 3 years ago

Hi there! I recently noticed that the label_cell2 function throws a NameError with any input. While working on the current Kaggle competition, I was interested in speeding up my code by only working with cell masks (and omitting the nuclei masks). This seemed like the proper function to use for that, but unfortunately it raises:

/opt/conda/lib/python3.7/site-packages/hpacellseg/utils.py in label_cell2(cell_pred)
    202         np.invert(np.asarray(cell_pred[..., 1] > 0.01)),
    203     )
--> 204     cell_region_eroded = morphology.erosion(
    205         cell_region1, morphology.square(25))
    206     cell_region_eroded = np.asarray(cell_region_eroded, dtype=np.uint8)

NameError: name 'morphology' is not defined

Looking at the relevant lines of code, it becomes clear that the problem is simply that the morphology module simply isn't imported! Or... at least it isn't imported in the manner the code expects. I suspect that extending the current import would suffice:

from skimage.morphology import (binary_erosion, closing, disk, erosion
                                remove_small_holes, remove_small_objects, square)

Of course the calling code would need to be updated as well to reference these imported functions directly:

cell_region_eroded = erosion(cell_region1, square(25))

I'm happy to put together a pull request for this, just let me know if you'd like that.

cwinsnes commented 3 years ago

A pull request for this would be great if you want to do that!

We haven't used the code in label_cell2 for a while. I don't remember the exact reasoning why this is, but I'd recommend proceeding with some care and double check that the code does what you expect it to.