我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用skimage.transform.hough_circle()。
def test_image_transformation(): s = XSeries([generate_image(False) for _ in range(100)]) try: image_transformer = ImageTransformer().fit() assert False except: assert True image_transformer = ImageTransformer(skimage_transform.hough_circle, radius=5).fit() s_transformed = image_transformer.transform(s) assert s_transformed.data_type == np.ndarray image_transformer = ImageTransformer(skimage_transform.resize, output_shape=(10, 10)).fit() s_transformed = image_transformer.transform(s) assert s_transformed.data_type == np.ndarray
def find_circles(edges_img, min_radius, max_radius): """ Finds circles using the Hough transformation For each radius a Hough transformation matrix is calculated and retured """ hough_radii = numpy.arange(min_radius, max_radius, 1) hough_res = hough_circle(edges_img, hough_radii) return (hough_radii, hough_res)
def process(self, im): (width, height, _) = im.image.shape img_adapted = im.prep(self.transform) if width > self.max_resized or height > self.max_resized: scale_height = self.max_resized / height scale_width = self.max_resized / width scale = min(scale_height, scale_width) img_adapted = resize(img_adapted, (int(width * scale), int(height * scale))) edges = canny(img_adapted, sigma=self.sigma) # Detect two radii # Calculate image diameter shape = im.image.shape diam = math.sqrt(shape[0] ** 2 + shape[1] ** 2) radii = np.arange(diam / 3, diam * 0.8, 2) hough_res = hough_circle(edges, radii) accums = [] for radius, h in zip(radii, hough_res): # For each radius, extract two circles peaks = peak_local_max(h, num_peaks=1, min_distance=1) if len(peaks) > 0: accums.extend(h[peaks[:, 0], peaks[:, 1]]) if len(accums) == 0: # TODO: fix, should not happen return [0] idx = np.argmax(accums) return [accums[idx]]