U Ph, @sddlmZddlmZddlZddlZddlmZddl m Z e d\Z Z e d\Z Z dd d d d d Zdd ddddZGdddeZdS)) annotations)AnyN)ProbNMS)optional_importzskimage.measurez scipy.ndimagez np.ndarrayfloatr)mask thresholdreturncCs>d|d}tj|}||k}tj|}tj|dd}|S)z This method computes the segmentation mask according to the binary tumor mask. Args: mask: the binary mask array threshold: the threshold to fill holes ) connectivity)ndimage morphologydistance_transform_edtbinary_fill_holesmeasurelabel)rrnegdistancebinary filled_imageZmulti_instance_maskrO/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/apps/pathology/utils.pycompute_multi_instance_masks   rz list[int]) tumor_maskrr cs0t|}t|fddt|D}|S)aJ This method computes identifies Isolated Tumor Cells (ITC) and return their labels. Args: tumor_mask: the tumor mask. threshold: the threshold (at the mask level) to define an isolated tumor cell (ITC). A region with the longest diameter less than this threshold is considered as an ITC. cs"g|]}|jkr|dqS))major_axis_length).0i propertiesrrr 8sz0compute_isolated_tumor_cells..)npamaxr regionpropsrange)rr max_labelZitc_listrrrcompute_isolated_tumor_cells-s  r'c@s$eZdZdZd ddddddZd S) PathologyProbNMSzc This class extends monai.utils.ProbNMS and add the `resolution` option for Pathology. rznp.ndarray | torch.Tensorintz list[list]) probs_mapresolution_levelr c Cshtd|}t||}g}|D]D}|d}t|dd}|d|t} ||gt| q|S)z probs_map: the input probabilities map, it must have shape (H[, W, ...]). resolution_level: the level at which the probabilities map is made. r rrNg?) powr__call__r"asarrayastyper)appendlist) selfr*r+ resolutionZ org_outputsoutputsZ org_outputprobcoordZ coord_wsirrrr-Cs  zPathologyProbNMS.__call__N)r)__name__ __module__ __qualname____doc__r-rrrrr(=sr() __future__rtypingrnumpyr"torchmonai.transforms.post.arrayr monai.utilsrr_r rr'r(rrrr s