diff --git a/bob/pad/face/config/grid.py b/bob/pad/face/config/grid.py index 7c5713d4b589f7c7f9e4f3c643c7d8e588208510..29851085bda879cf517e810d628509996c12eed5 100644 --- a/bob/pad/face/config/grid.py +++ b/bob/pad/face/config/grid.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: set fileencoding=utf-8 : -from bob.bio.base.grid import Grid +from bob.bio.base_legacy.grid import Grid # Configuration to run on computation cluster: idiap = Grid( diff --git a/bob/pad/face/database/hqwmca_warp.py b/bob/pad/face/database/hqwmca_warp.py index 1a7d20f96fba45e1efadf026cdcff5b30a21db13..eac223fee884f3b41503e839c5b1efff807443fb 100644 --- a/bob/pad/face/database/hqwmca_warp.py +++ b/bob/pad/face/database/hqwmca_warp.py @@ -239,6 +239,8 @@ class HQWMCAPadDatabase_warp(PadDatabase): file_path = os.path.join(self.annotations_dir, ff.path + ".json") + print('Annotation path',file_path) + if not os.path.isfile(file_path): # no file with annotations # original values of the arguments of f: diff --git a/bob/pad/face/preprocessor/FaceCropAlign.py b/bob/pad/face/preprocessor/FaceCropAlign.py index aab0e6a8bb166542ba69580bbc46e1b092cce81f..a101900a7e62cf89cdf3ba0c5eb59c20643543b9 100644 --- a/bob/pad/face/preprocessor/FaceCropAlign.py +++ b/bob/pad/face/preprocessor/FaceCropAlign.py @@ -28,6 +28,67 @@ logger = logging.getLogger("bob.pad.face") # ============================================================================== + + +def depth_auto_norm_image(data, annotations, n_sigma=3.0, norm_method='MAD', FD=500): + """ + Normalizes a single channel image to range 0-255, using the data distribution + Expects single channel images + + **method: Gaussian , MAD, MINMAX + **n_sigma: The range which is normalized + + """ + + # print('annotation',annotations) + + face = data[annotations['topleft'][0]:annotations['bottomright'][0], + annotations['topleft'][1]:annotations['bottomright'][1]] + + face = face.astype('float') + data = data.astype('float') + + assert(len(data.shape)==2) + + face_c = np.ma.array(face).compressed() + # Avoiding zeros from flat field in thermal and holes in depth + + face_c=face_c[face_c>1.0] + + if norm_method=='STD': + + mu = np.mean(face_c) + std = np.std(face_c) + + data_n=((data-mu+n_sigma*std)/(2.0*n_sigma*std))*255.0 + + + if norm_method=='MAD': + + med = np.median(face_c) + mad = np.median(np.abs(face_c - med)) + + data_n = ((data-med+n_sigma*mad)/(2.0*n_sigma*mad))*255.0 + + + if norm_method=='MINMAX': + + t_min = np.min(face_c) + t_max = np.max(face_c) + + data_n = ((data-t_min)/(t_max-t_min))*255.0 + + + # Clamping to 0-255 + data_n=np.maximum(data_n,0) + data_n=np.minimum(data_n,255) + + data_n = data_n.astype('uint8') + + return data_n + + + def auto_norm_image(data, annotations, n_sigma=3.0, norm_method='MAD'): """ Normalizes a single channel image to range 0-255, using the data distribution @@ -581,7 +642,7 @@ class FaceCropAlign(Preprocessor): - print('INSIDE FACECROP ALIGN',annotations.keys(), annotations) + #print('INSIDE FACECROP ALIGN',annotations.keys(), annotations) if self.normalization_function is not None: image = self.normalization_function(image, annotations, **self.normalization_function_kwargs)