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