algorithms/asa.py
def _separate_masks(mask, threshold=0.025):
    """
    Returns a list of segmentation masks each of the same dimension as the input one,
    but where they each have exactly one segment in them and all other samples in them
    are zeroed.

    Only bothers to return segments that are larger in total area than `threshold * mask.size`.
    """
    try:
        ncpus = multiprocessing.cpu_count()
    except NotImplementedError:
        ncpus = 2

    with multiprocessing.Pool(processes=ncpus) as pool:
        mask_ids = [id for id in np.unique(mask) if id != 0]
        thresholds = [threshold * mask.size for _ in range(len(mask_ids))]
        masks = [mask for _ in range(len(mask_ids))]
        ms = pool.starmap(_separate_masks_task, zip(mask_ids, thresholds, masks))
    return [m for m in ms if m is not None]
def _separate_masks(mask, threshold=0.025):
    try:
        ncpus = multiprocessing.cpu_count()
    except NotImplementedError:
        ncpus = 2

    with multiprocessing.Pool(processes=ncpus) as pool:
        mask_ids = [id for id in np.unique(mask) if id != 0]
        thresholds = [threshold * mask.size for _ in range(len(mask_ids))]
        masks = [mask for _ in range(len(mask_ids))]
        ms = pool.starmap(_separate_masks_task, zip(mask_ids, thresholds, masks))
    return [m for m in ms if m is not None]
def _separate_masks ( mask , threshold = 0.025 ) : try : ncpus = multiprocessing . cpu_count ( ) except NotImplementedError : ncpus = 2 with multiprocessing . Pool ( processes = ncpus ) as pool : mask_ids = [ id for id in np . unique ( mask ) if id != 0 ] thresholds = [ threshold * mask . size for _ in range ( len ( mask_ids ) ) ] masks = [ mask for _ in range ( len ( mask_ids ) ) ] ms = pool . starmap ( _separate_masks_task , zip ( mask_ids , thresholds , masks ) ) return [ m for m in ms if m is not None ]
Returns a list of segmentation masks each of the same dimension as the input one,
    but where they each have exactly one segment in them and all other samples in them
    are zeroed.

    Only bothers to return segments that are larger in total area than `threshold * mask.size`.
Returns a list of segmentation masks each of the same dimension as the input one but where they each have exactly one segment in them and all other samples in them are zeroed .