Help us understand the problem. What is going on with this article?

画像にガウシアンノイズを加える with python2.7

More than 3 years have passed since last update.

【環境】

windows8.1
Anaconda(python2.7)
あらかじめopencv3をインストールしておく必要があります。

【概要】

指定したフォルダ内にある複数の画像データにランダムなガウシアンノイズを加えた画像データを作成して別の指定したフォルダに保存します。

フォルダ構成
|---gaussian
    |---before_images(ノイズを加える前の画像フォルダ)
    |---before_images(ノイズを加えた後の画像フォルダ)
    |---gaussian.py
gaussian.py
# -*- coding: utf-8 -*-

import cv2
import numpy as np
import sys
import os
import glob

# ガウシアンノイズ
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

# プログラムが存在するディレクトリの代入
current_dir = os.getcwd()
# 画像が存在するディレクトリの代入
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:
        # 画像の読み込み
        img = cv2.imread(image)

        # ノイズ付加
        after_image = addGaussianNoise(img)

        # 画像保存   
        cv2.imwrite(current_dir + '\\after_images\\' + str(i) + '.jpg', after_image) 
        i += 1

【参考URL】

https://github.com/bohemian916/deeplearning_tool/blob/master/increase_picture.py
opencv3のインストール

Nobu12
ユニークで奇抜な面白いアイディアのプログラミングをしたい!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした