diff --git a/bob/bio/vein/database/putvein.py b/bob/bio/vein/database/putvein.py index b4f972b06b2b1b14e3d53a4584b4f4d472dda3e6..8f993d9b6ba1aab93174d574e137145bb93aedc1 100644 --- a/bob/bio/vein/database/putvein.py +++ b/bob/bio/vein/database/putvein.py @@ -8,9 +8,35 @@ framework). """ from bob.bio.base.database import BioFile, BioDatabase -import bob.ip.color import numpy as np +#TODO: I know this is not DRY recommended, but that's life +# I might move this to a proper package. +def rgb_to_gray(image): + """ + Converts an RGB image to a grayscale image. + The formula is: + GRAY = 0.299 * R + 0.587 * G + 0.114 * B + + + Parameters + ---------- + + image : numpy.ndarray + An image in RGB format (channels first): For an ND array (N >= 3), + + + """ + + assert image.ndim == 3, "The image should have 3 dimensions" + + R = image[0, :, :] + G = image[1, :, :] + B = image[2, :, :] + + return 0.299 * R + 0.587 * G + 0.114 * B + + class File(BioFile): """ @@ -38,7 +64,7 @@ class File(BioFile): """ color_image = self.f.load(directory=directory, extension=extension) - grayscale_image = bob.ip.color.rgb_to_gray(color_image) + grayscale_image = rgb_to_gray(color_image) grayscale_image = np.rot90(grayscale_image, k=3) return grayscale_image diff --git a/bob/bio/vein/extractor/LocalBinaryPatterns.py b/bob/bio/vein/extractor/LocalBinaryPatterns.py deleted file mode 100644 index 2adb4482c144e74e2a07b63793375aa2a689759e..0000000000000000000000000000000000000000 --- a/bob/bio/vein/extractor/LocalBinaryPatterns.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python -# vim: set fileencoding=utf-8 : - -import numpy - -import bob.ip.base -import bob.io.base - -from bob.bio.base.extractor import Extractor - - -class LocalBinaryPatterns (Extractor): - """LBP feature extractor - - Parameters fixed based on L. Mirmohamadsadeghi and A. Drygajlo. Palm vein - recognition using local texture patterns, IET Biometrics, pp. 1-9, 2013. - """ - - def __init__( - self, - # Block setup - block_size = 59, # one or two parameters for block size - block_overlap = 15, # one or two parameters for block overlap - # LBP parameters - lbp_radius = 7, - lbp_neighbor_count = 16, - lbp_uniform = True, - lbp_circular = True, - lbp_rotation_invariant = False, - lbp_compare_to_average = False, - lbp_add_average = False, - # histogram options - sparse_histogram = False, - split_histogram = None, - ): - - # call base class constructor - Extractor.__init__( - self, - # Block setup - block_size = block_size, - block_overlap = block_overlap, - #LBP parameters - lbp_radius = lbp_radius, - lbp_neighbor_count = lbp_neighbor_count, - lbp_uniform = lbp_uniform, - lbp_circular = lbp_circular, - lbp_rotation_invariant = lbp_rotation_invariant, - lbp_compare_to_average = lbp_compare_to_average, - lbp_add_average = lbp_add_average, - sparse_histogram = sparse_histogram, - split_histogram = split_histogram, - ) - - # block parameters - self.m_block_size = block_size if isinstance(block_size, (tuple, list)) else (block_size, block_size) - self.m_block_overlap = block_overlap if isinstance(block_overlap, (tuple, list)) else (block_overlap, block_overlap) - if self.m_block_size[0] < self.m_block_overlap[0] or self.m_block_size[1] < self.m_block_overlap[1]: - raise ValueError("The overlap is bigger than the block size. This won't work. Please check your setup!") - - self.m_lbp = bob.ip.base.LBP( - neighbors = lbp_neighbor_count, - radius = float(lbp_radius), - circular = lbp_circular, - to_average = lbp_compare_to_average, - add_average_bit = lbp_add_average, - uniform = lbp_uniform, - rotation_invariant = lbp_rotation_invariant, - border_handling = 'wrap', - ) - - - self.m_split = split_histogram - self.m_sparse = sparse_histogram - if self.m_sparse and self.m_split: - raise ValueError("Sparse histograms cannot be split! Check your setup.") - - - def __fill__(self, lbphs_array, lbphs_blocks, j): - """Copies the given array into the given blocks""" - - # fill array in the desired shape - for b in range(self.m_n_blocks): - lbphs_array[b * self.m_n_bins : (b+1) * self.m_n_bins] = lbphs_blocks[b][:] - - - def lbp_features(self, finger_image, mask): - """Computes and returns the LBP features for the given input fingervein - image""" - - finger_image = finger_image.astype(numpy.float64) - - finger_mask = numpy.zeros(mask.shape) - finger_mask[mask == True] = 1 - - # Mask the vein image with the finger region - finger_image = finger_image*finger_mask - - # Computes LBP histograms - abs_blocks = bob.ip.base.lbphs(finger_image, self.m_lbp, self.m_block_size, self.m_block_overlap) - - # Converts to Blitz array (of different dimensionalities) - self.m_n_bins = abs_blocks.shape[1] - self.m_n_blocks = abs_blocks.shape[0] - - shape = self.m_n_bins * self.m_n_blocks - - # create new array - lbphs_array = numpy.zeros(shape, 'float64') - - # fill the array with the absolute values of the Gabor wavelet transform - self.__fill__(lbphs_array, abs_blocks, 0) - - # return the concatenated list of all histograms - return lbphs_array - - - def __call__(self, image): - """Reads the input image, extract the features based on LBP of the fingervein image, and writes the resulting template""" - #For debugging - - finger_image = image[0] #Normalized image with histogram equalization - finger_mask = image[1] - - return self.lbp_features(finger_image, finger_mask) diff --git a/bob/bio/vein/extractor/__init__.py b/bob/bio/vein/extractor/__init__.py index afd52d096a2f4237817de10f43cc3a47c994ec5b..559d6f56bc6a135be2d98e67f6ffc28591eb239f 100644 --- a/bob/bio/vein/extractor/__init__.py +++ b/bob/bio/vein/extractor/__init__.py @@ -1,4 +1,3 @@ -from .LocalBinaryPatterns import LocalBinaryPatterns from .NormalisedCrossCorrelation import NormalisedCrossCorrelation from .PrincipalCurvature import PrincipalCurvature from .RepeatedLineTracking import RepeatedLineTracking diff --git a/conda/meta.yaml b/conda/meta.yaml index 7c9b0e12177cfe96bfc2be9ccc62ff81d591dfc9..a853a8f3d5b823558bcf5f70558f13963325b5f6 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -35,9 +35,6 @@ requirements: - bob.extension - bob.core - bob.io.base - - bob.io.image - - bob.ip.base - - bob.ip.color - bob.bio.base run: diff --git a/requirements.txt b/requirements.txt index 8a9e371c9caba8ae0dd5d31d75eb72ebd3b50f62..a77ceeeb175640f9f84a55b5aee528cbea7f0e53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,4 @@ matplotlib bob.extension bob.core bob.io.base -bob.io.image -bob.ip.base -bob.ip.color bob.bio.base