Python skimage.morphology.closing() Examples

The following are 5 code examples of skimage.morphology.closing(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module skimage.morphology , or try the search function .
Example #1
Source File: draw_ellipse.py    From DeepVOG with GNU General Public License v3.0 6 votes vote down vote up
def isolate_islands(prediction, threshold):
    bw = closing(prediction > threshold , square(3))
    labelled = label(bw)  
    regions_properties = regionprops(labelled)
    max_region_area = 0
    select_region = 0
    for region in regions_properties:
        if region.area > max_region_area:
            max_region_area = region.area
            select_region = region
    output = np.zeros(labelled.shape)
    if select_region == 0:
        return output
    else:
        output[labelled == select_region.label] = 1
        return output

# input: output from bwperim -- 2D image with perimeter of the ellipse = 1 
Example #2
Source File: image.py    From PassportEye with MIT License 5 votes vote down vote up
def __call__(self, img_small):
        m = morphology.square(self.square_size)
        img_th = morphology.black_tophat(img_small, m)
        img_sob = abs(filters.sobel_v(img_th))
        img_closed = morphology.closing(img_sob, m)
        threshold = filters.threshold_otsu(img_closed)
        return img_closed > threshold 
Example #3
Source File: segmentation_test.py    From DRFNS with MIT License 5 votes vote down vote up
def prefilter(self, img, rec_size=20, se_size=3):
    
        se = morphology.disk(se_size)
        
        im1 = self.morpho_rec(img, rec_size)
        im2 = self.morpho_rec2(im1, int(rec_size / 2))
        
        im3 = morphology.closing(im2, se)
        
        return im3 
Example #4
Source File: segmentation_test.py    From DRFNS with MIT License 5 votes vote down vote up
def prefilter_new(self, img, rec_size=20, se_size=3):
    
        img_cc = ccore.numpy_to_image(img, copy=True)        
        im1 = ccore.diameter_open(img_cc, rec_size, 8)        
        im2 = ccore.diameter_close(im1, int(rec_size / 2), 8)        

        #im1 = self.morpho_rec(img, rec_size)
        #im2 = self.morpho_rec2(im1, int(rec_size / 2))

        se = morphology.disk(se_size)        
        im3 = morphology.closing(im2.toArray(), se)
        
        return im3 
Example #5
Source File: closing.py    From plantcv with MIT License 5 votes vote down vote up
def closing(gray_img, kernel=None):
    """Wrapper for scikit-image closing functions. Opening can remove small dark spots (i.e. pepper).

    Inputs:
    gray_img = input image (grayscale or binary)
    kernel   = optional neighborhood, expressed as an array of 1s and 0s. If None, use cross-shaped structuring element.

    :param gray_img: ndarray
    :param kernel = ndarray
    :return filtered_img: ndarray
    """

    params.device += 1

    # Make sure the image is binary/grayscale
    if len(np.shape(gray_img)) != 2:
        fatal_error("Input image must be grayscale or binary")

    # If image is binary use the faster method
    if len(np.unique(gray_img)) == 2:
        bool_img = morphology.binary_closing(image=gray_img, selem=kernel)
        filtered_img = np.copy(bool_img.astype(np.uint8) * 255)
    # Otherwise use method appropriate for grayscale images
    else:
        filtered_img = morphology.closing(gray_img, kernel)

    if params.debug == 'print':
        print_image(filtered_img, os.path.join(params.debug_outdir, str(params.device) + '_opening' + '.png'))
    elif params.debug == 'plot':
        plot_image(filtered_img, cmap='gray')

    return filtered_img