Commit a4fe3bf6 authored by André Anjos's avatar André Anjos 💬

More cleaning-up and test passing

parent ac24ea5d
......@@ -2,23 +2,4 @@
# vim: set fileencoding=utf-8 :
from ...preprocessors import FingerCrop
# Contour localization mask
CONTOUR_MASK_HEIGHT = 4 # Height of the mask
CONTOUR_MASK_WIDTH = 40 # Width of the mask
PADDING_OFFSET = 5
PADDING_THRESHOLD = 0.2 #Threshold for padding black zones
FINGERCONTOUR = 'leemaskMod' # Options: 'leemaskMatlab', 'konomask'
POSTPROCESSING = 'CircGabor' # Options: None, 'HE', 'HFE', 'CircGabor'
# define the preprocessor
preprocessor = FingerCrop(
mask_h=CONTOUR_MASK_HEIGHT,
mask_w=CONTOUR_MASK_WIDTH,
padding_offset=PADDING_OFFSET,
padding_threshold=PADDING_THRESHOLD,
fingercontour=FINGERCONTOUR,
postprocessing=POSTPROCESSING,
)
preprocessor = FingerCrop(postprocessing='CircGabor')
......@@ -2,24 +2,4 @@
# vim: set fileencoding=utf-8 :
from ...preprocessors import FingerCrop
# Contour localization mask
CONTOUR_MASK_HEIGHT = 4 # Height of the mask
CONTOUR_MASK_WIDTH = 40 # Width of the mask
PADDING_OFFSET = 5
PADDING_THRESHOLD = 0.2 #Threshold for padding black zones
PREPROCESSING = None
FINGERCONTOUR = 'leemaskMod' # Options: 'leemaskMatlab', 'konomask'
POSTPROCESSING = 'HE' # Options: None, 'HE', 'HFE', 'CircGabor'
# define the preprocessor
preprocessor = FingerCrop(
mask_h=CONTOUR_MASK_HEIGHT,
mask_w=CONTOUR_MASK_WIDTH,
padding_offset=PADDING_OFFSET,
padding_threshold=PADDING_THRESHOLD,
fingercontour=FINGERCONTOUR,
postprocessing=POSTPROCESSING,
)
preprocessor = FingerCrop(postprocessing='HFE')
......@@ -2,26 +2,4 @@
# vim: set fileencoding=utf-8 :
from ...preprocessors import FingerCrop
# Contour localization mask
CONTOUR_MASK_HEIGHT = 4 # Height of the mask
CONTOUR_MASK_WIDTH = 40 # Width of the mask
PADDING_OFFSET = 5
PADDING_THRESHOLD = 0.2 #Threshold for padding black zones
PREPROCESSING = None
FINGERCONTOUR = 'leemaskMod' # Options: 'leemaskMatlab', 'konomask'
POSTPROCESSING = 'HFE' # Options: None, 'HE', 'HFE', 'CircGabor'
# define the preprocessor
preprocessor = FingerCrop(
mask_h=CONTOUR_MASK_HEIGHT,
mask_w=CONTOUR_MASK_WIDTH,
padding_offset=PADDING_OFFSET,
padding_threshold=PADDING_THRESHOLD,
preprocessing=PREPROCESSING,
fingercontour=FINGERCONTOUR,
postprocessing=POSTPROCESSING,
)
preprocessor = FingerCrop(postprocessing='HFE')
......@@ -2,24 +2,4 @@
# vim: set fileencoding=utf-8 :
from ...preprocessors import FingerCrop
# Contour localization mask
CONTOUR_MASK_HEIGHT = 4 # Height of the mask
CONTOUR_MASK_WIDTH = 40 # Width of the mask
PADDING_OFFSET = 5
PADDING_THRESHOLD = 0.2 #Threshold for padding black zones
FINGERCONTOUR = 'leemaskMod' # Options: 'leemaskMod', leemaskMatlab', 'konomask'
POSTPROCESSING = None # Options: None, 'HE', 'HFE', 'CircGabor'
# define the preprocessor
preprocessor = FingerCrop(
mask_h=CONTOUR_MASK_HEIGHT,
mask_w=CONTOUR_MASK_WIDTH,
padding_offset=PADDING_OFFSET,
padding_threshold=PADDING_THRESHOLD,
fingercontour=FINGERCONTOUR,
postprocessing=POSTPROCESSING,
)
preprocessor = FingerCrop()
......@@ -57,11 +57,11 @@ class MaximumCurvature (Extractor):
# Do the actual filtering
fx = utils.imfilter(image, hx, conv=False)
fxx = utils.imfilter(image, hxx, conv=False)
fy = utils.imfilter(image, hy, conv=False)
fyy = utils.imfilter(image, hyy, conv=False)
fxy = utils.imfilter(image, hxy, conv=False)
fx = utils.imfilter(image, hx)
fxx = utils.imfilter(image, hxx)
fy = utils.imfilter(image, hy)
fyy = utils.imfilter(image, hyy)
fxy = utils.imfilter(image, hxy)
f1 = 0.5*numpy.sqrt(2)*(fx + fy) # \ #
f2 = 0.5*numpy.sqrt(2)*(fx - fy) # / #
......
This diff is collapsed.
......@@ -29,6 +29,27 @@ def F(parts):
return pkg_resources.resource_filename(__name__, os.path.join(*parts))
def _show_mask_over_image(image, mask, color='red'):
"""Plots the mask over the image of a finger, for debugging purposes
Parameters:
image (numpy.ndarray): A 2D numpy.ndarray compose of 8-bit unsigned
integers containing the original image
mask (numpy.ndarray): A 2D numpy.ndarray compose of boolean values
containing the calculated mask
"""
from PIL import Image
img = Image.fromarray(image).convert(mode='RGBA')
msk = Image.fromarray((~mask).astype('uint8')*80)
red = Image.new('RGBA', img.size, color=color)
img.paste(red, mask=msk)
img.show()
def test_finger_crop():
input_filename = F(('preprocessors', '0019_3_1_120509-160517.png'))
......@@ -40,17 +61,17 @@ def test_finger_crop():
img = bob.io.base.load(input_filename)
from bob.bio.vein.preprocessors.FingerCrop import FingerCrop
preprocess = FingerCrop(fingercontour='leemaskMatlab')
preprocess = FingerCrop(fingercontour='leemaskMatlab', padding_width=0)
output_img, finger_mask_norm = preprocess(img)
preproc, mask = preprocess(img)
#_show_mask_over_image(preproc, mask)
# Load Matlab reference
output_img_ref = bob.io.base.load(output_img_filename)
output_fvr_ref = bob.io.base.load(output_fvr_filename)
mask_ref = bob.io.base.load(output_fvr_filename)
preproc_ref = bob.io.base.load(output_img_filename)
# Compare output of python's implementation to matlab reference
# (loose comparison!)
assert numpy.mean(numpy.abs(output_img - output_img_ref)) < 1e2
# Very loose comparison!
assert numpy.mean(numpy.abs(mask.astype('float64') - mask_ref)) < 1e-2
assert numpy.mean(numpy.abs(preproc - preproc_ref)) < 1e2
def test_miuramax():
......@@ -67,7 +88,7 @@ def test_miuramax():
# Apply Python implementation
from bob.bio.vein.extractors.MaximumCurvature import MaximumCurvature
MC = MaximumCurvature(5, False)
MC = MaximumCurvature(5)
output_img = MC((input_img, input_fvr))
# Load Matlab reference
......
......@@ -8,10 +8,10 @@ import bob.sp
import bob.core
def imfilter(a, b, conv=True):
def imfilter(a, b):
"""Applies a 2D filtering between images
This implementation was created to work exactly like the Matlab one.
This implementation was created to work similarly like the Matlab one.
Parameters:
......@@ -23,20 +23,16 @@ def imfilter(a, b, conv=True):
with :py:func:`bob.core.convert` and the range reset to ``[0.0, 1.0]``.
b (numpy.ndarray): A 64-bit float 2-dimensional :py:class:`numpy.ndarray`
which represents the filter to be applied to the image
conv (bool, Optional): If set, then rotates the filter ``b`` by 180 degrees
before applying it to the image ``a``, with
:py:func:`bob.ip.base.rotate`.
which represents the filter to be applied to the image. The input filter
has to be rotated by 180 degrees as we use
:py:func:`scipy.signal.convolve2d` to apply it. You can rotate your
filter ``b`` with the help of :py:func:`bob.ip.base.rotate`.
"""
if a.dtype == numpy.uint8:
a = bob.core.convert(a, numpy.float64, (0,1))
if conv:
b = bob.ip.base.rotate(b, 180)
shape = (a.shape[0] + b.shape[0] - 1, a.shape[1] + b.shape[1] - 1)
a_ext = numpy.ndarray(shape=shape, dtype=numpy.float64)
bob.sp.extrapolate_nearest(a, a_ext)
......
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