-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest1.py
48 lines (40 loc) · 1.42 KB
/
test1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 8 21:26:41 2014
@author: pi19404
"""
import pylab
from PIL import Image
import scipy.signal
import numpy as np
import matplotlib.pyplot as plt
import numpy
rng = numpy.random.RandomState(23455)
im = Image.open(open('/home/pi19404/repository/pyVision/data/t1.jpg'))
#im /= 255. # normalise to 0-1, it's easier to work in float space
im = numpy.asarray(im, dtype='float64') / 256.
# make some kind of kernel, there are many ways to do this...
w_shp = (9, 9,3)
w_bound = numpy.sqrt(3 * 9 * 9)
kernel=numpy.asarray(rng.uniform(low=-1.0 / w_bound,high=1.0 / w_bound,size=w_shp),dtype=im.dtype)
#kernel = t.reshape(21, 1) * t.reshape(1, 21
#kernel = np.asarray(rng.uniform(-0.1,0.1,size=(21,21)),dtype='float64')
#kernel /= kernel.sum() # kernel should sum to 1! :)
# convolve 2d the kernel with each channel
r = scipy.signal.convolve2d(im[:,:,0], kernel[:,:,0], mode='same')
g = scipy.signal.convolve2d(im[:,:,1], kernel[:,:,1], mode='same')
b = scipy.signal.convolve2d(im[:,:,2], kernel[:,:,2], mode='same')
# stack the channels back into a 8-bit colour depth image and plot it
im_out = np.dstack([r, g, b])
#im_out = (im_out ).astype(np.uint8)
scipy.nd
img2 = scipy.ndimage.convolve(im, kernel, mode='constant', cval=0.0)
pylab.subplot(1,3,1)
pylab.imshow(im)
pylab.gray();
pylab.subplot(1,3,2)
pylab.imshow(im_out[:,:,0])
pylab.subplot(1,3,3)
pylab.imshow(im_out[:,:,1])
pylab.gray();
pylab.show()