-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_Goulib_image.py
149 lines (119 loc) · 4.67 KB
/
test_Goulib_image.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# coding: utf8
from nose.tools import assert_equal
from nose import SkipTest
#lines above are inserted automatically by pythoscope. Line below overrides them
from Goulib.tests import *
from Goulib.image import *
import os
path=os.path.dirname(os.path.abspath(__file__))
try: # http://scikit-image.org/ is optional
import skimage
SKIMAGE=True
except:
SKIMAGE=False
class TestImage:
@classmethod
def setup_class(self):
self.lena=Image(path+'/data/lena.png')
self.lena.grayscale().save(path+'/results/lena_gray.png')
self.lena_gray=Image(path+'/results/lena_gray.png')
def test___init__(self):
lena2=Image(self.lena)
assert_equal(self.lena,lena2)
lena3=Image().open(path+'/data/lena.png')
assert_equal(self.lena,lena3)
#from matrix
a=[[(x-64)*y for x in range(128)] for y in range(128)]
a=Image(a)
def test___hash__(self):
h1=hash(self.lena)
h2=hash(self.lena_gray)
diff=h1^h2 #XOR
diff=math2.digsum(diff,2) #number of different pixels
assert_equal(h1,h2,msg='difference is %d pixels'%diff)
def test___getitem__(self):
pixel=self.lena_gray[256,256]
assert_equal(pixel,100)
pixel=self.lena[256,256]
assert_equal(pixel,(180,65,72))
face=self.lena[246:374,225:353]
face.save(path+"/results/image.lena.face.png")
face=face.grayscale()
eye=face[3:35,-35:-3] # negative indexes are handy in some cases
c=face.correlation(eye)
c.save(path+"/results/image.correlation.png")
def test___lt__(self):
# image = Image(data)
# assert_equal(expected, image.__lt__(other))
raise SkipTest
def test___repr__(self):
# image = Image(data)
# assert_equal(expected, image.__repr__())
raise SkipTest
def test_mode(self):
pass #useless ?
def test_open(self):
pass #tested above
def test_split(self):
# split the image into individual bands
source = self.lena.split()
def test_html(self):
h=self.lena.html()
assert_true(h)
def test_average_hash(self):
# image = Image(data, **kwargs)
# assert_equal(expected, image.average_hash(hash_size))
raise SkipTest # TODO: implement your test here
def test_base64(self):
# image = Image(data, **kwargs)
# assert_equal(expected, image.base64(fmt))
raise SkipTest # TODO: implement your test here
def test_dist(self):
# image = Image(data, **kwargs)
# assert_equal(expected, image.dist(other, hash_size))
raise SkipTest # TODO: implement your test here
def test_grayscale(self):
pass
def test_invert(self):
# image = Image(data, **kwargs)
# assert_equal(expected, image.invert())
raise SkipTest # TODO: implement your test here
def test_ndarray(self):
# image = Image(data, **kwargs)
# assert_equal(expected, image.ndarray())
raise SkipTest # TODO: implement your test here
def test_to_html(self):
pass
def test_filter(self):
if not SKIMAGE:
raise SkipTest
from skimage.filters import sobel
for f in [sobel]:
assert_true(self.lena.filter(f))
class TestCorrelation:
def test_correlation(self):
# assert_equal(expected, correlation(input, match))
raise SkipTest # TODO: implement your test here
class TestAlphaToColor:
def test_alpha_to_color(self):
# assert_equal(expected, alpha_to_color(image, color))
raise SkipTest # TODO: implement your test here
class TestAlphaComposite:
def test_alpha_composite(self):
# assert_equal(expected, alpha_composite(front, back))
raise SkipTest # TODO: implement your test here
class TestAlphaCompositeWithColor:
def test_alpha_composite_with_color(self):
# assert_equal(expected, alpha_composite_with_color(image, color))
raise SkipTest # TODO: implement your test here
class TestPurePilAlphaToColorV1:
def test_pure_pil_alpha_to_color_v1(self):
# assert_equal(expected, pure_pil_alpha_to_color_v1(image, color))
raise SkipTest # TODO: implement your test here
class TestPurePilAlphaToColorV2:
def test_pure_pil_alpha_to_color_v2(self):
# assert_equal(expected, pure_pil_alpha_to_color_v2(image, color))
raise SkipTest # TODO: implement your test here
if __name__=="__main__":
runmodule()