本文整理汇总了Python中skimage.transform.hough_line_peaks函数的典型用法代码示例。如果您正苦于以下问题:Python hough_line_peaks函数的具体用法?Python hough_line_peaks怎么用?Python hough_line_peaks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hough_line_peaks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hough_line_peaks_dist
def test_hough_line_peaks_dist():
img = np.zeros((100, 100), dtype=np.bool_)
img[:, 30] = True
img[:, 40] = True
hspace, angles, dists = tf.hough_line(img)
assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=5)[0]) == 2
assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=15)[0]) == 1
示例2: test_hough_line_peaks_dist
def test_hough_line_peaks_dist():
img = np.zeros((100, 100), dtype=np.bool_)
img[:, 30] = True
img[:, 40] = True
hspace, angles, dists = tf.hough_line(img)
with expected_warnings(['`background`']):
assert len(tf.hough_line_peaks(hspace, angles, dists,
min_distance=5)[0]) == 2
assert len(tf.hough_line_peaks(hspace, angles, dists,
min_distance=15)[0]) == 1
示例3: calculate
def calculate(self, image: np.ndarray, disk_size: int=9,
mean_threshold: int=100, min_object_size: int=750) -> float:
# Find edges that have a strong vertical direction
vertical_edges = sobel_v(image)
# Separate out the areas where there is a large amount of vertically-oriented stuff
segmentation = self._segment_edge_areas(vertical_edges, disk_size, mean_threshold, min_object_size)
# Draw a line that follows the center of the segments at each point, which should be roughly vertical
# We should expect this to give us four approximately-vertical lines, possibly with many gaps in
# each line
skeletons = skeletonize(segmentation)
# Use the Hough transform to get the closest lines that approximate those four lines
hough = transform.hough_line(skeletons, np.arange(-constants.FIFTEEN_DEGREES_IN_RADIANS,
constants.FIFTEEN_DEGREES_IN_RADIANS,
0.0001))
# Create a list of the angles (in radians) of all of the lines the Hough transform produced, with 0.0
# being completely vertical
# These angles correspond to the angles of the four sides of the channels, which we need to
# correct for
angles = [angle for _, angle, dist in zip(*transform.hough_line_peaks(*hough))]
if not angles:
raise ValueError("Image rotation could not be calculated. Check the images to see if they're weird.")
else:
# Get the average angle and convert it to degrees
offset = sum(angles) / len(angles) * 180.0 / math.pi
if offset > constants.ACCEPTABLE_SKEW_THRESHOLD:
log.warn("Image is heavily skewed. Check that the images are valid.")
return offset
示例4: test_hough_line_peaks_zero_input
def test_hough_line_peaks_zero_input():
# Test to make sure empty input doesn't cause a failure
img = np.zeros((100, 100), dtype='uint8')
theta = np.linspace(0, np.pi, 100)
hspace, angles, dists = transform.hough_line(img, theta)
h, a, d = transform.hough_line_peaks(hspace, angles, dists)
assert_equal(a, np.array([]))
示例5: calculate_rotation
def calculate_rotation(image):
# sometimes we snag corners, by cropping the left and right 10% of the image we focus only on the
# vertical bars formed by the structure
height, width = image.shape
crop = int(width * 0.1)
cropped_image = image[:, crop: width - crop]
# Find edges that have a strong vertical direction
vertical_edges = sobel_v(cropped_image)
# Separate out the areas where there is a large amount of vertically-oriented stuff
segmentation = segment_edge_areas(vertical_edges)
# Draw a line that follows the center of the segments at each point, which should be roughly vertical
# We should expect this to give us four approximately-vertical lines, possibly with many gaps in
# each line
skeletons = skeletonize(segmentation)
# Use the Hough transform to get the closest lines that approximate those four lines
hough = transform.hough_line(skeletons, np.arange(-constants.FIFTEEN_DEGREES_IN_RADIANS,
constants.FIFTEEN_DEGREES_IN_RADIANS,
0.0001))
# Create a list of the angles (in radians) of all of the lines the Hough transform produced, with 0.0
# being completely vertical
# These angles correspond to the angles of the four sides of the channels, which we need to
# correct for
angles = [angle for _, angle, dist in zip(*transform.hough_line_peaks(*hough))]
if not angles:
raise ValueError("Image rotation could not be calculated. Check the images to see if they're weird.")
else:
# Get the average angle and convert it to degrees
offset = sum(angles) / len(angles) * 180.0 / math.pi
if offset > constants.ACCEPTABLE_SKEW_THRESHOLD:
log.warn("Image is heavily skewed. Check that the images are valid.")
return offset
示例6: removeChessboard
def removeChessboard(img):
# Get the major lines in the image
edges, dilatedEdges, (h, theta, d) = findLines(img)
# Create image with ones to fill inn lines
lines = np.ones(img.shape[:2])
# Add lines to image as zeroes
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
y1 = (dist - img.shape[1] * np.cos(angle)) / np.sin(angle)
x, y = line(int(y1), 0, int(y0), img.shape[1] - 1)
x = np.clip(x, 0, img.shape[0] - 1)
y = np.clip(y, 0, img.shape[1] - 1)
lines[x, y] = 0
# Remove border edges from image with all edges
w = 4
edges = np.pad(edges[w:img.shape[0] - w, w:img.shape[1] - w], w, mode='constant')
# Erode the lines bigger, such that they cover the original lines
lines = erosion(lines, square(13))
# Remove major lines and close shape paths
removedChessboard = closing(edges * lines, square(8))
return removedChessboard
示例7: test_hough_line_peaks_num
def test_hough_line_peaks_num():
img = np.zeros((100, 100), dtype=np.bool_)
img[:, 30] = True
img[:, 40] = True
hspace, angles, dists = transform.hough_line(img)
assert len(transform.hough_line_peaks(hspace, angles, dists,
min_distance=0, min_angle=0,
num_peaks=1)[0]) == 1
示例8: align_with_boarder
def align_with_boarder(image, sigma=1):
edges = ft.canny(image, sigma=sigma)
# edges = abs(fil.sobel_v(image))
h, theta, d = tf.hough_line(edges)
a, rot_angle, c = tf.hough_line_peaks(h, theta, d, min_distance=0)
image = rotate(image, np.rad2deg(rot_angle[0]))
return image
示例9: test_ideal_tfr
def test_ideal_tfr(self):
"""Test if the ideal TFR can be found using the instantaneous frequency
laws."""
_, iflaw1 = fmlin(128, 0.0, 0.2)
_, iflaw2 = fmlin(128, 0.3, 0.5)
iflaws = np.c_[iflaw1, iflaw2].T
tfr, _, _ = pproc.ideal_tfr(iflaws)
tfr[tfr == 1] = 255
tfr = tfr.astype(np.uint8)
hspace, angles, dists = hough_line(tfr)
for x in hough_line_peaks(hspace, angles, dists):
self.assertEqual(len(x), 2)
示例10: test_hough_line_peaks
def test_hough_line_peaks():
img = np.zeros((100, 150), dtype=int)
rr, cc = line(60, 130, 80, 10)
img[rr, cc] = 1
out, angles, d = tf.hough_line(img)
out, theta, dist = tf.hough_line_peaks(out, angles, d)
assert_equal(len(dist), 1)
assert_almost_equal(dist[0], 80.723, 1)
assert_almost_equal(theta[0], 1.41, 1)
示例11: houghSides
def houghSides(bottle, edges, threshold, left):
h, theta, d = hough_line(edges)
accum = zip(*hough_line_peaks(h, theta, d))
sortedAccum = sorted(accum, key=getKey, reverse=True)
sortedAccumR = [sa for sa in sortedAccum if sa[2] > 200]
sortedAccumL = [sa for sa in sortedAccum if sa[2] <= 200]
if left:
hpeak, angle, dist = sortedAccumL[0]
else:
hpeak, angle, dist in sortedAccumR[0]
return (1, dist, angle)
示例12: test_hough_line_peaks_ordered
def test_hough_line_peaks_ordered():
# Regression test per PR #1421
testim = np.zeros((256, 64), dtype=np.bool)
testim[50:100, 20] = True
testim[85:200, 25] = True
testim[15:35, 50] = True
testim[1:-1, 58] = True
hough_space, angles, dists = tf.hough_line(testim)
hspace, _, _ = tf.hough_line_peaks(hough_space, angles, dists)
assert hspace[0] > hspace[1]
示例13: check_door
def check_door(image, Pw_corners, Pi_corners, door_edges,
required_matching_ratio=0.7, verbose=0):
"""Check if door is closed."""
results = {}
image_sobel, image_edges = detect_edges(image)
# Detect lines with Hough transform
hough_accumulator, angles, dists = hough_line(image_edges)
hspace, angles, dists = hough_line_peaks(
hough_accumulator, angles, dists, threshold=150.0)
# Estimate camera transformation by minimizing the distance between
# calibration points
params = optimize_transform(camera_params, Pw_corners, Pi_corners)
if verbose >= 1:
print("Parameters: %s" % np.round(params, 3))
cam2world = transform_from(matrix_from_euler_xyz(params[:3]), params[3:6])
kappa = params[-1]
W2I = partial(world2image, cam2world=cam2world, kappa=kappa,
**camera_params)
# Get edge pixels in vicinity of lines
Pi_line_points = check_edge_is_on_line(image_edges, angles, dists)
if len(Pi_line_points) == 0:
if verbose >= 1:
print("No lines detected, assume that door is closed")
door_closed = True
else:
# Check how good the edges of the door projected to the image match
# detected edge pixels that correspond to lines
matchings = [check_line_is_edge(edge, Pi_line_points, cam2world, kappa,
camera_params) for edge in door_edges]
results["door_edges_in_image"] = [m[0] for m in matchings]
ratios = np.array([m[1] for m in matchings])
if verbose >= 1:
print(("Matching ratios: " + ", ".join(["%.2f"] * len(ratios)))
% tuple(100 * ratios))
door_closed = np.any(ratios > required_matching_ratio)
results["cam2world"] = cam2world
results["Pi_line_points"] = Pi_line_points
results["image_sobel"] = image_sobel
results["image_edges"] = image_edges
results["lines"] = (angles, dists)
return door_closed, W2I, results
示例14: test_hough_line_peaks_angle
def test_hough_line_peaks_angle():
img = np.zeros((100, 100), dtype=np.bool_)
img[:, 0] = True
img[0, :] = True
hspace, angles, dists = tf.hough_line(img)
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1
theta = np.linspace(0, np.pi, 100)
hspace, angles, dists = tf.hough_line(img, theta)
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1
theta = np.linspace(np.pi / 3, 4. / 3 * np.pi, 100)
hspace, angles, dists = tf.hough_line(img, theta)
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=45)[0]) == 2
assert len(tf.hough_line_peaks(hspace, angles, dists, min_angle=90)[0]) == 1
示例15: test_example
def test_example():
# Construct toydata
image = np.zeros((100, 100))
idx = np.arange(25, 75)
image[idx[::-1], idx] = 255
image[idx, idx] = 255
# Classic straight-line Hough transform
h, theta, d = hough_line(image)
# plot
plt.figure(figsize=(8, 4))
plt.subplot(131)
plt.imshow(image, cmap=plt.cm.gray)
plt.title('Input image')
plt.subplot(132)
plt.imshow(np.log(1 + h),
extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]),
d[-1], d[0]],
cmap=plt.cm.gray, aspect=1/1.5)
plt.title('Hough transform')
plt.xlabel('Angles (degrees)')
plt.ylabel('Distance (pixels)')
plt.subplot(133)
plt.imshow(image, cmap=plt.cm.gray)
rows, cols = image.shape
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
y1 = (dist - cols * np.cos(angle)) / np.sin(angle)
plt.plot((0, cols), (y0, y1), '-r')
plt.axis((0, cols, rows, 0))
plt.title('Detected lines')