當前位置: 首頁>>代碼示例>>Python>>正文


Python ndimage.find_objects方法代碼示例

本文整理匯總了Python中scipy.ndimage.find_objects方法的典型用法代碼示例。如果您正苦於以下問題:Python ndimage.find_objects方法的具體用法?Python ndimage.find_objects怎麽用?Python ndimage.find_objects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.find_objects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _find_flats_edges

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def _find_flats_edges(self, data, mag, direction):
        """
        Extend flats 1 square downstream
        Flats on the downstream side of the flat might find a valid angle,
        but that doesn't mean that it's a correct angle. We have to find
        these and then set them equal to a flat
        """

        i12 = np.arange(data.size).reshape(data.shape)

        flat = mag == FLAT_ID_INT
        flats, n = spndi.label(flat, structure=FLATS_KERNEL3)
        objs = spndi.find_objects(flats)

        f = flat.ravel()
        d = data.ravel()
        for i, _obj in enumerate(objs):
            region = flats[_obj] == i+1
            I = i12[_obj][region]
            J = get_adjacent_index(I, data.shape, data.size)
            f[J] = d[J] == d[I[0]]

        flat = f.reshape(data.shape)
        return flat 
開發者ID:creare-com,項目名稱:pydem,代碼行數:26,代碼來源:dem_processing.py

示例2: find_paws

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def find_paws(data, smooth_radius = 5, threshold = 0.0001):
    # http://stackoverflow.com/questions/4087919/how-can-i-improve-my-paw-detection
    """Detects and isolates contiguous regions in the input array"""
    # Blur the input data a bit so the paws have a continous footprint
    data = ndimage.uniform_filter(data, smooth_radius)
    # Threshold the blurred data (this needs to be a bit > 0 due to the blur)
    thresh = data > threshold
    # Fill any interior holes in the paws to get cleaner regions...
    filled = ndimage.morphology.binary_fill_holes(thresh)
    # Label each contiguous paw
    coded_paws, num_paws = ndimage.label(filled)
    # Isolate the extent of each paw
    # find_objects returns a list of 2-tuples: (slice(...), slice(...))
    # which represents a rectangular box around the object
    data_slices = ndimage.find_objects(coded_paws)
    return data_slices 
開發者ID:leokarlin,項目名稱:LaSO,代碼行數:18,代碼來源:tightcrop.py

示例3: get_transformed_bbox

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def get_transformed_bbox(bbox, image_width, image_height, **kwargs):
    l, t, w, h = bbox
    r = l + w
    b = t + h
    y_heatmap = np.zeros((image_height, image_width)).astype(bool)
    y_heatmap[t:b, l:r] = True

    y_heatmap = im_affine_transform(y_heatmap[np.newaxis, ...], **kwargs)
    y_heatmap = y_heatmap[0].astype(bool)

    dets = find_objects(y_heatmap)

    if len(dets) == 1:
        t = dets[0][0].start
        b = dets[0][0].stop
        l = dets[0][1].start
        r = dets[0][1].stop
        w = r - l
        h = b - t
    else:
        l, t, w, h = 0, 0, 0, 0

    return l, t, w, h 
開發者ID:felixlaumon,項目名稱:kaggle-right-whale,代碼行數:25,代碼來源:iterators.py

示例4: detect_objects_heatmap

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def detect_objects_heatmap(heatmap):
    data = 256 * heatmap
    data_max = filters.maximum_filter(data, 3)
    maxima = (data == data_max)
    data_min = filters.minimum_filter(data, 3)
    diff = ((data_max - data_min) > 0.3)
    maxima[diff == 0] = 0
    labeled, num_objects = ndimage.label(maxima)
    slices = ndimage.find_objects(labeled)
    objects = np.zeros((num_objects, 2), dtype=np.int32)
    pidx = 0
    for (dy, dx) in slices:
        pos = [(dy.start + dy.stop - 1) // 2, (dx.start + dx.stop - 1) // 2]
        if heatmap[pos[0], pos[1]] > config.CENTER_TR:
            objects[pidx, :] = pos
            pidx += 1
    return objects[:pidx] 
開發者ID:DenisTome,項目名稱:Lifting-from-the-Deep-release,代碼行數:19,代碼來源:process.py

示例5: _get_image_segments

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def _get_image_segments(image, kernel, block_size, c):
    binarized_image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                            cv2.THRESH_BINARY_INV, block_size, c)

    labeled, nr_objects = ndimage.label(binarized_image, structure=kernel)
    slices = ndimage.find_objects(labeled)

    image_segments = {}
    for idx, slice_ in enumerate(slices):
        offset = instantiators['point'](slice_[1].start, slice_[0].start)
        sliced_image = image[slice_]
        boolean_array = labeled[slice_] == (idx+1)
        segmented_image = 255- (255-sliced_image) * boolean_array
        pixels = set(instantiators['point'](x, y) for x, y in np.transpose(np.nonzero(np.transpose(boolean_array))))
        binarized_segmented_image = cv2.adaptiveThreshold(segmented_image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                                          cv2.THRESH_BINARY_INV, block_size, c)

        image_segment = ImageSegment(segmented_image, sliced_image, binarized_segmented_image, pixels, offset, idx)
        image_segments[idx] = image_segment

    return image_segments 
開發者ID:uwnlp,項目名稱:geosolver,代碼行數:23,代碼來源:parse_image_segments.py

示例6: find_slices

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def find_slices(mask_img):
    mask = mask_img > 100
    label_im, nb_labels = ndimage.label(mask)
    # Find the largest connect component
    sizes = ndimage.sum(mask, label_im, range(nb_labels + 1))
    mask_size = sizes < 50000
    remove_pixel = mask_size[label_im]
    label_im[remove_pixel] = 0
    labels = np.unique(label_im)
    label_im = np.searchsorted(labels, label_im)
    # Now that we have only one connect component, extract it's bounding box
    slice_y, slice_x = ndimage.find_objects(label_im == 1)[0]
    return slice_x, slice_y 
開發者ID:killthekitten,項目名稱:kaggle-carvana-2017,代碼行數:15,代碼來源:find_bounding_boxes.py

示例7: find_blank_rows

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def find_blank_rows(image, line_spacing=1):

    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blank_rows = np.all(gray_image == 255, axis=1)

    im_bw = np.zeros(gray_image.shape)
    im_bw[blank_rows] = 255
    #gray_image[~blank_rows] = 0

    #cv2.imwrite("/home/psm2208/code/eval/test.png", im_bw)

    labeled, ncomponents = ndimage.label(im_bw)
    rows = []

    indices = np.indices(im_bw.shape).T[:, :, [1, 0]]

    line_bbs = ndimage.find_objects(labeled)
    sizes = np.array([[bb.stop - bb.start for bb in line_bb]
                      for line_bb in line_bbs])

    sizes = sizes[:,0]
    mask = (sizes > line_spacing)

    idx = np.flatnonzero(mask)

    for i in idx:
        labels = (labeled == (i+1))
        pixels = indices[labels.T]
        box = [min(pixels[:, 0]), min(pixels[:, 1]), max(pixels[:, 0]), max(pixels[:, 1])]
        rows.append(box)

    return rows 
開發者ID:MaliParag,項目名稱:ScanSSD,代碼行數:34,代碼來源:stitch_patches_page.py

示例8: test_label_default_dtype

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_label_default_dtype():
    test_array = np.random.rand(10, 10)
    label, no_features = ndimage.label(test_array > 0.5)
    assert_(label.dtype in (np.int32, np.int64))
    # Shouldn't raise an exception
    ndimage.find_objects(label) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_measurements.py

示例9: test_find_objects01

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects01():
    "find_objects 1"
    data = np.ones([], dtype=int)
    out = ndimage.find_objects(data)
    assert_(out == [()]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_measurements.py

示例10: test_find_objects02

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects02():
    "find_objects 2"
    data = np.zeros([], dtype=int)
    out = ndimage.find_objects(data)
    assert_(out == []) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_measurements.py

示例11: test_find_objects03

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects03():
    "find_objects 3"
    data = np.ones([1], dtype=int)
    out = ndimage.find_objects(data)
    assert_equal(out, [(slice(0, 1, None),)]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_measurements.py

示例12: test_find_objects04

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects04():
    "find_objects 4"
    data = np.zeros([1], dtype=int)
    out = ndimage.find_objects(data)
    assert_equal(out, []) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_measurements.py

示例13: test_find_objects06

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects06():
    "find_objects 6"
    data = np.array([1, 0, 2, 2, 0, 3])
    out = ndimage.find_objects(data)
    assert_equal(out, [(slice(0, 1, None),),
                       (slice(2, 4, None),),
                       (slice(5, 6, None),)]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:9,代碼來源:test_measurements.py

示例14: test_find_objects07

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects07():
    "find_objects 7"
    data = np.array([[0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0]])
    out = ndimage.find_objects(data)
    assert_equal(out, []) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_measurements.py

示例15: test_find_objects08

# 需要導入模塊: from scipy import ndimage [as 別名]
# 或者: from scipy.ndimage import find_objects [as 別名]
def test_find_objects08():
    "find_objects 8"
    data = np.array([[1, 0, 0, 0, 0, 0],
                           [0, 0, 2, 2, 0, 0],
                           [0, 0, 2, 2, 2, 0],
                           [3, 3, 0, 0, 0, 0],
                           [3, 3, 0, 0, 0, 0],
                           [0, 0, 0, 4, 4, 0]])
    out = ndimage.find_objects(data)
    assert_equal(out, [(slice(0, 1, None), slice(0, 1, None)),
                       (slice(1, 3, None), slice(2, 5, None)),
                       (slice(3, 5, None), slice(0, 2, None)),
                       (slice(5, 6, None), slice(3, 5, None))]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:test_measurements.py


注:本文中的scipy.ndimage.find_objects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。