本文整理汇总了Python中cv2.Scharr方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.Scharr方法的具体用法?Python cv2.Scharr怎么用?Python cv2.Scharr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.Scharr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_gradient
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def compute_gradient(img, use_scharr=True):
if use_scharr:
norm_factor = 32
gradx = cv2.Scharr(img, cv2.CV_32F, 1, 0, scale=1.0/norm_factor)
grady = cv2.Scharr(img, cv2.CV_32F, 0, 1, scale=1.0/norm_factor)
else:
kx = cv2.getDerivKernels(1, 0, ksize=1, normalize=True)
ky = cv2.getDerivKernels(0, 1, ksize=1, normalize=True)
gradx = cv2.sepFilter2D(img, cv2.CV_32F, kx[0], kx[1])
grady = cv2.sepFilter2D(img, cv2.CV_32F, ky[0], ky[1])
gradient = np.dstack([gradx, grady])
return gradient
示例2: from_gradient
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def from_gradient(gray):
fieldx = cv2.Scharr(gray, cv2.CV_32F, 1, 0) / 15.36
fieldy = cv2.Scharr(gray, cv2.CV_32F, 0, 1) / 15.36
return VectorField(fieldx, fieldy)
示例3: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def main():
image = cv2.imread("../data/5.1.11.tiff", 0)
cv2.imshow("Orignal Image", image)
# Laplacian High Pass Filter
lap_filter = cv2.Laplacian(image, ddepth=-1, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Laplacian Filter", lap_filter)
# Sobel High Pass Filter
sobelx_filter = cv2.Sobel(image, ddepth=-1, dx=2, dy=0, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Sobel X Filter", sobelx_filter)
sobely_filter = cv2.Sobel(image, ddepth=-1, dx=0, dy=2, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Sobel Y Filter", sobely_filter)
sobel_filter = sobelx_filter + sobely_filter
cv2.imshow("Sobel Filter", sobel_filter)
# Scharr High Pass Filter Implementation
scharrx_filter = cv2.Scharr(image, ddepth=-1, dx=1, dy=0, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Scharr X Filter", scharrx_filter)
scharry_filter = cv2.Scharr(image, ddepth=-1, dx=0, dy=1, scale=1, borderType=cv2.BORDER_DEFAULT)
cv2.imshow("Scharr Y Filter", scharry_filter)
scharr_filter = scharrx_filter + scharry_filter
cv2.imshow("Scharr Filter", scharr_filter)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例4: scharr_filter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def scharr_filter(img, dx, dy, scale):
"""This is a filtering method used to identify and highlight gradient edges/features using the 1st derivative.
Typically used to identify gradients along the x-axis (dx = 1, dy = 0) and y-axis (dx = 0, dy = 1) independently.
Performance is quite similar to Sobel filter. Used to detect edges / changes in pixel intensity. ddepth = -1
specifies that the dimensions of output image will be the same as the input image.
Inputs:
gray_img = Grayscale image data
dx = derivative of x to analyze (1-3)
dy = derivative of x to analyze (1-3)
scale = scaling factor applied (multiplied) to computed Scharr values (scale = 1 is unscaled)
Returns:
sr_img = Scharr filtered image
:param img: numpy.ndarray
:param dx: int
:param dy: int
:param scale: int
:return sr_img: numpy.ndarray
"""
sr_img = cv2.Scharr(src=img, ddepth=-1, dx=dx, dy=dy, scale=scale)
params.device += 1
if params.debug == 'print':
name = os.path.join(params.debug_outdir, str(params.device))
name += '_sr_img_dx' + str(dx) + '_dy' + str(dy) + '_scale' + str(scale) + '.png'
print_image(sr_img, name)
elif params.debug == 'plot':
plot_image(sr_img, cmap='gray')
return sr_img