-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_objects.py
More file actions
57 lines (47 loc) · 2.29 KB
/
Copy pathtest_objects.py
File metadata and controls
57 lines (47 loc) · 2.29 KB
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
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy import misc
from skimage.util import view_as_windows, view_as_blocks
from Block import Block
from Histogram import Histogram
from Cell import Cell
test_holes_image = np.array([[0,0,0,0,0,0,1,0,0,0],
[0,1,1,1,1,1,0,0,0,0],
[0,1,1,1,1,1,0,0,0,0],
[0,1,1,1,1,1,0,0,0,0],
[0,1,1,1,1,1,0,0,0,0],
[0,0,0,0,0,0,0,2,2,2],
[0,0,0,0,0,0,0,2,0,2],
[0,0,0,0,0,0,0,2,2,2]])
def test_gradient_image():
h = Hog(test_holes_image, 16, 16, 0.5, 8, 8)
gx, gy = h._create_gradient_images(h._inputImage)
expected_gx = np.array([[0,0,0,0,0, 1, 0,-1,0, 0],
[1,1,0,0,0,-1,-1, 0,0, 0],
[1,1,0,0,0,-1,-1, 0,0, 0],
[1,1,0,0,0,-1,-1, 0,0, 0],
[1,1,0,0,0,-1,-1, 0,0, 0],
[0,0,0,0,0, 0, 2, 2,0,-2],
[0,0,0,0,0, 0, 2, 0,0, 0],
[0,0,0,0,0, 0, 2, 2,0,-2]])
expected_gy = np.array([[0, 1, 1, 1, 1, 1, 0, 0,0, 0],
[0, 1, 1, 1, 1, 1,-1, 0,0, 0],
[0, 0, 0, 0, 0, 0, 0, 0,0, 0],
[0, 0, 0, 0, 0, 0, 0, 0,0, 0],
[0,-1,-1,-1,-1,-1, 0, 2,2, 2],
[0,-1,-1,-1,-1,-1, 0, 2,0, 2],
[0, 0, 0, 0, 0, 0, 0, 0,0, 0],
[0, 0, 0, 0, 0, 0, 0,-2,0,-2]])
expected_grad = np.arctan2(expected_gy, expected_gx)
np.testing.assert_almost_equal(h.grad, expected_grad)
def testHog():
"""Tests our version of Hog with skimage's version"""
split = np.array([[1, 1, 5, 5, 9, 9,13,13,17,17,21,21],
[1, 1, 5, 5, 9, 9,13,13,17,17,21,21],
[2, 2, 6, 6,10,10,14,14,18,18,22,22],
[2, 2, 6, 6,10,10,14,14,18,18,22,22],
[3, 3, 7, 7,11,11,15,15,19,19,23,23],
[3, 3, 7, 7,11,11,15,15,19,19,23,23],
[4, 4, 8, 8,12,12,16,16,20,20,24,24],
[4, 4, 8, 8,12,12,16,16,20,20,24,24]])