当前位置: 首页>>代码示例>>Python>>正文


Python morphology.remove_small_objects方法代码示例

本文整理汇总了Python中skimage.morphology.remove_small_objects方法的典型用法代码示例。如果您正苦于以下问题:Python morphology.remove_small_objects方法的具体用法?Python morphology.remove_small_objects怎么用?Python morphology.remove_small_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.morphology的用法示例。


在下文中一共展示了morphology.remove_small_objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_small_tissue

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def remove_small_tissue(bw_img, min_size=10000):
    """ Remove small holes in tissue image
    Parameters
    ----------
    bw_img : np.array
        2D binary image.
    min_size: int
        Minimum tissue area.
    Returns
    -------
    bw_remove: np.array
        Binary image with small tissue regions removed
    """

    bw_remove = remove_small_objects(bw_img, min_size=min_size, connectivity=8)

    return bw_remove 
开发者ID:PingjunChen,项目名称:tissueloc,代码行数:19,代码来源:locate_tissue.py

示例2: wsh

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def wsh(mask_img, threshold, border_img, seeds):
    img_copy = np.copy(mask_img)
    m = seeds * border_img# * dt
    img_copy[m <= threshold + 0.35] = 0
    img_copy[m > threshold + 0.35] = 1
    img_copy = img_copy.astype(np.bool)
    img_copy = remove_small_objects(img_copy, 10).astype(np.uint8)

    mask_img[mask_img <= threshold] = 0
    mask_img[mask_img > threshold] = 1
    mask_img = mask_img.astype(np.bool)
    mask_img = remove_small_holes(mask_img, 1000)
    mask_img = remove_small_objects(mask_img, 8).astype(np.uint8)
    # cv2.imwrite('t.png', (mask_img * 255).astype(np.uint8))
    # cv2.imwrite('t2.png', (img_copy * 255).astype(np.uint8))
    labeled_array = my_watershed(mask_img, mask_img, img_copy)
    return labeled_array 
开发者ID:selimsef,项目名称:dsb2018_topcoders,代码行数:19,代码来源:submit.py

示例3: test_autocrop

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def test_autocrop(self):
        from PIL import Image
        import numpy as np
        from skimage import morphology
        image = Image.open("screenshots/screenshot.png")
        width, height = image.size[0], image.size[1]
        array_img = np.array(image)
        ot_img = (array_img > 200)
        obj_dtec_img = morphology.remove_small_objects(ot_img, min_size=width * height / 4, connectivity=1)
        if np.sum(obj_dtec_img) < 1000:
            print("can't find question")
        print([
            np.where(obj_dtec_img * 1.0 > 0)[1].min() + 20,
            np.where(obj_dtec_img * 1.0 > 0)[0].min(),
            np.where(obj_dtec_img * 1.0 > 0)[1].max(),
            np.where(obj_dtec_img * 1.0 > 0)[0].max()]) 
开发者ID:smileboywtu,项目名称:MillionHeroAssistant,代码行数:18,代码来源:test.py

示例4: auto_find_crop_area

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def auto_find_crop_area(source_file):
    """
    1. convert to gray picture
    2. find pixel > 200 (white) and connect
    3. if > image/4 
    4. find edge of question and answer
    
    :param source_file:
    :return: 
    """
    image = Image.open(source_file)
    width, height = image.size[0], image.size[1]
    array_img = np.array(image)
    ot_img = (array_img > 200)
    obj_dtec_img = morphology.remove_small_objects(ot_img, min_size=width * height / 4, connectivity=1)
    if np.sum(obj_dtec_img) < 1000:
        return []
    return [
        np.where(obj_dtec_img * 1.0 > 0)[1].min() + 20,
        np.where(obj_dtec_img * 1.0 > 0)[0].min(),
        np.where(obj_dtec_img * 1.0 > 0)[1].max(),
        np.where(obj_dtec_img * 1.0 > 0)[0].max()] 
开发者ID:smileboywtu,项目名称:MillionHeroAssistant,代码行数:24,代码来源:android.py

示例5: finalProcessingArea

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def finalProcessingArea(s, params):
    logging.info(f"{s['filename']} - \tfinalProcessingArea")
    area_thresh = int(params.get("area_threshold", "1000"))
    mask = s["img_mask_use"]

    mask_opened = remove_small_objects(mask, min_size=area_thresh)
    mask_removed_area = ~mask_opened & mask

    io.imsave(s["outdir"] + os.sep + s["filename"] + "_areathresh.png", img_as_ubyte(mask_removed_area))

    prev_mask = s["img_mask_use"]
    s["img_mask_use"] = mask_opened > 0

    s.addToPrintList("areaThresh",
                     printMaskHelper(params.get("mask_statistics", s["mask_statistics"]), prev_mask, s["img_mask_use"]))

    if len(s["img_mask_use"].nonzero()[0]) == 0:  # add warning in case the final tissue is empty
        logging.warning(
            f"{s['filename']} - After BasicModule.finalProcessingArea NO tissue remains detectable! Downstream modules likely to be incorrect/fail")
        s["warnings"].append(
            f"After BasicModule.finalProcessingArea NO tissue remains detectable! Downstream modules likely to be incorrect/fail") 
开发者ID:choosehappy,项目名称:HistoQC,代码行数:23,代码来源:BasicModule.py

示例6: removeSmallObjects

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def removeSmallObjects(s, params):
    logging.info(f"{s['filename']} - \tremoveSmallObjects")
    min_size = int(params.get("min_size", 64))
    img_reduced = morphology.remove_small_objects(s["img_mask_use"], min_size=min_size)
    img_small = np.invert(img_reduced) & s["img_mask_use"]

    io.imsave(s["outdir"] + os.sep + s["filename"] + "_small_remove.png", img_as_ubyte(img_small))
    s["img_mask_small_filled"] = (img_small * 255) > 0

    prev_mask = s["img_mask_use"]
    s["img_mask_use"] = img_reduced

    s.addToPrintList("percent_small_tissue_removed",
                     printMaskHelper(params.get("mask_statistics", s["mask_statistics"]), prev_mask, s["img_mask_use"]))


    if len(s["img_mask_use"].nonzero()[0]) == 0:  # add warning in case the final tissue is empty
        logging.warning(f"{s['filename']} - After MorphologyModule.removeSmallObjects: NO tissue "
                        f"remains detectable! Downstream modules likely to be incorrect/fail")
        s["warnings"].append(f"After MorphologyModule.removeSmallObjects: NO tissue remains "
                             f"detectable! Downstream modules likely to be incorrect/fail")

    return 
开发者ID:choosehappy,项目名称:HistoQC,代码行数:25,代码来源:MorphologyModule.py

示例7: proc_np_dist

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def proc_np_dist(pred):
    """
    Process Nuclei Prediction with Distance Map

    Args:
        pred: prediction output, assuming 
                channel 0 contain probability map of nuclei
                channel 1 containing the regressed distance map
    """
    blb_raw = pred[...,0]
    dst_raw = pred[...,1]

    blb = np.copy(blb_raw)
    blb[blb >  0.5] = 1
    blb[blb <= 0.5] = 0
    blb = measurements.label(blb)[0]
    blb = remove_small_objects(blb, min_size=10)
    blb[blb > 0] = 1   

    dst_raw[dst_raw < 0] = 0
    dst = np.copy(dst_raw)
    dst = dst * blb
    dst[dst  > 0.5] = 1
    dst[dst <= 0.5] = 0

    marker = dst.copy()
    marker = binary_fill_holes(marker) 
    marker = measurements.label(marker)[0]
    marker = remove_small_objects(marker, min_size=10)
    proced_pred = watershed(-dst_raw, marker, mask=blb)    
    return proced_pred

#### 
开发者ID:vqdang,项目名称:hover_net,代码行数:35,代码来源:hover.py

示例8: cleanSmallObjects

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def cleanSmallObjects(self):
        cleanImg = morphology.remove_small_objects(self.curImg, min_size=130, connectivity=100)
        self.curImg = cleanImg
    
    #cv2.imwrite('Final123.jpg',threshImg) 
开发者ID:ebdulrasheed,项目名称:Diabetic-Retinopathy-Feature-Extraction-using-Fundus-Images,代码行数:7,代码来源:BloodVessels.py

示例9: compute_binary_mask_lasseck

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def compute_binary_mask_lasseck(spectrogram, threshold):
    # normalize to [0, 1)
    norm_spectrogram = normalize(spectrogram)

    # median clipping
    binary_image = median_clipping(norm_spectrogram, threshold)

    # closing binary image (dilation followed by erosion)
    binary_image = morphology.binary_closing(binary_image, selem=np.ones((4, 4)))

    # dialate binary image
    binary_image = morphology.binary_dilation(binary_image, selem=np.ones((4, 4)))

    # apply median filter
    binary_image = filters.median(binary_image, selem=np.ones((2, 2)))

    # remove small objects
    binary_image = morphology.remove_small_objects(binary_image, min_size=32, connectivity=1)

    mask = np.array([np.max(col) for col in binary_image.T])
    mask = smooth_mask(mask)

    return mask


# TODO: This method needs some real testing 
开发者ID:johnmartinsson,项目名称:bird-species-classification,代码行数:28,代码来源:preprocessing.py

示例10: get_rough_detection

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def get_rough_detection(self, img, bigsize=40.0, smallsize=4.0, thresh = 0):
        diff = self.difference_of_gaussian(-img, bigsize, smallsize)
        diff[diff>thresh] = 1
        
        se = morphology.square(4)
        ero = morphology.erosion(diff, se)
        
        labimage = label(ero)
        #rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
        
        # connectivity=1 corresponds to 4-connectivity.
        morphology.remove_small_objects(labimage, min_size=600, connectivity=1, in_place=True)
        #res = np.zeros(img.shape)
        ero[labimage==0] = 0
        ero = 1 - ero
        labimage = label(ero)
        morphology.remove_small_objects(labimage, min_size=400, connectivity=1, in_place=True)
        ero[labimage==0] = 0
        res = 1 - ero
        res[res>0] = 255
        
        #temp = 255 - temp
        #temp = morphology.remove_small_objects(temp, min_size=400, connectivity=1, in_place=True)
        #res = 255 - temp
        
        return res 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:28,代码来源:segmentation_test.py

示例11: drop_small_unlabeled

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def drop_small_unlabeled(img, min_size):
    img = morph.remove_small_objects(img.astype(np.bool), min_size=min_size)
    return img.astype(np.uint8) 
开发者ID:minerva-ml,项目名称:open-solution-data-science-bowl-2018,代码行数:5,代码来源:postprocessing.py

示例12: drop_small

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def drop_small(img, min_size):
    img = morph.remove_small_objects(img, min_size=min_size)
    return relabel(img) 
开发者ID:minerva-ml,项目名称:open-solution-data-science-bowl-2018,代码行数:5,代码来源:postprocessing.py

示例13: remove_small_regions

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def remove_small_regions(img, size):
    """Morphologically removes small (less than size) connected regions of 0s or 1s."""
    img = morphology.remove_small_objects(img, size)
    img = morphology.remove_small_holes(img, size)
    return img 
开发者ID:SConsul,项目名称:Global_Convolutional_Network,代码行数:7,代码来源:inferences.py

示例14: load_correct_segm

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def load_correct_segm(path_img):
    """ load segmentation and correct it with simple morphological operations

    :param str path_img:
    :return (ndarray, ndarray):
    """
    assert os.path.isfile(path_img), 'missing: %s' % path_img
    logging.debug('loading image: %s', path_img)
    img = tl_data.io_imread(path_img)
    seg = (img > 0)
    seg = morphology.binary_opening(seg, selem=morphology.disk(25))
    seg = morphology.remove_small_objects(seg)
    seg_lb = measure.label(seg)
    seg_lb[seg == 0] = 0
    return seg, seg_lb 
开发者ID:Borda,项目名称:pyImSegm,代码行数:17,代码来源:run_create_annotation.py

示例15: parse_answer_area

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import remove_small_objects [as 别名]
def parse_answer_area(source_file, text_area_file, compress_level, crop_area):
    """
    crop the answer area

    :return:
    """

    image = Image.open(source_file)
    width, height = image.size[0], image.size[1]

    if not crop_area:
        image = image.convert("L")
        array_img = np.array(image)
        ot_img = (array_img > 225)
        obj_dtec_img = morphology.remove_small_objects(ot_img, min_size=width * height / 4, connectivity=1)
        if np.sum(obj_dtec_img) < 1000:
            return False
        region = image.crop((
            np.where(obj_dtec_img * 1.0 > 0)[1].min() + 20,
            np.where(obj_dtec_img * 1.0 > 0)[0].min() + 215,
            np.where(obj_dtec_img * 1.0 > 0)[1].max(),
            np.where(obj_dtec_img * 1.0 > 0)[0].max()))
    else:
        if compress_level == 1:
            image = image.convert("L")
        elif compress_level == 2:
            image = image.convert("1")
        region = image.crop((width * crop_area[0], height * crop_area[1], width * crop_area[2], height * crop_area[3]))

    if enable_scale:
        region = region.resize((int(1080 / 3), int(1920 / 5)), Image.BILINEAR)
    region.save(text_area_file)
    return True 
开发者ID:smileboywtu,项目名称:MillionHeroAssistant,代码行数:35,代码来源:android.py


注:本文中的skimage.morphology.remove_small_objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。