windows8.1 Anaconda(python2.7) You need to have opencv3 installed in advance.
Creates image data with random Gaussian noise added to multiple image data in the specified folder and saves it in another specified folder.
Folder structure
|---gaussian
|---before_images(Image folder before adding noise)
|---before_images(Image folder after adding noise)
|---gaussian.py
gaussian.py
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import sys
import os
import glob
#Gaussian noise
def addGaussianNoise(src):
row,col,ch= src.shape
mean = 0
var = 0.1
sigma = 15
gauss = np.random.normal(mean,sigma,(row,col,ch))
gauss = gauss.reshape(row,col,ch)
noisy = src + gauss
return noisy
#Substitution of the directory where the program resides
current_dir = os.getcwd()
#Substitution of the directory where the image exists
before_images = glob.glob(current_dir + "\\before_images\\*")
i = 0
for image in before_images:
if image == current_dir + "\\before_images\\Thumbs.db":
continue
else:
#Loading images
img = cv2.imread(image)
#Add noise
after_image = addGaussianNoise(img)
#Save image
cv2.imwrite(current_dir + '\\after_images\\' + str(i) + '.jpg', after_image)
i += 1
https://github.com/bohemian916/deeplearning_tool/blob/master/increase_picture.py Install opencv3
Recommended Posts