From c9a94c90aeccb5247c685fd202e1be8416cfba0d Mon Sep 17 00:00:00 2001 From: Andre Anjos Date: Fri, 30 Jun 2017 16:22:46 +0200 Subject: [PATCH] Speeds-up the evaluation of vein probabilities --- bob/bio/vein/extractor/MaximumCurvature.py | 30 +++++++++++----------- bob/bio/vein/tests/test.py | 3 +-- matlab/compare.py | 6 +---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/bob/bio/vein/extractor/MaximumCurvature.py b/bob/bio/vein/extractor/MaximumCurvature.py index 8453b6b..d41d320 100644 --- a/bob/bio/vein/extractor/MaximumCurvature.py +++ b/bob/bio/vein/extractor/MaximumCurvature.py @@ -217,7 +217,7 @@ class MaximumCurvature (Extractor): ''' - V = numpy.zeros_like(k) + V = numpy.zeros(k.shape[:2], dtype='float64') def _prob_1d(a): '''Finds "vein probabilities" in a 1-D signal @@ -289,17 +289,17 @@ class MaximumCurvature (Extractor): # Horizontal direction for index in range(k.shape[0]): - V[index,:,0] += _prob_1d(k[index,:,0]) + V[index,:] += _prob_1d(k[index,:,0]) # Vertical direction for index in range(k.shape[1]): - V[:,index,1] += _prob_1d(k[:,index,1]) + V[:,index] += _prob_1d(k[:,index,1]) # Direction: 45 degrees (\) curv = k[:,:,2] i,j = numpy.indices(curv.shape) for index in range(-curv.shape[0]+1, curv.shape[1]): - V[i==(j-index),2] += _prob_1d(curv.diagonal(index)) + V[i==(j-index)] += _prob_1d(curv.diagonal(index)) # Direction: -45 degrees (/) # NOTE: due to the way the access to the diagonals are implemented, in this @@ -308,7 +308,7 @@ class MaximumCurvature (Extractor): curv = numpy.flipud(k[:,:,3]) #required so we get "/" diagonals correctly Vud = numpy.flipud(V) #match above inversion for index in reversed(range(curv.shape[1]-1, -curv.shape[0], -1)): - Vud[i==(j-index),3] += _prob_1d(curv.diagonal(index)) + Vud[i==(j-index)] += _prob_1d(curv.diagonal(index)) return V @@ -472,36 +472,36 @@ class MaximumCurvature (Extractor): finger_image = image[0] finger_mask = image[1] - import time - start = time.time() + #import time + #start = time.time() kappa = self.detect_valleys(finger_image, finger_mask) #self._view_four(kappa, "Valley Detectors - $\kappa$") - print('filtering took %.2f seconds' % (time.time() - start)) - start = time.time() + #print('filtering took %.2f seconds' % (time.time() - start)) + #start = time.time() V = self.eval_vein_probabilities(kappa) #self._view_four(V, "Center Probabilities - $V_i$") #self._view_single(V.sum(axis=2), "Accumulated Probabilities - V") - print('probabilities took %.2f seconds' % (time.time() - start)) - start = time.time() + #print('probabilities took %.2f seconds' % (time.time() - start)) + #start = time.time() - Cd = self.connect_centres(V.sum(axis=2)) + Cd = self.connect_centres(V) #self._view_four(Cd, "Connected Centers - $C_{di}$") #self._view_single(numpy.amax(Cd, axis=2), "Connected Centers - G") - print('connections took %.2f seconds' % (time.time() - start)) - start = time.time() + #print('connections took %.2f seconds' % (time.time() - start)) + #start = time.time() retval = self.binarise(numpy.amax(Cd, axis=2)) #self._view_single(retval, "Final Binarised Image") - print('binarization took %.2f seconds' % (time.time() - start)) + #print('binarization took %.2f seconds' % (time.time() - start)) return retval diff --git a/bob/bio/vein/tests/test.py b/bob/bio/vein/tests/test.py index dbc5953..23cf7c3 100644 --- a/bob/bio/vein/tests/test.py +++ b/bob/bio/vein/tests/test.py @@ -86,8 +86,7 @@ def test_max_curvature(): MC = MaximumCurvature(3) #value used to create references kappa = MC.detect_valleys(image, mask) - V = MC.eval_vein_probabilities(kappa) - Vt = V.sum(axis=2) + Vt = MC.eval_vein_probabilities(kappa) Cd = MC.connect_centres(Vt) G = numpy.amax(Cd, axis=2) bina = MC.binarise(G) diff --git a/matlab/compare.py b/matlab/compare.py index f78bfad..a6c1de2 100644 --- a/matlab/compare.py +++ b/matlab/compare.py @@ -32,8 +32,7 @@ from bob.bio.vein.extractor.MaximumCurvature import MaximumCurvature MC = MaximumCurvature(3) kappa = MC.detect_valleys(image, region) #OK -V = MC.eval_vein_probabilities(kappa) #OK -Vt = V.sum(axis=2) #OK +Vt = MC.eval_vein_probabilities(kappa) #OK Cd = MC.connect_centres(Vt) #OK G = numpy.amax(Cd, axis=2) #OK @@ -42,9 +41,6 @@ for k in range(4): print('Comparing kappa[%d]: %s' % (k, numpy.abs(kappa[...,k]-kappa_matlab[...,k]).sum())) -for k in range(4): - print('Comparing V[%d]: %s' % (k, numpy.abs(V[...,k]-V_matlab[...,k]).sum())) - print('Comparing Vt: %s' % numpy.abs(Vt-Vt_matlab).sum()) for k in range(4): -- 2.21.0