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

[preproc] Improve finger post-processing (heq); Fix warnings

parent bc0745df
...@@ -26,10 +26,10 @@ class FingerCrop (Preprocessor): ...@@ -26,10 +26,10 @@ class FingerCrop (Preprocessor):
In this implementation, the finger image is (in this order): In this implementation, the finger image is (in this order):
1. Padded 1. Padded
2. The mask is extracted 2. The mask is extracted
3. The finger is normalized (made horizontal) 3. The finger is normalized (made horizontal)
3. (optionally) Post processed 4. (optionally) Post processed
Parameters: Parameters:
...@@ -220,15 +220,15 @@ class FingerCrop (Preprocessor): ...@@ -220,15 +220,15 @@ class FingerCrop (Preprocessor):
# Right region has always the finger ending, crop the padding with the # Right region has always the finger ending, crop the padding with the
# meadian # meadian
finger_mask[:,numpy.median(y_rg)+img_filt_rg.shape[1]:] = False finger_mask[:,int(numpy.median(y_rg)+img_filt_rg.shape[1]):] = False
# Extract y-position of finger edges # Extract y-position of finger edges
edges = numpy.zeros((2,img_w)) edges = numpy.zeros((2,img_w))
edges[0,:] = y_up edges[0,:] = y_up
edges[0,0:round(numpy.mean(y_lf))+1] = edges[0,round(numpy.mean(y_lf))+1] edges[0,0:int(round(numpy.mean(y_lf))+1)] = edges[0,int(round(numpy.mean(y_lf))+1)]
edges[1,:] = numpy.round(y_lo + img_filt_lo.shape[0]) edges[1,:] = numpy.round(y_lo + img_filt_lo.shape[0])
edges[1,0:round(numpy.mean(y_lf))+1] = edges[1,round(numpy.mean(y_lf))+1] edges[1,0:int(round(numpy.mean(y_lf))+1)] = edges[1,int(round(numpy.mean(y_lf))+1)]
return finger_mask, edges return finger_mask, edges
...@@ -401,8 +401,13 @@ class FingerCrop (Preprocessor): ...@@ -401,8 +401,13 @@ class FingerCrop (Preprocessor):
return (image_norm, mask_norm) return (image_norm, mask_norm)
def __HE__(self, image): def __HE__(self, image, mask):
"""Applies histogram equalization on the input image """Applies histogram equalization on the input image inside the mask
In this implementation, only the pixels that lie inside the mask will be
used to calculate the histogram equalization parameters. Because of this
particularity, we don't use Bob's implementation for histogram equalization
and have one based exclusively on NumPy.
Parameters: Parameters:
...@@ -410,6 +415,10 @@ class FingerCrop (Preprocessor): ...@@ -410,6 +415,10 @@ class FingerCrop (Preprocessor):
image (numpy.ndarray): raw image to be filtered, as 2D array of image (numpy.ndarray): raw image to be filtered, as 2D array of
unsigned 8-bit integers unsigned 8-bit integers
mask (numpy.ndarray): mask of the same size of the image, but composed
of boolean values indicating which values should be considered for
the histogram equalization
Returns: Returns:
...@@ -418,9 +427,19 @@ class FingerCrop (Preprocessor): ...@@ -418,9 +427,19 @@ class FingerCrop (Preprocessor):
""" """
#Umbralization based on the pixels non zero image_histogram, bins = numpy.histogram(image[mask], 256, normed=True)
retval = numpy.zeros(image.shape, dtype=numpy.uint8) cdf = image_histogram.cumsum() # cumulative distribution function
bob.ip.base.histogram_equalization(image, retval) cdf = 255 * cdf / cdf[-1] # normalize
# use linear interpolation of cdf to find new pixel values
image_equalized = numpy.interp(image.flatten(), bins[:-1], cdf)
image_equalized = image_equalized.reshape(image.shape)
# normalized image to be returned is a composition of the original image
# (background) and the equalized image (finger area)
retval = image.copy()
retval[mask] = image_equalized[mask]
return retval return retval
...@@ -521,32 +540,33 @@ class FingerCrop (Preprocessor): ...@@ -521,32 +540,33 @@ class FingerCrop (Preprocessor):
"""Reads the input image, extract the mask of the fingervein, postprocesses """Reads the input image, extract the mask of the fingervein, postprocesses
""" """
import ipdb; ipdb.set_trace()
# 1. Pads the input image if any padding should be added # 1. Pads the input image if any padding should be added
image = numpy.pad(image, self.padding_width, 'constant', image = numpy.pad(image, self.padding_width, 'constant',
constant_values = self.padding_constant) constant_values = self.padding_constant)
## Finger edges and contour extraction: ## Finger edges and contour extraction:
if self.fingercontour == 'leemaskMatlab': if self.fingercontour == 'leemaskMatlab':
finger_mask, finger_edges = self.__leemaskMatlab__(image) #for UTFVP mask, edges = self.__leemaskMatlab__(image) #for UTFVP
elif self.fingercontour == 'leemaskMod': elif self.fingercontour == 'leemaskMod':
finger_mask, finger_edges = self.__leemaskMod__(image) #for VERA mask, edges = self.__leemaskMod__(image) #for VERA
elif self.fingercontour == 'konomask': elif self.fingercontour == 'konomask':
finger_mask, finger_edges = self.__konomask__(image, sigma=5) mask, edges = self.__konomask__(image, sigma=5)
## Finger region normalization: ## Finger region normalization:
image_norm, finger_mask_norm = self.__huangnormalization__(image, image_norm, mask_norm = self.__huangnormalization__(image, mask, edges)
finger_mask, finger_edges)
## veins enhancement: ## veins enhancement:
if self.postprocessing == 'HE': if self.postprocessing == 'HE':
image_norm = self.__HE__(image_norm) image_norm = self.__HE__(image_norm, mask_norm)
elif self.postprocessing == 'HFE': elif self.postprocessing == 'HFE':
image_norm = self.__HFE__(image_norm) image_norm = self.__HFE__(image_norm)
elif self.postprocessing == 'CircGabor': elif self.postprocessing == 'CircGabor':
image_norm = self.__circularGabor__(image_norm, 1.12, 5) image_norm = self.__circularGabor__(image_norm, 1.12, 5)
## returns the normalized image and the finger mask ## returns the normalized image and the finger mask
return image_norm, finger_mask_norm return image_norm, mask_norm
def write_data(self, data, filename): def write_data(self, data, filename):
......
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