o  i @sddlmZddlmZddlZddlZddlmZddl m Z e d\Z Z e d\Z Z dddZdddZGdddeZdS)) annotations)AnyN)ProbNMS)optional_importzskimage.measurez scipy.ndimagemask np.ndarray thresholdfloatreturnrcCs:d|d}t|}||k}t|}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)ndimagedistance_transform_edtbinary_fill_holesmeasurelabel)rrnegdistancebinaryZ filled_imageZmulti_instance_maskr\/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/apps/pathology/utils.pycompute_multi_instance_masks  r tumor_mask list[int]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))Zmajor_axis_length).0i propertiesrrr 8s"z0compute_isolated_tumor_cells..)npamaxr regionpropsrange)rr max_labelZitc_listrrrcompute_isolated_tumor_cells-s r&c@seZdZdZd d d d Zd S)PathologyProbNMSzc This class extends monai.utils.ProbNMS and add the `resolution` option for Pathology. r probs_mapnp.ndarray | torch.Tensorresolution_levelintr list[list]c Cshtd|}t||}g}|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)r(r)r*r+r r,)__name__ __module__ __qualname____doc__r.rrrrr'=sr')rrrr r r)rrrr r r) __future__rtypingrnumpyr!torchmonai.transforms.post.arrayr monai.utilsrr_rrr&r'rrrrs