-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_zca.py
53 lines (45 loc) · 1.17 KB
/
test_zca.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
49
50
51
52
53
"""
Testing and checking ZCA whitening preprocessing
"""
import time
import pylab
import cv2
from preprocessing.transform_in import zca_whiten
img_path = './data/iccv09Data/images/0002136.jpg'
img = cv2.imread(img_path, cv2.CV_LOAD_IMAGE_COLOR)
# img = cv2.imread(img_path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
if img is None:
print "cant load image"
exit(1)
img = img.astype('float32')
# print img
print "Img shape", img.shape, img.dtype
pylab.gray()
pylab.subplot(2, 3, 1)
pylab.axis('off')
pylab.imshow(img[:, :, 0])
pylab.subplot(2, 3, 2)
pylab.axis('off')
pylab.imshow(img[:, :, 1])
pylab.subplot(2, 3, 3)
pylab.axis('off')
pylab.imshow(img[:, :, 2])
orig_shape = img.shape
start = time.clock()
white_img = zca_whiten(img.reshape((-1, 3)))
stop = time.clock()
white_img = white_img.reshape(orig_shape)
print "Time", stop-start, "sec"
print "new image shape", white_img.shape
print "new image dtype", white_img.dtype
# print white_img[100:140, 100:140]
pylab.subplot(2, 3, 4)
pylab.axis('off')
pylab.imshow(white_img[:, :, 0])
pylab.subplot(2, 3, 5)
pylab.axis('off')
pylab.imshow(white_img[:, :, 1])
pylab.subplot(2, 3, 6)
pylab.axis('off')
pylab.imshow(white_img[:, :, 2])
pylab.show()