コード例 #1
0
ファイル: m1_3.py プロジェクト: wuhu/mohbf
def main():
  # tryout
  image_list = listdir(IMAGE_PATH)
  im = import_pics(choice(image_list))
  patch = get_patch(im,16)
  patch = normalize(patch)
  patches = get_patches(10, im, 16)
  patches = normalize_set(patches)
コード例 #2
0
ファイル: 1.4.py プロジェクト: wuhu/mohbf
from os import listdir
from random import choice
import numpy as np
import pylab as mpl

from common import import_pics, show_image, IMAGE_PATH
from 1.3 import get_patch, normalize_set

# take 500 random images and slice out 16x16 patches
image_list = listdir(IMAGE_PATH)
patches = []
for i in range(500)
  im = import_pics(choice(image_list))
  patches.append(get_patch(im,16))
  patches = normalize_set(patches)

# generate white noise images
noises = []
for i in range(500)
  noises.append(np.random.normal(0, 15000, (16, 16)))
  normalize_set(noises)
  noises = normalize_set(noises)

# generate smoothed white noise images
fnoises = []
for i in range(500)
  noise = np.random.normal(0, 15000, (16, 16))
  n = 9
  fnoises.append(convolve2d(noise, np.ones((n, n)) / (n * n), mode="same", boundary="symm"))
  fnoises = normalize_set(fnoises)
コード例 #3
0
ファイル: 1.2.py プロジェクト: wuhu/mohbf
import numpy as np
import pylab as mpl
from scipy.signal import convolve2d

from common import import_pics, show_image

# 1.2
# import an image
im = import_pics("imk01765.tiff")

# a)
# add white noise using different variances
for i in (100, 1000, 5000, 10000, 30000):
    # generate white noise
    whiten = np.random.normal(0, i, (1020, 1532))
    # add the noise to the image
    imnoise = im + whiten
    # show image
    show_image(imnoise, "Noise added (sigma=%d)" % i)

# b)

# generate white noise
whiten = np.random.normal(0, 15000, (1020, 1532))
kernels = (3, 5, 9, 15, 29)
for n in kernels:
    # create smooth white noise by convolving white noise with a rectangular window
    tmp = convolve2d(whiten, np.ones((n, n)) / (n * n), mode="same", boundary="symm")
    show_image(im + tmp, "Noise kernel (%d,%d)" % (n, n))

# first manual approach (with 1-d vector)