本文整理匯總了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