Пример #1
0
def segment_bacteria_return_cyto_no_bac(nuc,
                                        img,
                                        slen=3,
                                        SIGMA=0.5,
                                        THRES=20,
                                        CLOSE=20,
                                        THRESCHANGE=1000,
                                        MINAREA=5,
                                        dist=25):
    """ Segment bacteria and assign to closest nucleus and return the mask back without regions containing bacteria

    Args:
        nuc (numpy.ndarray): nuclear mask labels
        img (numpy.ndarray): image in bacterial channel
        slen (int): Size of Gaussian kernel
        SIGMA (float): Standard deviation for Gaussian kernel
        THRES (int): Threshold pixel intensity fo real signal 
        CLOSE (int): Radius for disk used to return morphological closing of the image (dilation followed by erosion to remove dark spots and connect bright cracks)
        THRESCHANGE (int): argument unnecessary? 
        MINAREA (int): minimum area in pixels for a bacterium 

    Returns:
        labels (numpy.ndarray[np.uint16]): bacterial mask labels  

    """
    labels = label_high_pass(img, slen=slen, SIGMA=SIGMA, THRES=THRES, CLOSE=3)
    if labels.any():
        labels, comb, nuc_prop, nuc_loc = label_nearest(img, labels, nuc, dist)
    from skimage.morphology import remove_small_objects
    labels = remove_small_objects(labels, MINAREA)
    labels = comb - labels
    return labels.astype(np.uint16)
Пример #2
0
def segment_bacteria(nuc,
                     img,
                     slen=3,
                     SIGMA=0.5,
                     THRES=20,
                     CLOSE=20,
                     MINAREA=5,
                     dist=25,
                     SEGMENT='highpass',
                     ASSIGN=True):
    """ Segment bacteria using high pass filter or constant thresholding and assign to closest nucleus

    Args:
        nuc (numpy.ndarray): nuclear mask labels
        img (numpy.ndarray): image in bacterial channel
        slen (int): Size of Gaussian kernel
        SIGMA (float): Standard deviation for Gaussian kernel
        THRES (int): Threshold pixel intensity fo real signal 
        CLOSE (int): Radius for disk used to return morphological closing of the image
                     (dilation followed by erosion to remove dark spots and connect bright cracks)
        THRESCHANGE (int): argument unnecessary? 
        MINAREA (int): minimum area in pixels for a bacterium 
        dist (int): acceptable distance bac can be from mask 
        SEGMENT: choose one of 'highpass' or 'constant'.
        ASSIGN: If False, it does not assign to closest nucleus. 
    Returns:
        labels (numpy.ndarray[np.uint16]): bacterial mask labels  

    """
    if SEGMENT == 'highpass':
        labels = label_high_pass(img,
                                 slen=slen,
                                 SIGMA=SIGMA,
                                 THRES=THRES,
                                 CLOSE=3)
    elif SEGMENT == 'constant':
        labels = constant_thres(img, THRES=THRES)
    if not ASSIGN:
        return labels.astype(np.uint16)
    if labels.any():
        labels, comb, nuc_prop, nuc_loc = label_nearest(img, labels, nuc, dist)
    from skimage.morphology import remove_small_objects
    labels = remove_small_objects(labels, MINAREA)
    return labels.astype(np.uint16)
Пример #3
0
def segment_bacteria_repair(nuc,
                            img,
                            slen=3,
                            SIGMA=0.5,
                            THRES=20,
                            CLOSE=20,
                            THRESCHANGE=1000,
                            MINAREA=5,
                            dist=25):
    """ Segment bacteria and assign to closest nucleus ## This is still under construction

    Args:
        nuc (numpy.ndarray): nuclear mask labels
        img (numpy.ndarray): image in bacterial channel
        slen (int): Size of Gaussian kernel
        SIGMA (float): Standard deviation for Gaussian kernel
        THRES (int): Threshold pixel intensity fo real signal 
        CLOSE (int): Radius for disk used to return morphological closing of the image (dilation followed by erosion to remove dark spots and connect bright cracks)
        THRESCHANGE (int): argument unnecessary? 
        MINAREA (int): minimum area in pixels for a bacterium 

    Returns:
        labels (numpy.ndarray[np.uint16]): bacterial mask labels  

    """
    labels = label_high_pass(img, slen=slen, SIGMA=SIGMA, THRES=THRES, CLOSE=3)
    if labels.any():
        labels, comb, nuc_prop, nuc_loc = label_nearest(img, labels, nuc, dist)
        if not hasattr(holder, 'plabel'):  #not sure what this is doing
            holder.plabel = labels
            holder.pcomb = comb
            holder.pimg = img
            return labels
            #.astype(np.unit16)
        labels = repair_sal(img, holder.pimg, comb, holder.pcomb, labels,
                            nuc_prop, nuc_loc, THRESCHANGE)
    from skimage.morphology import remove_small_objects
    labels = remove_small_objects(labels, MINAREA)
    return labels