本文整理汇总了Python中cv2.getGaussianKernel方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.getGaussianKernel方法的具体用法?Python cv2.getGaussianKernel怎么用?Python cv2.getGaussianKernel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.getGaussianKernel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_edge_smooth
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def make_edge_smooth(dataset_name, img_size) :
check_folder('./dataset/{}/{}'.format(dataset_name, 'trainB_smooth'))
file_list = glob('./dataset/{}/{}/*.*'.format(dataset_name, 'trainB'))
save_dir = './dataset/{}/trainB_smooth'.format(dataset_name)
kernel_size = 5
kernel = np.ones((kernel_size, kernel_size), np.uint8)
gauss = cv2.getGaussianKernel(kernel_size, 0)
gauss = gauss * gauss.transpose(1, 0)
for f in tqdm(file_list) :
file_name = os.path.basename(f)
bgr_img = cv2.imread(f)
gray_img = cv2.imread(f, 0)
bgr_img = cv2.resize(bgr_img, (img_size, img_size))
pad_img = np.pad(bgr_img, ((2, 2), (2, 2), (0, 0)), mode='reflect')
gray_img = cv2.resize(gray_img, (img_size, img_size))
edges = cv2.Canny(gray_img, 100, 200)
dilation = cv2.dilate(edges, kernel)
gauss_img = np.copy(bgr_img)
idx = np.where(dilation != 0)
for i in range(np.sum(dilation != 0)):
gauss_img[idx[0][i], idx[1][i], 0] = np.sum(
np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 0], gauss))
gauss_img[idx[0][i], idx[1][i], 1] = np.sum(
np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 1], gauss))
gauss_img[idx[0][i], idx[1][i], 2] = np.sum(
np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 2], gauss))
cv2.imwrite(os.path.join(save_dir, file_name), gauss_img)
示例2: ssim
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def ssim(img1, img2):
C1 = (0.01 * 255)**2
C2 = (0.03 * 255)**2
img1 = img1.astype(np.float64)
img2 = img2.astype(np.float64)
kernel = cv2.getGaussianKernel(11, 1.5)
window = np.outer(kernel, kernel.transpose())
mu1 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5] # valid
mu2 = cv2.filter2D(img2, -1, window)[5:-5, 5:-5]
mu1_sq = mu1**2
mu2_sq = mu2**2
mu1_mu2 = mu1 * mu2
sigma1_sq = cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq
sigma2_sq = cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq
sigma12 = cv2.filter2D(img1 * img2, -1, window)[5:-5, 5:-5] - mu1_mu2
ssim_map = ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) / ((mu1_sq + mu2_sq + C1) *
(sigma1_sq + sigma2_sq + C2))
return ssim_map.mean()
示例3: ssim
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def ssim(img1, img2):
C1 = (0.01 * 255)**2
C2 = (0.03 * 255)**2
img1 = img1.astype(np.float64)
img2 = img2.astype(np.float64)
kernel = cv2.getGaussianKernel(11, 1.5)
window = np.outer(kernel, kernel.transpose())
mu1 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5] # valid
mu2 = cv2.filter2D(img2, -1, window)[5:-5, 5:-5]
mu1_sq = mu1**2
mu2_sq = mu2**2
mu1_mu2 = mu1 * mu2
sigma1_sq = cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq
sigma2_sq = cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq
sigma12 = cv2.filter2D(img1 * img2, -1, window)[5:-5, 5:-5] - mu1_mu2
ssim_map = ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) / ((mu1_sq + mu2_sq + C1) *
(sigma1_sq + sigma2_sq + C2))
return ssim_map.mean()
示例4: _ssim
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def _ssim(img1, img2):
C1 = (0.01 * 255) ** 2
C2 = (0.03 * 255) ** 2
img1 = img1.astype(np.float64)
img2 = img2.astype(np.float64)
kernel = cv2.getGaussianKernel(11, 1.5)
window = np.outer(kernel, kernel.transpose())
mu1 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5] # valid
mu2 = cv2.filter2D(img2, -1, window)[5:-5, 5:-5]
mu1_sq = mu1 ** 2
mu2_sq = mu2 ** 2
mu1_mu2 = mu1 * mu2
sigma1_sq = cv2.filter2D(img1 ** 2, -1, window)[5:-5, 5:-5] - mu1_sq
sigma2_sq = cv2.filter2D(img2 ** 2, -1, window)[5:-5, 5:-5] - mu2_sq
sigma12 = cv2.filter2D(img1 * img2, -1, window)[5:-5, 5:-5] - mu1_mu2
ssim_map = ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) / (
(mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2)
)
return ssim_map.mean()
示例5: downsample
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def downsample(image, coordinates, **config):
with tf.name_scope('gaussian_blur'):
k_size = config['blur_size']
kernel = cv.getGaussianKernel(k_size, 0)[:, 0]
kernel = np.outer(kernel, kernel).astype(np.float32)
kernel = tf.reshape(tf.convert_to_tensor(kernel), [k_size]*2+[1, 1])
pad_size = int(k_size/2)
image = tf.pad(image, [[pad_size]*2, [pad_size]*2, [0, 0]], 'REFLECT')
image = tf.expand_dims(image, axis=0) # add batch dim
image = tf.nn.depthwise_conv2d(image, kernel, [1, 1, 1, 1], 'VALID')[0]
with tf.name_scope('downsample'):
ratio = tf.divide(tf.convert_to_tensor(config['resize']), tf.shape(image)[0:2])
coordinates = coordinates * tf.cast(ratio, tf.float32)
image = tf.image.resize_images(image, config['resize'],
method=tf.image.ResizeMethod.BILINEAR)
return image, coordinates
示例6: make_edge_smooth
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def make_edge_smooth(path):
file_list = glob(os.path.expanduser(os.path.join(path, 'trainB', '*')))
save_dir = os.path.expanduser(os.path.join(path, 'trainB_smooth'))
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
kernel_size = 5
kernel = np.ones((kernel_size, kernel_size), np.uint8)
gauss = cv2.getGaussianKernel(kernel_size, 0)
gauss = gauss * gauss.transpose(1, 0)
for f in tqdm(file_list):
file_name = os.path.basename(f)
bgr_img = cv2.imread(f)
gray_img = cv2.imread(f, 0)
pad_img = np.pad(bgr_img, ((2, 2), (2, 2), (0, 0)), mode='reflect')
edges = cv2.Canny(gray_img, 100, 200)
dilation = cv2.dilate(edges, kernel)
gauss_img = np.copy(bgr_img)
idx = np.where(dilation != 0)
for i in range(np.sum(dilation != 0)):
gauss_img[idx[0][i], idx[1][i], 0] = np.sum(np.multiply(
pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 0],
gauss))
gauss_img[idx[0][i], idx[1][i], 1] = np.sum(np.multiply(
pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 1],
gauss))
gauss_img[idx[0][i], idx[1][i], 2] = np.sum(np.multiply(
pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 2],
gauss))
cv2.imwrite(os.path.join(save_dir, file_name), gauss_img)
示例7: edge_promoting
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def edge_promoting(root, save):
file_list = os.listdir(root)
if not os.path.isdir(save):
os.makedirs(save)
kernel_size = 5
kernel = np.ones((kernel_size, kernel_size), np.uint8)
gauss = cv2.getGaussianKernel(kernel_size, 0)
gauss = gauss * gauss.transpose(1, 0)
n = 1
for f in tqdm(file_list):
rgb_img = cv2.imread(os.path.join(root, f))
gray_img = cv2.imread(os.path.join(root, f), 0)
rgb_img = cv2.resize(rgb_img, (256, 256))
pad_img = np.pad(rgb_img, ((2,2), (2,2), (0,0)), mode='reflect')
gray_img = cv2.resize(gray_img, (256, 256))
edges = cv2.Canny(gray_img, 100, 200)
dilation = cv2.dilate(edges, kernel)
gauss_img = np.copy(rgb_img)
idx = np.where(dilation != 0)
for i in range(np.sum(dilation != 0)):
gauss_img[idx[0][i], idx[1][i], 0] = np.sum(np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 0], gauss))
gauss_img[idx[0][i], idx[1][i], 1] = np.sum(np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 1], gauss))
gauss_img[idx[0][i], idx[1][i], 2] = np.sum(np.multiply(pad_img[idx[0][i]:idx[0][i] + kernel_size, idx[1][i]:idx[1][i] + kernel_size, 2], gauss))
result = np.concatenate((rgb_img, gauss_img), 1)
cv2.imwrite(os.path.join(save, str(n) + '.png'), result)
n += 1
示例8: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getGaussianKernel [as 别名]
def __init__(self, kernel_size=5):
super(GaussianSmoother, self).__init__()
self.sigma = 0.3*((kernel_size-1)*0.5-1)+0.8
kernel = cv2.getGaussianKernel(kernel_size, -1)
kernel2d = np.dot(kernel.reshape(kernel_size,1),kernel.reshape(1,kernel_size))
data = torch.Tensor(1, 1, kernel_size, kernel_size)
self.pad = (kernel_size-1)/2
for i in range(0,1):
data[i,0,:,:] = torch.from_numpy(kernel2d)
self.blur_kernel = Variable(data, requires_grad=False)