From c11fc7717295d8f8e9295f1e7f623d5c19d26b32 Mon Sep 17 00:00:00 2001 From: ageorge <anjith.george@idiap.ch> Date: Thu, 29 Oct 2020 08:57:46 +0100 Subject: [PATCH] For the SCalability experiments --- bob/pad/face/config/grid.py | 2 +- bob/pad/face/database/hqwmca_warp.py | 2 + bob/pad/face/preprocessor/FaceCropAlign.py | 63 +++++++++++++++++++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/bob/pad/face/config/grid.py b/bob/pad/face/config/grid.py index 7c5713d4..29851085 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 1a7d20f9..eac223fe 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 aab0e6a8..a101900a 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) -- GitLab