Commit fa3e558618a7c3eae0771294ce9a243c8819d1a0
1 parent
0239196a
removed ebif
Showing
1 changed file
with
0 additions
and
148 deletions
openbr/plugins/classification/ebif.cpp deleted
| 1 | -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
| 2 | - * Copyright 2012 The MITRE Corporation * | ||
| 3 | - * * | ||
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| 5 | - * you may not use this file except in compliance with the License. * | ||
| 6 | - * You may obtain a copy of the License at * | ||
| 7 | - * * | ||
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| 9 | - * * | ||
| 10 | - * Unless required by applicable law or agreed to in writing, software * | ||
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| 13 | - * See the License for the specific language governing permissions and * | ||
| 14 | - * limitations under the License. * | ||
| 15 | - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
| 16 | - | ||
| 17 | -#include <opencv2/imgproc/imgproc.hpp> | ||
| 18 | - | ||
| 19 | -#include <openbr/plugins/openbr_internal.h> | ||
| 20 | -#include <openbr/core/common.h> | ||
| 21 | -#include <openbr/core/opencvutils.h> | ||
| 22 | - | ||
| 23 | -using namespace cv; | ||
| 24 | - | ||
| 25 | -namespace br | ||
| 26 | -{ | ||
| 27 | - | ||
| 28 | -/*! | ||
| 29 | - * \ingroup transforms | ||
| 30 | - * \brief Face Recognition Using Early Biologically Inspired Features | ||
| 31 | - * \br_paper Li, Min, et al. | ||
| 32 | - * "Face recognition using early biologically inspired features." | ||
| 33 | - * Biometrics: Theory, Applications and Systems (BTAS), 2013 IEEE Sixth International Conference on. IEEE, 2013. | ||
| 34 | - * \author Josh Klontz \cite jklontz | ||
| 35 | - * \br_property int N The number of scales. Default is 6. | ||
| 36 | - * \br_property int M The number of orientations between 0 and pi. Default is 9. | ||
| 37 | - */ | ||
| 38 | -class EBIFTransform : public UntrainableTransform | ||
| 39 | -{ | ||
| 40 | - Q_OBJECT | ||
| 41 | - Q_PROPERTY(int N READ get_N WRITE set_N RESET reset_N STORED false) // scales | ||
| 42 | - Q_PROPERTY(int M READ get_M WRITE set_M RESET reset_M STORED false) // orientations | ||
| 43 | - BR_PROPERTY(int, N, 6) | ||
| 44 | - BR_PROPERTY(int, M, 9) | ||
| 45 | - | ||
| 46 | - QList<Transform*> orientations; | ||
| 47 | - | ||
| 48 | - void init() | ||
| 49 | - { | ||
| 50 | - for (int m=0; m<M; m++) | ||
| 51 | - orientations.append(make(QString("Gabor(%1,%2,%3,%4,%5,Phase)+Abs").arg( | ||
| 52 | - QString::number(5), // lambda = 5 (just one wavelength) | ||
| 53 | - QString::number(CV_PI*m/M), // M orientations between 0 and pi | ||
| 54 | - QString::number(0), // psi = 0 (no offset) | ||
| 55 | - QString::number(3), // sigma = 3 (just one width) | ||
| 56 | - QString::number(1) // gamma = 1 (no skew) | ||
| 57 | - ))); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - void project(const Template &src, Template &dst) const | ||
| 61 | - { | ||
| 62 | - // Compute the image pyramid | ||
| 63 | - Template scales; | ||
| 64 | - float scaleFactor = 1; | ||
| 65 | - for (int n=0; n<N; n++) { | ||
| 66 | - Mat scale; | ||
| 67 | - const int width = src.m().cols * scaleFactor; | ||
| 68 | - const int height = src.m().rows * scaleFactor; | ||
| 69 | - resize(src, scale, Size(width, height)); | ||
| 70 | - scale.convertTo(scale, CV_32F); | ||
| 71 | - scales.append(scale); | ||
| 72 | - scaleFactor /= sqrt(2.f); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - // Mean and standard deviation pooling | ||
| 76 | - QList< QList<float> > features; | ||
| 77 | - foreach (Transform *orientation, orientations) { | ||
| 78 | - // Compute the reponse wavelet response | ||
| 79 | - Template response; | ||
| 80 | - orientation->project(scales, response); | ||
| 81 | - | ||
| 82 | - // Pool for each two adjacent features | ||
| 83 | - QList<float> orientedFeatures; | ||
| 84 | - for (int i=0; i<N-1; i++) | ||
| 85 | - orientedFeatures.append(pool(response[i], response[i+1])); | ||
| 86 | - features.append(orientedFeatures); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - // L2 normalization across orientations | ||
| 90 | - for (int i=0; i<features.first().size(); i++) { | ||
| 91 | - float squaredSum = 0; | ||
| 92 | - for (int m=0; m<M; m++) { | ||
| 93 | - const float val = features[m][i]; | ||
| 94 | - squaredSum += val * val; | ||
| 95 | - } | ||
| 96 | - const float norm = 1/sqrt(squaredSum + 0.001 /* Avoid division by zero */); | ||
| 97 | - for (int m=0; m<M; m++) | ||
| 98 | - features[m][i] *= norm; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - // Group features by location (not done in paper) | ||
| 102 | - for (int i=0; i<features.first().size(); i+=2) { | ||
| 103 | - QList<float> localFeatures; localFeatures.reserve(2*M); | ||
| 104 | - for (int m=0; m<M; m++) { | ||
| 105 | - localFeatures.append(features[m][i]); // mean | ||
| 106 | - localFeatures.append(features[m][i+1]); // standard deviation | ||
| 107 | - } | ||
| 108 | - dst += OpenCVUtils::toMat(localFeatures); | ||
| 109 | - } | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - QList<float> pool(const Mat &bottom, const Mat &top) const | ||
| 113 | - { | ||
| 114 | - QList<float> features; | ||
| 115 | - for (int i=0; i<=top.rows-3; i+=3) { | ||
| 116 | - for (int j=0; j<=top.cols-3; j+=3) { | ||
| 117 | - QList<float> vals; vals.reserve(3*3 + 4*4); | ||
| 118 | - | ||
| 119 | - // Top values | ||
| 120 | - for (int k=0; k<3; k++) { | ||
| 121 | - const float *data = top.ptr<float>(i+k, j); | ||
| 122 | - for (int l=0; l<3; l++) | ||
| 123 | - vals.append(data[l]); | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - // Bottom values | ||
| 127 | - for (int k=0; k<4; k++) { | ||
| 128 | - const float *data = bottom.ptr<float>(4*i/3+k, 4*j/3); | ||
| 129 | - for (int l=0; l<4; l++) | ||
| 130 | - vals.append(data[l]); | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - double mean, stddev; | ||
| 134 | - Common::MeanStdDev(vals, &mean, &stddev); | ||
| 135 | - features.append(mean); | ||
| 136 | - features.append(stddev); | ||
| 137 | - } | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - return features; | ||
| 141 | - } | ||
| 142 | -}; | ||
| 143 | - | ||
| 144 | -BR_REGISTER(Transform, EBIFTransform) | ||
| 145 | - | ||
| 146 | -} // namespace br | ||
| 147 | - | ||
| 148 | -#include "classification/ebif.moc" |