From 1a51ef4dfe12f810ddb33f3e470e2958cb1fa0a9 Mon Sep 17 00:00:00 2001 From: Rakesh Mehta <rakesh.mehta@idiap.ch> Date: Tue, 27 Aug 2013 14:25:29 +0200 Subject: [PATCH] Comments added to features --- xbob/boosting/core/gaussiantrainer.py | 61 ------------------------- xbob/boosting/features/local_feature.py | 29 +++++++----- 2 files changed, 17 insertions(+), 73 deletions(-) delete mode 100644 xbob/boosting/core/gaussiantrainer.py diff --git a/xbob/boosting/core/gaussiantrainer.py b/xbob/boosting/core/gaussiantrainer.py deleted file mode 100644 index 851fef0..0000000 --- a/xbob/boosting/core/gaussiantrainer.py +++ /dev/null @@ -1,61 +0,0 @@ - -class GaussianMachine(): - - def __init__(self, num_classes): - self.means = numpy.zeros(num_classes) - self.variance = numpy.zeros(num_classes) - self.selected_index = 0 - - - def get_weak_scores(self, features): - num_classes = self.means.shape[0] - - - for i in range(num_classes): - mean_i = means[i] - variance_i = variance[i] - feature_i = features[:,i] - demon = numpy.sqrt(2*numpy.pi*variance_i) - scores[i] = numpy.exp(-(((feature_i - mean_i)**2)/2*variance_i)) - - return scores - -class GaussianTrainer(): - - def __init__(self, num_classes): - self.num_classes = num_classes - - - def compute_weak_trainer(self, features, loss_grad): - - num_features = features.shape[1] - means = numpy.zeros([num_features,self.num_classes]) - variances = numpy.zeros([num_features,self.num_classes]) - summed_loss = numpy.zeros(num_features) - gauss_machine = GaussianMachine() - - for feature_index in range(num_features) - single_feature = features[:,feature_index] - means[i,;], variances[i,:], loss[i] = compute_current_loss(single_feature, classes, loss_grad) - - gauss_machine.selected_index = numpy.argmin(loss) - gauss_machine.means = means[optimum_index,:] - gauss_machine.variance = variances[optimum_index,:] - - - - def compute_current_loss(feature, classes, loss_grad): - num_samples = feature.shape[0] - scores = numpy.zeros([num_samples, self.num_classes]) - - for class_index in range(self.num_classes): - samples_i = feature[loss_grad[:,class_index] < 0] - mean[i] = numpy.mean(samples_i) - variance[i] = numpy.std(samples_i)**2 - scores[:,class_index] = numpy.exp(-(((feature_i - mean_i)**2)/2*variance_i)) - - - scores_sum = numpy.sum(scores) - - return mean, variance, scores_sum - diff --git a/xbob/boosting/features/local_feature.py b/xbob/boosting/features/local_feature.py index 913f8fe..755971d 100644 --- a/xbob/boosting/features/local_feature.py +++ b/xbob/boosting/features/local_feature.py @@ -37,7 +37,7 @@ class lbp_feature(): img: Input images return: - int_img: The integral image of the input image.""" + integral_xy: The integral image of the input image.""" integral_y = numpy.cumsum(img,0) integral_xy = numpy.cumsum(integral_y,1) @@ -100,14 +100,12 @@ class lbp_feature(): def lbp(self, block_sum): - """Function to compute the LBP for a image at single scale. + """Function to compute the LBP(3x3) for a image at single scale. The LBP features of the given image is computed and the feature map is returned Inputs: - coord: The coordinates specify the neighbour to be considered. - feature_map_dimx: feature map's dimension along the columns. - feature_map_dimy: Feature maps dimension along the rows. + block_sum: The image with each pixel representing the sum of a block. Return: feature_map: The lbp feature map @@ -129,9 +127,7 @@ class lbp_feature(): The tLBP features of the given image is computed and the feature map is returned Inputs: - coord: The coordinates specify the neighbour to be considered. - feature_map_dimx: feature map's dimension along the columns. - feature_map_dimy: Feature maps dimension along the rows. + block_sum: The image with each pixel representing the sum of a block. Return: feature_map: The lbp feature map @@ -158,9 +154,7 @@ class lbp_feature(): The dLBP features of the given image is computed and the feature map is returned Inputs: - coord: The coordinates specify the neighbour to be considered. - feature_map_dimx: feature map's dimension along the columns. - feature_map_dimy: Feature maps dimension along the rows. + block_sum: The image with each pixel representing the sum of a block. Return: feature_map: The lbp feature map @@ -189,7 +183,7 @@ class lbp_feature(): The mLBP features of the given image is computed and the feature map is returned. Inputs: - block_sum: The image that to apply mlbp operator on. + block_sum: The image with each pixel representing the sum of a block. Return: feature_map: The lbp feature map @@ -234,6 +228,17 @@ class lbp_feature(): return feature_vector.shape[0] def get_map_dimension(self, block_sum): + """ The function computes the dimension of the LBP (R = 1, P = 8) type feature image + + The feature image returned by LBP with radius R is less than the image size by 2*R -1, for + R = 1, the feature map is smaller than the image by 2 pixel in both direction. + + Input: + + block_sum: The image with each pixel representing the sum of a block. + + Return: + feature_map_dimx, feature_map_dimy : The dimensions of the feature map.""" # Initialize the size of the final feature map that will be obtained feature_map_dimy = block_sum.shape[0] -2 -- GitLab