當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。