當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。