本文整理汇总了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
示例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
示例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
示例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]
示例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
示例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
示例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
示例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)
示例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 == [()])
示例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 == [])
示例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),)])
示例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, [])
示例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),)])
示例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, [])
示例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))])