Commit ac8caa742fe974139ca4a9bf53a85b8cdb407924
1 parent
56b429c4
remove rndsubspace
Showing
2 changed files
with
0 additions
and
175 deletions
openbr/plugins/imgproc/rg.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 <openbr/plugins/openbr_internal.h> | |
| 18 | - | |
| 19 | -using namespace cv; | |
| 20 | - | |
| 21 | -namespace br | |
| 22 | -{ | |
| 23 | - | |
| 24 | -/*! | |
| 25 | - * \ingroup transforms | |
| 26 | - * \brief Normalized RG color space. | |
| 27 | - * \author Josh Klontz \cite jklontz | |
| 28 | - */ | |
| 29 | -class RGTransform : public UntrainableTransform | |
| 30 | -{ | |
| 31 | - Q_OBJECT | |
| 32 | - | |
| 33 | - void project(const Template &src, Template &dst) const | |
| 34 | - { | |
| 35 | - if (src.m().type() != CV_8UC3) | |
| 36 | - qFatal("Expected CV_8UC3 images."); | |
| 37 | - | |
| 38 | - const Mat &m = src.m(); | |
| 39 | - Mat R(m.size(), CV_8UC1); // R / (R+G+B) | |
| 40 | - Mat G(m.size(), CV_8UC1); // G / (R+G+B) | |
| 41 | - | |
| 42 | - for (int i=0; i<m.rows; i++) | |
| 43 | - for (int j=0; j<m.cols; j++) { | |
| 44 | - Vec3b v = m.at<Vec3b>(i,j); | |
| 45 | - const int b = v[0]; | |
| 46 | - const int g = v[1]; | |
| 47 | - const int r = v[2]; | |
| 48 | - const int sum = b + g + r; | |
| 49 | - if (sum > 0) { | |
| 50 | - R.at<uchar>(i, j) = saturate_cast<uchar>(255.0*r/(r+g+b)); | |
| 51 | - G.at<uchar>(i, j) = saturate_cast<uchar>(255.0*g/(r+g+b)); | |
| 52 | - } else { | |
| 53 | - R.at<uchar>(i, j) = 0; | |
| 54 | - G.at<uchar>(i, j) = 0; | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | - dst.append(R); | |
| 59 | - dst.append(G); | |
| 60 | - } | |
| 61 | -}; | |
| 62 | - | |
| 63 | -BR_REGISTER(Transform, RGTransform) | |
| 64 | - | |
| 65 | -} // namespace br | |
| 66 | - | |
| 67 | -#include "imgproc/rg.moc" |
openbr/plugins/imgproc/rndsubspace.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 Generates a random subspace. | |
| 31 | - * \author Josh Klontz \cite jklontz | |
| 32 | - */ | |
| 33 | -class RndSubspaceTransform : public MetaTransform | |
| 34 | -{ | |
| 35 | - Q_OBJECT | |
| 36 | - Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false) | |
| 37 | - Q_PROPERTY(bool weighted READ get_weighted WRITE set_weighted RESET reset_weighted STORED false) | |
| 38 | - BR_PROPERTY(float, fraction, 0.5) | |
| 39 | - BR_PROPERTY(bool, weighted, false) | |
| 40 | - | |
| 41 | - QList<Mat> maps; | |
| 42 | - | |
| 43 | - void train(const TemplateList &data) | |
| 44 | - { | |
| 45 | - // While RndSubspace transform could be independent, making it a MetaTransform is a workaround | |
| 46 | - // for parallel random number generation being difficult on Windows due to thread-local | |
| 47 | - // RNG states all initialized with the same seed and thus producing the same sequence of random numbers. | |
| 48 | - for (int index=0; index<data.first().size(); index++) { | |
| 49 | - const int cols = data.first()[index].cols; | |
| 50 | - const int size = data.first()[index].rows * cols; | |
| 51 | - QList<float> weights; weights.reserve(size); | |
| 52 | - if (weighted) { | |
| 53 | - Mat flatData = OpenCVUtils::toMat(data.data()); | |
| 54 | - for (int i=0; i<size; i++) { | |
| 55 | - Scalar mean, stddev; | |
| 56 | - cv::meanStdDev(flatData.col(i), mean, stddev); | |
| 57 | - weights.append(pow(stddev[0],2.0)); | |
| 58 | - } | |
| 59 | - } else { | |
| 60 | - for (int i=0; i<size; i++) | |
| 61 | - weights.append(1); | |
| 62 | - } | |
| 63 | - const int dimsOut = std::max(int(weights.size()*fraction), 1); | |
| 64 | - | |
| 65 | - QList<int> sample = Common::RandSample(dimsOut, weights); | |
| 66 | - Mat xMap(1, dimsOut, CV_16SC1); | |
| 67 | - Mat yMap(1, dimsOut, CV_16SC1); | |
| 68 | - for (int j=0; j<dimsOut; j++) { | |
| 69 | - int index = sample[j]; | |
| 70 | - xMap.at<short>(0,j) = index % cols; | |
| 71 | - yMap.at<short>(0,j) = index / cols; | |
| 72 | - } | |
| 73 | - std::vector<Mat> mv; | |
| 74 | - mv.push_back(xMap); | |
| 75 | - mv.push_back(yMap); | |
| 76 | - | |
| 77 | - Mat map; | |
| 78 | - merge(mv, map); | |
| 79 | - maps.append(map); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - void project(const Template &src, Template &dst) const | |
| 84 | - { | |
| 85 | - dst.file = src.file; | |
| 86 | - for (int i=0; i<src.size(); i++) { | |
| 87 | - Mat m; | |
| 88 | - remap(src, m, maps[i], Mat(), INTER_NEAREST); | |
| 89 | - dst.append(m); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - void store(QDataStream &stream) const | |
| 94 | - { | |
| 95 | - stream << maps; | |
| 96 | - } | |
| 97 | - | |
| 98 | - void load(QDataStream &stream) | |
| 99 | - { | |
| 100 | - stream >> maps; | |
| 101 | - } | |
| 102 | -}; | |
| 103 | - | |
| 104 | -BR_REGISTER(Transform, RndSubspaceTransform) | |
| 105 | - | |
| 106 | -} // namespace br | |
| 107 | - | |
| 108 | -#include "imgproc/rndsubspace.moc" |