Commit a10153883188a2f44779ecc645b05db08cf447a0
1 parent
d86637ae
optimizations
Showing
1 changed file
with
12 additions
and
7 deletions
openbr/plugins/quantize.cpp
| @@ -74,22 +74,27 @@ class BayesianQuantizationDistance : public Distance | @@ -74,22 +74,27 @@ class BayesianQuantizationDistance : public Distance | ||
| 74 | QList<int> labels = src.labels<int>(); | 74 | QList<int> labels = src.labels<int>(); |
| 75 | 75 | ||
| 76 | QVector<qint64> genuines(256*256,0), impostors(256*256,0); | 76 | QVector<qint64> genuines(256*256,0), impostors(256*256,0); |
| 77 | - qint64 totalGenuines(0), totalImpostors(0); | ||
| 78 | for (int i=0; i<labels.size(); i++) { | 77 | for (int i=0; i<labels.size(); i++) { |
| 79 | const uchar *a = data.ptr(i); | 78 | const uchar *a = data.ptr(i); |
| 80 | for (int j=0; j<labels.size(); j++) { | 79 | for (int j=0; j<labels.size(); j++) { |
| 81 | const uchar *b = data.ptr(j); | 80 | const uchar *b = data.ptr(j); |
| 82 | const bool genuine = (labels[i] == labels[j]); | 81 | const bool genuine = (labels[i] == labels[j]); |
| 83 | - for (int k=0; k<data.cols; k++) { | ||
| 84 | - if (genuine) { genuines[256*a[k]+b[k]]++; genuines[256*b[k]+a[k]]++; totalGenuines++; } | ||
| 85 | - else { impostors[256*a[k]+b[k]]++; impostors[256*b[k]+a[k]]++; totalImpostors++; } | ||
| 86 | - } | 82 | + for (int k=0; k<data.cols; k++) |
| 83 | + genuine ? genuines[256*a[k]+b[k]]++ : impostors[256*a[k]+b[k]]++; | ||
| 87 | } | 84 | } |
| 88 | } | 85 | } |
| 89 | 86 | ||
| 87 | + qint64 totalGenuines(0), totalImpostors(0); | ||
| 88 | + for (int i=0; i<256*256; i++) { | ||
| 89 | + totalGenuines += genuines[i]; | ||
| 90 | + totalImpostors += impostors[i]; | ||
| 91 | + } | ||
| 92 | + | ||
| 90 | loglikelihood = QVector<float>(256*256); | 93 | loglikelihood = QVector<float>(256*256); |
| 91 | - for (int i=0; i<256*256; i++) | ||
| 92 | - loglikelihood[i] = log((double(genuines[i]+1)/totalGenuines)/(double(impostors[i]+1)/totalImpostors)); | 94 | + for (int i=0; i<256; i++) |
| 95 | + for (int j=0; j<256; j++) | ||
| 96 | + loglikelihood[i*256+j] = log((double(genuines[i*256+j]+genuines[j*256+i]+1)/totalGenuines)/ | ||
| 97 | + (double(impostors[i*256+j]+impostors[j*256+i]+1)/totalImpostors)); | ||
| 93 | } | 98 | } |
| 94 | 99 | ||
| 95 | float compare(const Template &a, const Template &b) const | 100 | float compare(const Template &a, const Template &b) const |