Commit 75a21481701e3c817e70d6be1d97773aca590e64
1 parent
99dd9000
added support for non-square identity matricies
Showing
2 changed files
with
22 additions
and
13 deletions
sdk/core/bee.cpp
| ... | ... | @@ -112,25 +112,32 @@ template <typename T> |
| 112 | 112 | Mat readMatrix(const br::File &matrix) |
| 113 | 113 | { |
| 114 | 114 | // Special case matrix construction |
| 115 | - if (matrix == "Matrix") { | |
| 116 | - const int size = matrix.getInt("Size"); | |
| 117 | - const int step = matrix.getInt("Step", 1); | |
| 118 | - if (size % step != 0) qFatal("Step does not divide size evenly."); | |
| 115 | + if (matrix == "Identity") { | |
| 116 | + int rows = matrix.getInt("rows", -1); | |
| 117 | + int columns = matrix.getInt("columns", -1); | |
| 118 | + const int size = matrix.getInt("size", -1); | |
| 119 | + if (size != -1) { | |
| 120 | + if (rows == -1) rows = size; | |
| 121 | + if (columns == -1) columns = size; | |
| 122 | + } | |
| 123 | + const int step = matrix.getInt("step", 1); | |
| 124 | + if (rows % step != 0) qFatal("Step does not divide rows evenly."); | |
| 125 | + if (columns % step != 0) qFatal("Step does not divide columns evenly."); | |
| 119 | 126 | |
| 120 | 127 | if (sizeof(T) == sizeof(BEE::Mask_t)) { |
| 121 | - const bool selfSimilar = matrix.getBool("SelfSimilar"); | |
| 128 | + const bool selfSimilar = matrix.getBool("selfSimilar"); | |
| 122 | 129 | |
| 123 | - Mat m(size, size, CV_8UC1); | |
| 130 | + Mat m(rows, columns, CV_8UC1); | |
| 124 | 131 | m.setTo(BEE::NonMatch); |
| 125 | - for (int i=0; i<size; i+=step) | |
| 132 | + for (int i=0; i<std::min(rows, columns); i+=step) | |
| 126 | 133 | for (int j=0; j<step; j++) |
| 127 | 134 | for (int k=0; k<step; k++) |
| 128 | 135 | m.at<BEE::Mask_t>(i+j,i+k) = ((selfSimilar && (j == k)) ? BEE::DontCare : BEE::Match); |
| 129 | 136 | return m; |
| 130 | 137 | } else if (sizeof(T) == sizeof(BEE::Simmat_t)) { |
| 131 | - Mat m(size, size, CV_32FC1); | |
| 132 | - m.setTo(BEE::NonMatch); | |
| 133 | - for (int i=0; i<size; i+=step) | |
| 138 | + Mat m(rows, columns, CV_32FC1); | |
| 139 | + m.setTo(0); | |
| 140 | + for (int i=0; i<std::min(rows, columns); i+=step) | |
| 134 | 141 | for (int j=0; j<step; j++) |
| 135 | 142 | for (int k=0; k<step; k++) |
| 136 | 143 | m.at<BEE::Simmat_t>(i+j,i+k) = 1; |
| ... | ... | @@ -140,7 +147,7 @@ Mat readMatrix(const br::File &matrix) |
| 140 | 147 | |
| 141 | 148 | QFile file(matrix); |
| 142 | 149 | bool success = file.open(QFile::ReadOnly); |
| 143 | - if (!success) qFatal("Unable to open %s for reading.", qPrintable((QString)matrix)); | |
| 150 | + if (!success) qFatal("Unable to open %s for reading.", qPrintable(matrix.name)); | |
| 144 | 151 | |
| 145 | 152 | // Check format |
| 146 | 153 | QByteArray format = file.readLine(); |
| ... | ... | @@ -164,7 +171,7 @@ Mat readMatrix(const br::File &matrix) |
| 164 | 171 | file.close(); |
| 165 | 172 | |
| 166 | 173 | Mat result; |
| 167 | - if (isDistance ^ matrix.getBool("Negate")) m.convertTo(result, -1, -1); | |
| 174 | + if (isDistance ^ matrix.getBool("negate")) m.convertTo(result, -1, -1); | |
| 168 | 175 | else result = m.clone(); |
| 169 | 176 | return result; |
| 170 | 177 | } | ... | ... |
sdk/core/plot.cpp
| ... | ... | @@ -118,7 +118,9 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) |
| 118 | 118 | |
| 119 | 119 | // Read files |
| 120 | 120 | const Mat scores = BEE::readSimmat(simmat); |
| 121 | - File maskFile(mask); maskFile.insert("Size", scores.rows); | |
| 121 | + File maskFile(mask); | |
| 122 | + maskFile.insert("rows", scores.rows); | |
| 123 | + maskFile.insert("columns", scores.cols); | |
| 122 | 124 | const Mat masks = BEE::readMask(maskFile); |
| 123 | 125 | if (scores.size() != masks.size()) qFatal("Simmat/Mask size mismatch."); |
| 124 | 126 | ... | ... |