Commit 413b80be authored by André Anjos's avatar André Anjos 💬

Merge branch 'utils' into 'master'

Utils for annotation creation

See merge request !17
parents a42fe58c 35292e11
Pipeline #5128 passed with stages
in 16 minutes and 42 seconds
include README.rst bootstrap-buildout.py buildout.cfg COPYING
recursive-include doc *.py *.rst
recursive-include bob/bio/vein/tests *.png *.mat
recursive-include bob/bio/vein/tests *.png *.mat *.txt *.npy
from .utils import ManualRoiCut
from .utils import ConstructVeinImage
from .utils import NormalizeImageRotation
# gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')]
This diff is collapsed.
26 0
27 7
29 24
31 38
40 80
45 104
50 124
58 156
61 171
65 187
67 194
69 205
71 223
74 251
76 274
79 298
81 324
83 341
83 358
86 385
87 408
89 445
90 474
91 518
91 534
91 559
90 581
90 620
90 633
88 648
89 655
89 672
277 672
279 648
280 606
284 552
284 482
280 413
280 358
281 309
286 277
288 238
288 195
285 165
285 138
285 111
288 49
291 20
294 0
11 91
8 322
76 320
114 307
140 300
176 292
225 292
269 288
330 287
405 288
436 290
456 288
468 276
473 242
472 208
470 184
466 146
455 116
440 93
424 77
397 69
358 64
298 60
247 52
201 38
160 25
130 7
106 7
81 16
46 46
22 71
......@@ -14,6 +14,7 @@ the generated sphinx documentation)
import os
import numpy
import numpy as np
import nose.tools
import pkg_resources
......@@ -186,3 +187,67 @@ def test_miura_match():
score_imp = MM.score(template_vein, probe_imp_vein)
assert numpy.isclose(score_imp, 0.172906739278421)
def test_manualRoiCut():
"""
Test ManualRoitCut
"""
from bob.bio.vein.preprocessor.utils import ManualRoiCut
image_path = F(('preprocessors', '0019_3_1_120509-160517.png'))
annotation_path = F(('preprocessors', '0019_3_1_120509-160517.txt'))
c = ManualRoiCut(annotation_path, image_path)
mask_1 = c.roi_mask()
image_1 = c.roi_image()
# create mask using size:
c = ManualRoiCut(annotation_path, sizes=(672,380))
mask_2 = c.roi_mask()
# loading image:
image = bob.io.base.load(image_path)
c = ManualRoiCut(annotation_path, image)
mask_3 = c.roi_mask()
image_3 = c.roi_image()
# load text file:
with open(annotation_path,'r') as f:
retval = numpy.loadtxt(f, ndmin=2)
# carefully -- this is BOB format --- (x,y)
annotation = list([tuple([k[0], k[1]]) for k in retval])
c = ManualRoiCut(annotation, image)
mask_4 = c.roi_mask()
image_4 = c.roi_image()
assert (mask_1 == mask_2).all()
assert (mask_1 == mask_3).all()
assert (mask_1 == mask_4).all()
assert (image_1 == image_3).all()
assert (image_1 == image_4).all()
def test_ConstructAnnotations():
"""
Test ConstructAnnotations preprocessor
"""
image_filename = F( ( 'preprocessors', 'ConstructAnnotations.png' ) )
roi_annotations_filename = F( ( 'preprocessors', 'ConstructAnnotations.txt' ) )
vein_annotations_filename = F( ( 'preprocessors', 'ConstructAnnotations.npy' ) )
image = bob.io.base.load( image_filename )
roi_annotations = np.loadtxt(roi_annotations_filename, dtype='uint16')
roi_annotations = [tuple([point[0], point[1]]) for point in roi_annotations]
fp = open(vein_annotations_filename, 'rb')
vein_annotations = np.load(fp)
vein_annotations = vein_annotations['arr_0'].tolist()
fp.close()
vein_annotations = [[tuple([point[0], point[1]]) for point in line] for line in vein_annotations]
annotation_dictionary = {"image" : image, "roi_annotations" : roi_annotations, "vein_annotations" : vein_annotations}
from bob.bio.vein.preprocessor.utils import ConstructVeinImage
from bob.bio.vein.preprocessor.utils import NormalizeImageRotation
output = ConstructVeinImage(annotation_dictionary, center = True)
output = NormalizeImageRotation(output, dark_lines = False)
assert np.array_equal(output, image)
......@@ -24,6 +24,11 @@ Pre-processors
.. automodule:: bob.bio.vein.preprocessor
Pre-processor utilities
-----------------------
.. automodule:: bob.bio.vein.preprocessor.utils
Feature Extractors
------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment