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


Python feature.canny方法代码示例

本文整理汇总了Python中skimage.feature.canny方法的典型用法代码示例。如果您正苦于以下问题:Python feature.canny方法的具体用法?Python feature.canny怎么用?Python feature.canny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.feature的用法示例。


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

示例1: _extract_lines

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _extract_lines(img, edges=None, mask=None, min_line_length=20, max_line_gap=3):
    global __i__
    __i__ += 1

    if edges is None:
        edges = canny(rgb2grey(img))
    if mask is not None:
        edges = edges & mask

    # figure()
    # subplot(131)
    # imshow(img)
    # subplot(132)
    #vimshow(edges)
    # subplot(133)
    # if mask is not None:
    #     imshow(mask, cmap=cm.gray)
    # savefig('/home/shared/Projects/Facades/src/data/for-labelme/debug/foo/{:06}.jpg'.format(__i__))

    lines = np.array(probabilistic_hough_line(edges, line_length=min_line_length, line_gap=max_line_gap))

    return lines 
开发者ID:jfemiani,项目名称:facade-segmentation,代码行数:24,代码来源:rectify.py

示例2: image2edge

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def image2edge(img, mode = None):
	'''_image2edge(img)

	convert image to edge map
	img: 2D_numpy_array 
	Return 2D_numpy_array '''
        if mode == 'canny':
                img = image_norm(img)
                edgeim = numpy.uint8(canny(img))*255
                return edgeim 
        if mode == 'sobel':
                img = image_norm(img)
                edgeim = sobel(img)*255
                return edgeim 
	img = numpy.float32(img)
	im1 = scipy.ndimage.filters.sobel(img,axis=0,mode='constant',cval =0.0)
	im2 = scipy.ndimage.filters.sobel(img,axis=1,mode='constant',cval =0.0)
	return (abs(im1) + abs(im2))/2 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:20,代码来源:imgOp.py

示例3: build_edge_dataset

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def build_edge_dataset(in_dir, out_dir, sigma=3):
    """Generate a dataset of (canny) edge-detected images.

    @param in_dir: string
                   input directory of images.
    @param out_dir: string
                    output directory of images.
    @param sigma: float (default: 3)
                  smoothness for edge detection.
    """
    image_paths = os.listdir(in_dir)
    n_images = len(image_paths)
    for i, image_path in enumerate(image_paths):
        print('Building edge-detected dataset: [%d/%d] images.' % (i + 1, n_images))
        image_full_path = os.path.join(in_dir, image_path)
        image = Image.open(image_full_path).convert('L')
        image_npy = np.asarray(image).astype(np.float) / 255.
        image_npy = feature.canny(image_npy, sigma=sigma)
        image_npy = image_npy.astype(np.uint8) * 255
        image = Image.fromarray(image_npy)
        image.save(os.path.join(out_dir, image_path)) 
开发者ID:mhw32,项目名称:multimodal-vae-public,代码行数:23,代码来源:setup.py

示例4: _phantom_center_calc

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _phantom_center_calc(self) -> Point:
        """Determine the phantom center.

        This is done by searching for circular ROIs of the canny image. Those that are circular and roughly the
        same size as the biggest circle ROI are all sampled for the center of the bounding box. The values are
        averaged over all the detected circles to give a more robust value.

        Returns
        -------
        center : Point
        """
        if self._phantom_center is not None:
            return self._phantom_center
        circles = [roi for roi in self._blobs if
                   np.isclose(self._regions[roi].major_axis_length, self.phantom_radius * 3.35, rtol=0.3)]

        # get average center of all circles
        circle_rois = [self._regions[roi] for roi in circles]
        y = np.mean([bbox_center(roi).y for roi in circle_rois])
        x = np.mean([bbox_center(roi).x for roi in circle_rois])
        return Point(x, y) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:23,代码来源:planar_imaging.py

示例5: _phantom_angle_calc

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _phantom_angle_calc(self) -> float:
        """Determine the angle of the phantom.

        This is done by searching for square-like boxes of the canny image. There are usually two: one lead and
        one copper. The box with the highest intensity (lead) is identified. The angle from the center of the lead
        square bounding box and the phantom center determines the phantom angle.

        Returns
        -------
        angle : float
            The angle in radians.
        """
        circle = CollapsedCircleProfile(self.phantom_center, self.phantom_radius * 0.79, self.image,
                                        width_ratio=0.04, ccw=True)
        circle.ground()
        circle.filter(size=0.01)
        peak_idx = circle.find_fwxm_peaks(threshold=0.6, max_number=1)[0]
        shift_percent = peak_idx / len(circle.values)
        shift_radians = shift_percent * 2 * np.pi
        shift_radians_corrected = 2*np.pi - shift_radians
        return np.degrees(shift_radians_corrected) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:23,代码来源:planar_imaging.py

示例6: _phantom_radius_calc

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _phantom_radius_calc(self) -> float:
        """Determine the radius of the phantom.

        The radius is determined by finding the largest of the detected blobs of the canny image and taking
        its major axis length.

        Returns
        -------
        radius : float
            The radius of the phantom in pixels. The actual value is not important; it is used for scaling the
            distances to the low and high contrast ROIs.
        """
        big_circle_idx = np.argsort([self._regions[roi].major_axis_length for roi in self._blobs])[-1]
        circle_roi = self._regions[self._blobs[big_circle_idx]]
        radius = circle_roi.major_axis_length / 3.35
        return radius 
开发者ID:jrkerns,项目名称:pylinac,代码行数:18,代码来源:planar_imaging.py

示例7: compute

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def compute(image):
    # type: (numpy.ndarray) -> float
    """Compute the sharpness metric for the given data."""

    # convert the image to double for further processing
    image = image.astype(np.float64)

    # edge detection using canny and sobel canny edge detection is done to
    # classify the blocks as edge or non-edge blocks and sobel edge
    # detection is done for the purpose of edge width measurement.
    from skimage.feature import canny
    canny_edges = canny(image)
    sobel_edges = sobel(image)

    # edge width calculation
    marziliano_widths = marziliano_method(sobel_edges, image)

    # sharpness metric calculation
    return _calculate_sharpness_metric(image, canny_edges, marziliano_widths) 
开发者ID:iperov,项目名称:DeepFaceLab,代码行数:21,代码来源:estimate_sharpness.py

示例8: filter

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def filter(self, filt, **kwargs):
        """Filter the image

        Parameters
        ----------
        filt : str
            Image filter. Additional parameters can be passed as keyword
            arguments. The following filters are supported:

            *  'sobel': Edge filter the image using the `Sobel filter
               <https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.sobel>`_.
            *  'scharr': Edge filter the image using the `Scarr filter
               <https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.scharr>`_.
            *  'canny': Edge filter the image using the `Canny algorithm
               <https://scikit-image.org/docs/stable/api/skimage.feature.html#skimage.feature.canny>`_.
               You can also specify ``sigma``, ``low_threshold``,
               ``high_threshold``, ``mask``, and ``use_quantiles``.
            *  'median': Return local median of the image.
        **kwargs :
            Additional parameters passed to the filter

        Returns
        -------
        stim : `ImageStimulus`
            A copy of the stimulus object with the filtered image
        """
        if not isinstance(filt, str):
            raise TypeError("'filt' must be a string, not %s." % type(filt))
        img = self.data.reshape(self.img_shape)
        if filt.lower() == 'sobel':
            img = sobel(img, **kwargs)
        elif filt.lower() == 'scharr':
            img = scharr(img, **kwargs)
        elif filt.lower() == 'canny':
            img = canny(img, **kwargs)
        elif filt.lower() == 'median':
            img = median(img, **kwargs)
        else:
            raise ValueError("Unknown filter '%s'." % filt)
        return ImageStimulus(img, electrodes=self.electrodes,
                             metadata=self.metadata) 
开发者ID:pulse2percept,项目名称:pulse2percept,代码行数:43,代码来源:images.py

示例9: get_edges

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def get_edges(self, detector='sobel'):
        if detector == 'sobel':
            img = filters.sobel(self.img_gray)
        elif detector == 'canny1':
            img = feature.canny(self.img_gray, sigma=1)
        elif detector == 'canny3':
            img = feature.canny(self.img_gray, sigma=3)
        elif detector == 'scharr':
            img = filters.scharr(self.img_gray)
        elif detector == 'prewitt':
            img = filters.prewitt(self.img_gray)
        elif detector == 'roberts':
            img = filters.roberts(self.img_gray)
        return img 
开发者ID:OnionDoctor,项目名称:FCN_for_crack_recognition,代码行数:16,代码来源:FCN_CrackAnalysis.py

示例10: plot

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def plot(data, xi=None, cmap='RdBu_r', axis=plt, percentile=100, dilation=3.0, alpha=0.8):
    dx, dy = 0.05, 0.05
    xx = np.arange(0.0, data.shape[1], dx)
    yy = np.arange(0.0, data.shape[0], dy)
    xmin, xmax, ymin, ymax = np.amin(xx), np.amax(xx), np.amin(yy), np.amax(yy)
    extent = xmin, xmax, ymin, ymax
    cmap_xi = plt.get_cmap('Greys_r')
    cmap_xi.set_bad(alpha=0)
    overlay = None
    if xi is not None:
        # Compute edges (to overlay to heatmaps later)
        xi_greyscale = xi if len(xi.shape) == 2 else np.mean(xi, axis=-1)
        in_image_upscaled = transform.rescale(xi_greyscale, dilation, mode='constant')
        edges = feature.canny(in_image_upscaled).astype(float)
        edges[edges < 0.5] = np.nan
        edges[:5, :] = np.nan
        edges[-5:, :] = np.nan
        edges[:, :5] = np.nan
        edges[:, -5:] = np.nan
        overlay = edges

    abs_max = np.percentile(np.abs(data), percentile)
    abs_min = abs_max

    if len(data.shape) == 3:
        data = np.mean(data, 2)
    axis.imshow(data, extent=extent, interpolation='none', cmap=cmap, vmin=-abs_min, vmax=abs_max)
    if overlay is not None:
        axis.imshow(overlay, extent=extent, interpolation='none', cmap=cmap_xi, alpha=alpha)
    axis.axis('off')
    return axis 
开发者ID:marcoancona,项目名称:DeepExplain,代码行数:33,代码来源:utils.py

示例11: canny_edge

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def canny_edge(img, sigma=1):
    """
    args:
        img : 2D or 3D array
    return:
        edge: outline of image
    """
    if len(img.shape) == 3:
        img = rgb2gray(img)
    edge_bool = feature.canny(img, sigma)
    edge_img = np.zeros((edge_bool.shape), np.uint8)
    edge_img[edge_bool] = 255
    return edge_img 
开发者ID:huster-wgm,项目名称:geoseg,代码行数:15,代码来源:vision.py

示例12: _get_canny_regions

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _get_canny_regions(self, sigma=2, percentiles=(0.001, 0.01)):
        """Compute the canny edges of the image and return the connected regions found."""
        # copy, filter, and ground the image
        img_copy = copy.copy(self.image)
        img_copy.filter(kind='gaussian', size=sigma)
        img_copy.ground()

        # compute the canny edges with very low thresholds (detects nearly everything)
        lo_th, hi_th = np.percentile(img_copy, percentiles)
        c = feature.canny(img_copy, low_threshold=lo_th, high_threshold=hi_th)

        # label the canny edge regions
        labeled = measure.label(c)
        regions = measure.regionprops(labeled, intensity_image=img_copy)
        return regions 
开发者ID:jrkerns,项目名称:pylinac,代码行数:17,代码来源:planar_imaging.py

示例13: _regions

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def _regions(self):
        """All the regions of the canny image that were labeled."""
        return self._get_canny_regions() 
开发者ID:jrkerns,项目名称:pylinac,代码行数:5,代码来源:planar_imaging.py

示例14: filter

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def filter(self, array, *args, **kwargs):
        array[np.isnan(array)] = 0.0
        array = feature.canny(array, sigma=self.sigma)
        return array 
开发者ID:birgander2,项目名称:PyRAT,代码行数:6,代码来源:Canny.py

示例15: canny

# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import canny [as 别名]
def canny(*args, **kwargs):
    return Canny(*args, **kwargs).run(**kwargs) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:4,代码来源:Canny.py


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