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


Python segmentation.felzenszwalb函数代码示例

本文整理汇总了Python中skimage.segmentation.felzenszwalb函数的典型用法代码示例。如果您正苦于以下问题:Python felzenszwalb函数的具体用法?Python felzenszwalb怎么用?Python felzenszwalb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_minsize

def test_minsize():
    # single-channel:
    img = data.coins()[20:168, 0:128]
    for min_size in np.arange(10, 100, 10):
        segments = felzenszwalb(img, min_size=min_size, sigma=3)
        counts = np.bincount(segments.ravel())
        # actually want to test greater or equal.
        assert_greater(counts.min() + 1, min_size)
    # multi-channel:
    coffee = data.coffee()[::4, ::4]
    for min_size in np.arange(10, 100, 10):
        segments = felzenszwalb(coffee, min_size=min_size, sigma=3)
        counts = np.bincount(segments.ravel())
        # actually want to test greater or equal.
        assert_greater(counts.min() + 1, min_size)
开发者ID:Cadair,项目名称:scikit-image,代码行数:15,代码来源:test_felzenszwalb.py

示例2: fun_compare_colorsegmentation_and_display

def fun_compare_colorsegmentation_and_display(image_data, number_segments=250, compactness_factor=10):
    """
    The function is a copy of what does this link http://scikit-image.org/docs/dev/auto_examples/plot_segmentations.html
    """
    segments_fz = felzenszwalb(image_data, scale=100, sigma=0.5, min_size=50)
    segments_slic = slic(image_data, n_segments=number_segments, compactness=compactness_factor, sigma=1)
    segments_quick = quickshift(image_data, kernel_size=3, max_dist=6, ratio=0.5)

    print ("Felzenszwalb's number of segments: %d" % len(np.unique(segments_fz)))
    print ("Slic number of segments: %d" % len(np.unique(segments_slic)))
    print ("Quickshift number of segments: %d" % len(np.unique(segments_quick)))

    fig, ax = plt.subplots(1, 3, sharex=True, sharey=True, subplot_kw={"adjustable": "box-forced"})
    fig.set_size_inches(8, 3, forward=True)
    fig.subplots_adjust(0.05, 0.05, 0.95, 0.95, 0.05, 0.05)

    ax[0].imshow(mark_boundaries(image_data, segments_fz, color=(1, 0, 0)))
    ax[0].set_title("Felzenszwalbs's method")
    ax[1].imshow(mark_boundaries(image_data, segments_slic, color=(1, 0, 0)))
    ax[1].set_title("SLIC")
    ax[2].imshow(mark_boundaries(image_data, segments_quick, color=(1, 0, 0)))
    ax[2].set_title("Quickshift")
    for a in ax:
        a.set_xticks(())
        a.set_yticks(())
    plt.show()
开发者ID:mrbonsoir,项目名称:random_notebooks,代码行数:26,代码来源:visualisationTools.py

示例3: selectiveSearch

def selectiveSearch(image):
    segments = felzenszwalb(image, scale=kFelzenszwalbScale)
    numRegions = segments.max()

    rectangles = []

    for regionTag in range(numRegions):
        selectedRegion = segments == regionTag
        regionPixelIndices = np.transpose(np.nonzero(selectedRegion))
        rectangle = aabb(regionPixelIndices)
        rectangles.append(rectangle)

    # Implement similarities, neighbourhood merging.
    # Felzenszwalb's segmentation is ridiculously good already.

    def debug():
        marked = np.zeros(image.shape, dtype=np.uint8)

        for rectangle in rectangles:
            rr, cc = rectangle.pixels(marked.shape)
            randcolor = randint(0, 255), randint(0, 255), randint(0, 255)
            marked[rr, cc] = randcolor

        print(image.shape, segments.shape, marked.shape)

        io.imshow_collection([image, segments, marked])
        io.show()

    # debug()

    return rectangles
开发者ID:daniel-j-h,项目名称:exit-signs,代码行数:31,代码来源:region-cnn.py

示例4: SegmentationFelz_run_2d

def SegmentationFelz_run_2d(rod):
    img = img_as_float(
        RodriguesToUnambiguousColor(rod["x"], rod["y"], rod["z"], maxRange=None, centerR=None).astype("uint8")
    )
    segments_slic = felzenszwalb(img, scale=100, sigma=0.0, min_size=10)
    print("Slic number of segments: %d" % len(np.unique(segments_slic)))
    return segments_slic
开发者ID:mattbierbaum,项目名称:cuda-plasticity,代码行数:7,代码来源:KMeansPruning.py

示例5: mask_felz

def mask_felz(image, config):
    #constants for felzenszwalb segmentation function
    scale = config[':felzenszwalb'][':scale']
    sigma = config[':felzenszwalb'][':sigma'] 
    min_size = config[':felzenszwalb'][':min_size'] 

    segments = felzenszwalb(image, scale, sigma, min_size)
    return segments
开发者ID:r3vl1s,项目名称:collagen,代码行数:8,代码来源:segments.py

示例6: doSegment

def doSegment(param, img):
  if param[0] == 'slic':
    segments_res = slic(img, n_segments=int(param[1]), compactness=int(param[2]), sigma=int(param[3]), convert2lab=True)
  elif param[0] == 'pff':
    segments_res = felzenszwalb(img, scale=int(param[1]), sigma=float(param[2]), min_size=int(param[3]))
  elif param[0] == 'quick':
    segments_res = quickshift(img, kernel_size=int(param[1]), max_dist=int(param[2]), ratio=float(param[3]), convert2lab=True)
  return segments_res
开发者ID:iandjakman,项目名称:lab1231-sun-prj,代码行数:8,代码来源:segment.py

示例7: test_minsize

def test_minsize():
    # single-channel:
    img = data.coins()[20:168,0:128]
    for min_size in np.arange(10, 100, 10):
        segments = felzenszwalb(img, min_size=min_size, sigma=3)
        counts = np.bincount(segments.ravel())
        # actually want to test greater or equal.
        assert_greater(counts.min() + 1, min_size)
    # multi-channel:
    coffee = data.coffee()[::4, ::4]
    for min_size in np.arange(10, 100, 10):
        segments = felzenszwalb(coffee, min_size=min_size, sigma=3)
        counts = np.bincount(segments.ravel())
        # actually want to test greater or equal.
        # the construction doesn't guarantee min_size is respected
        # after intersecting the sementations for the colors
        assert_greater(np.mean(counts) + 1, min_size)
开发者ID:AceHao,项目名称:scikit-image,代码行数:17,代码来源:test_felzenszwalb.py

示例8: test_merging

def test_merging():
    # test region merging in the post-processing step
    img = np.array([[0, 0.3], [0.7, 1]])
    # With scale=0, only the post-processing is performed.
    seg = felzenszwalb(img, scale=0, sigma=0, min_size=2)
    # we expect 2 segments:
    assert_equal(len(np.unique(seg)), 2)
    assert_array_equal(seg[0, :], 0)
    assert_array_equal(seg[1, :], 1)
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_felzenszwalb.py

示例9: __init__

    def __init__(self, fname):
        self.fname = fname
        self.image_cache = {}

        print 'loading image'
        self.raw_img = io.imread(fname)
        self._segment_ids = None
        img_float = img_as_float(self.raw_img)
        print 'segmenting image'
        self.segments = felzenszwalb(img_float, scale=300, sigma=0.5, min_size=100)
开发者ID:pombredanne,项目名称:spatchwork,代码行数:10,代码来源:segment.py

示例10: extract

 def extract(self, image):
     """
     Performs segmentation and returns a set of nd.array
     """
     # Init the list of segmentations
     segmentations = []
     for param in self.params_:
         sc, sg, m = param
         segm_mask = segmentation.felzenszwalb(image, sc, sg, m)
         segmentations.append(segm_mask)
     return segmentations
开发者ID:ElegantGod,项目名称:self-taught_localization,代码行数:11,代码来源:imgsegmentation.py

示例11: test_grey

def test_grey():
    # very weak tests.
    img = np.zeros((20, 21))
    img[:10, 10:] = 0.2
    img[10:, :10] = 0.4
    img[10:, 10:] = 0.6
    seg = felzenszwalb(img, sigma=0)
    # we expect 4 segments:
    assert_equal(len(np.unique(seg)), 4)
    # that mostly respect the 4 regions:
    for i in range(4):
        hist = np.histogram(img[seg == i], bins=[0, 0.1, 0.3, 0.5, 1])[0]
        assert_greater(hist[i], 40)
开发者ID:Cadair,项目名称:scikit-image,代码行数:13,代码来源:test_felzenszwalb.py

示例12: test_color

def test_color():
    # very weak tests.
    img = np.zeros((20, 21, 3))
    img[:10, :10, 0] = 1
    img[10:, :10, 1] = 1
    img[10:, 10:, 2] = 1
    seg = felzenszwalb(img, sigma=0)
    # we expect 4 segments:
    assert_equal(len(np.unique(seg)), 4)
    assert_array_equal(seg[:10, :10], 0)
    assert_array_equal(seg[10:, :10], 2)
    assert_array_equal(seg[:10, 10:], 1)
    assert_array_equal(seg[10:, 10:], 3)
开发者ID:Cadair,项目名称:scikit-image,代码行数:13,代码来源:test_felzenszwalb.py

示例13: SegmentationFelzenszwalb

def SegmentationFelzenszwalb(filename="/media/scratch/plasticity/lvp2d1024_s0_d.tar", time=None):
    t, s = TarFile.LoadTarState(filename, time=time)
    rod = s.CalculateRotationRodrigues()
    img = img_as_float(
        RodriguesToUnambiguousColor(rod["x"], rod["y"], rod["z"], maxRange=None, centerR=None).astype("uint8")
    )

    segments_slic = felzenszwalb(img, scale=100, sigma=0.0, min_size=10)
    print("Slic number of segments: %d" % len(np.unique(segments_slic)))

    fig = plt.figure()
    plt.imshow(mark_boundaries(img, segments_slic, color=[0, 0, 0], outline_color=None))
    plt.show()
开发者ID:mattbierbaum,项目名称:cuda-plasticity,代码行数:13,代码来源:KMeansPruning.py

示例14: __init__

    def __init__(self, fname):
        self.fname = fname

        print 'loading image'
        img = Image.open(fname)
        img.thumbnail((1280,1024), Image.ANTIALIAS)
        width, height = img.size
        square_size = width * height
        min_size = square_size / 300
        self.raw_img = np.array(enhance(img).convert('RGB'))
        self._segment_ids = None
        img_float = img_as_float(self.raw_img)
        print 'segmenting image'
        self.segments = felzenszwalb(img_float, scale=300, sigma=0.25, min_size=min_size)
开发者ID:bobpoekert,项目名称:spatchwork,代码行数:14,代码来源:segment.py

示例15: clustering

def clustering(inPixNP, width, height, scale=50, sigma=4.5, min_size=10):
    segmentsNP = felzenszwalb(inPixNP, scale, sigma, min_size)
    # felzenszwalb(image, scale=1, sigma=0.8, min_size=20)
    # image : (width, height, 3) or (width, height) ndarray - Input image.
    # scale : float - Free parameter. Higher means larger clusters.
    # sigma : float - Width of Gaussian kernel used in preprocessing.
    # min_size : int - Minimum component size. Enforced using postprocessing.
    
    # create a data structure with regionIDs as keys and lists of their pixel coordinates as values:
    maxSegmentID = np.max(segmentsNP)
    segmentsByIDlist = [[] for i in range(maxSegmentID + 1)]
    for y in range(0,height):
        for x in range(0,width):
            regionID = segmentsNP[y,x]
            segmentsByIDlist[regionID].append((x, y))
    return segmentsNP, segmentsByIDlist
开发者ID:afremize,项目名称:afremize,代码行数:16,代码来源:afremize.py


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