Commit 1a51ef4d authored by Rakesh MEHTA's avatar Rakesh MEHTA
Browse files

Comments added to features

parent 36f5181d
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
......@@ -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
......
Supports Markdown
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