本文整理汇总了Python中cv2.randn方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.randn方法的具体用法?Python cv2.randn怎么用?Python cv2.randn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.randn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: augment_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def augment_image(rgbImg):
augmented_images = []
# original image
augmented_images.append(rgbImg)
# fliped x-axis
rimg = rgbImg.copy()
cv2.flip(rimg, 1, rimg)
augmented_images.append(rimg)
# add gaussian noise
for _ in range(10):
gaussian_noise = rgbImg.copy()
cv2.randn(gaussian_noise, 0, 150)
augmented_images.append(rgbImg + gaussian_noise)
augmented_images.append(rimg + gaussian_noise)
for _ in range(10):
uniform_noise = rgbImg.copy()
cv2.randu(uniform_noise, 0, 1)
augmented_images.append(rgbImg + uniform_noise)
augmented_images.append(rimg + uniform_noise)
return augmented_images
示例2: read
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def read(self, dst=None):
w, h = self.frame_size
if self.bg is None:
buf = np.zeros((h, w, 3), np.uint8)
else:
buf = self.bg.copy()
self.render(buf)
if self.noise > 0.0:
noise = np.zeros((h, w, 3), np.int8)
cv2.randn(noise, np.zeros(3), np.ones(3)*255*self.noise)
buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)
return True, buf
示例3: read
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def read(self, dst=None):
w, h = self.frame_size
if self.bg is None:
buf = np.zeros((h, w, 3), np.uint8)
else:
buf = self.bg.copy()
self.render(buf)
if self.noise > 0.0:
noise = np.zeros((h, w, 3), np.int8)
cv2.randn(noise, np.zeros(3), np.ones(3) * 255 * self.noise)
buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)
return True, buf
示例4: add_gauss_noise
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def add_gauss_noise(img,bits):
"""
Add random gaussian noise to image
:param img: input image
:param bits: number of bits to represent a single color value
:returns: image with noise
"""
MAX = get_max(bits)
noise = img.copy()
cv2.randn(noise, 0, MAX//2)
return img + noise
示例5: gaussian_noise
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def gaussian_noise(images, mean, std):
"""
Applies gaussian noise to every image in the list "images" with the desired
Returns a list with all the original and noisy images.
"""
# if we only have 1 image, transform into a list to work with same script
if type(images) is not list:
images = [images]
# container for sheared images
noisy_images = []
# get every image and apply the number of desired shears
for img in images:
# get rows and cols apply noise to
rows, cols, depth = img.shape
# append original image
noisy_images.append(img)
# fill in the per-channel mean and std
m = np.full((1, depth), mean)
s = np.full((1, depth), std)
# add noise to image
# noisy_img = img.copy()
noisy_img = np.zeros((rows, cols, depth), dtype=np.uint8)
noisy_img = cv2.randn(noisy_img, m, s)
noisy_img = img + noisy_img
# append noisy image to container
noisy_images.append(noisy_img)
return noisy_images
示例6: apply_gauss_noise
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def apply_gauss_noise(self, img):
"""
Gaussian-distributed additive noise.
"""
mean = 0
stddev = np.sqrt(15)
gauss_noise = np.zeros(img.shape)
cv2.randn(gauss_noise, mean, stddev)
out = img + gauss_noise
return out
示例7: read
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def read(self, dst=None):
w, h = self.frame_size
if self.bg is None:
buf = np.zeros((h, w, 3), np.uint8)
else:
buf = self.bg.copy()
self.render(buf)
if self.noise > 0.0:
noise = np.zeros((h, w, 3), np.int8)
cv.randn(noise, np.zeros(3), np.ones(3)*255*self.noise)
buf = cv.add(buf, noise, dtype=cv.CV_8UC3)
return True, buf
示例8: gaussian_noise
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import randn [as 别名]
def gaussian_noise(height, width):
"""
Create a background with Gaussian noise (to mimic paper)
"""
# We create an all white image
image = np.ones((height, width)) * 255
# We add gaussian noise
cv2.randn(image, 235, 10)
return Image.fromarray(image).convert("RGBA")