Commit 0fdd8a12 authored by Patrik Huber's avatar Patrik Huber

Changed "unnormalised" basis to "orthonormal", and "normalised" to "rescaled"

This should clear up confusion and make the descriptions good and unambiguous.

- orthonormal = the old "unnormalised"
- rescaled = the old "normalised".

Also changed PcaModel's getter for the basis accordingly, and updated the documentation.
parent fd088862
......@@ -314,7 +314,7 @@ std::array<T, 3> get_shape_point(const morphablemodel::PcaModel& shape_model, co
{
int num_coeffs_fitting = 10; // Todo: Should be inferred or a function parameter!
auto mean = shape_model.get_mean_at_point(vertex_id);
auto basis = shape_model.get_normalised_pca_basis(vertex_id);
auto basis = shape_model.get_rescaled_pca_basis(vertex_id);
// Computing Shape = mean + basis * coeffs:
// Note: Could use an Eigen matrix with type T to see if it gives a speedup.
std::array<T, 3> point{ T(mean[0]), T(mean[1]), T(mean[2]) };
......@@ -355,7 +355,7 @@ std::array<T, 3> get_vertex_colour(const morphablemodel::PcaModel& color_model,
{
int num_coeffs_fitting = 10; // Todo: Should be inferred or a function parameter!
auto mean = color_model.get_mean_at_point(vertex_id);
auto basis = color_model.get_normalised_pca_basis(vertex_id);
auto basis = color_model.get_rescaled_pca_basis(vertex_id);
// Computing Colour = mean + basis * coeffs
// Note: Could use an Eigen matrix with type T to see if it gives a speedup.
std::array<T, 3> point{ T(mean[0]), T(mean[1]), T(mean[2]) };
......
......@@ -75,7 +75,7 @@ inline std::vector<float> fit_shape_to_landmarks_linear(const morphablemodel::Mo
Mat V_hat_h = Mat::zeros(4 * num_landmarks, num_coeffs_to_fit, CV_32FC1);
int row_index = 0;
for (int i = 0; i < num_landmarks; ++i) {
auto basis_rows_ = morphable_model.get_shape_model().get_normalised_pca_basis(vertex_ids[i]); // In the paper, the not-normalised basis might be used? I'm not sure, check it. It's even a mess in the paper. PH 26.5.2014: I think the normalised basis is fine/better.
auto basis_rows_ = morphable_model.get_shape_model().get_rescaled_pca_basis(vertex_ids[i]); // In the paper, the orthonormal basis might be used? I'm not sure, check it. It's even a mess in the paper. PH 26.5.2014: I think the rescaled basis is fine/better.
Mat basis_rows = Mat(basis_rows_.rows(), basis_rows_.cols(), CV_32FC1, basis_rows_.data());
//basisRows.copyTo(V_hat_h.rowRange(rowIndex, rowIndex + 3));
basis_rows.colRange(0, num_coeffs_to_fit).copyTo(V_hat_h.rowRange(row_index, row_index + 3));
......
This diff is collapsed.
......@@ -157,7 +157,7 @@ inline MorphableModel load_scm_model(boost::filesystem::path model_filename, boo
Eigen::Map<RowMajorMatrixXf> unnormalisedPcaBasisShape_(unnormalisedPcaBasisShape.ptr<float>(), unnormalisedPcaBasisShape.rows, unnormalisedPcaBasisShape.cols);
Eigen::Map<RowMajorMatrixXf> eigenvaluesShape_(eigenvaluesShape.ptr<float>(), eigenvaluesShape.rows, eigenvaluesShape.cols);
Eigen::Map<RowMajorMatrixXf> meanShape_(meanShape.ptr<float>(), meanShape.rows, meanShape.cols);
Eigen::MatrixXf normalisedPcaBasisShape_ = normalise_pca_basis(unnormalisedPcaBasisShape_, eigenvaluesShape_);
Eigen::MatrixXf normalisedPcaBasisShape_ = rescale_pca_basis(unnormalisedPcaBasisShape_, eigenvaluesShape_);
PcaModel shapeModel(meanShape_, normalisedPcaBasisShape_, eigenvaluesShape_, triangleList);
// Reading the color model
......@@ -209,7 +209,7 @@ inline MorphableModel load_scm_model(boost::filesystem::path model_filename, boo
Eigen::Map<RowMajorMatrixXf> unnormalisedPcaBasisColor_(unnormalisedPcaBasisColor.ptr<float>(), unnormalisedPcaBasisColor.rows, unnormalisedPcaBasisColor.cols);
Eigen::Map<RowMajorMatrixXf> eigenvaluesColor_(eigenvaluesColor.ptr<float>(), eigenvaluesColor.rows, eigenvaluesColor.cols);
Eigen::Map<RowMajorMatrixXf> meanColor_(meanColor.ptr<float>(), meanColor.rows, meanColor.cols);
Eigen::MatrixXf normalisedPcaBasisColor_ = normalise_pca_basis(unnormalisedPcaBasisColor_, eigenvaluesColor_);
Eigen::MatrixXf normalisedPcaBasisColor_ = rescale_pca_basis(unnormalisedPcaBasisColor_, eigenvaluesColor_);
PcaModel colorModel(meanColor_, normalisedPcaBasisColor_, eigenvaluesColor_, triangleList);
modelFile.close();
......
......@@ -94,7 +94,8 @@ PYBIND11_PLUGIN(eos) {
.def("get_triangle_list", &morphablemodel::PcaModel::get_triangle_list, "Returns a list of triangles on how to assemble the vertices into a mesh.")
.def("get_mean", &morphablemodel::PcaModel::get_mean, "Returns the mean of the model.")
.def("get_mean_at_point", &morphablemodel::PcaModel::get_mean_at_point, "Return the value of the mean at a given vertex index.", py::arg("vertex_index"))
.def("get_normalised_pca_basis", [](const morphablemodel::PcaModel& m) { return m.get_normalised_pca_basis(); }, "Returns the PCA basis matrix, i.e. the eigenvectors. Each column of the matrix is an eigenvector.") // use py::overload in VS2017
.def("get_orthonormal_pca_basis", [](const morphablemodel::PcaModel& m) { return m.get_orthonormal_pca_basis(); }, "Returns the orthonormal PCA basis matrix, i.e. the eigenvectors. Each column of the matrix is an eigenvector.") // use py::overload in VS2017
.def("get_rescaled_pca_basis", [](const morphablemodel::PcaModel& m) { return m.get_rescaled_pca_basis(); }, "Returns the rescaled PCA basis matrix, i.e. the eigenvectors. Each column of the matrix is an eigenvector, and each eigenvector has been rescaled by multiplying it with the square root of its eigenvalue.") // use py::overload in VS2017
.def("get_eigenvalues", &morphablemodel::PcaModel::get_eigenvalues, "Returns the models eigenvalues.")
.def("draw_sample", (Eigen::VectorXf(morphablemodel::PcaModel::*)(std::vector<float>) const)&morphablemodel::PcaModel::draw_sample, "Returns a sample from the model with the given PCA coefficients. The given coefficients should follow a standard normal distribution, i.e. not be scaled with their eigenvalues/variances.", py::arg("coefficients"))
;
......
......@@ -11,7 +11,7 @@
%
% Developer notes:
% - The BFM data type is single, SFM is double
% - The BFM Matlab file contains the "unnormalised", orthonormal basis
% - The BFM Matlab file contains the orthonormal basis
% (as do the Surrey .scm files).
% - Domains:
% Colour: BFM: [0, 255], SFM: [0, 1].
......
......@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
}
// We read the orthonormal basis from the file. Now let's rescale it and store the rescaled basis separately.
const auto rescaled_pca_basis_shape = morphablemodel::normalise_pca_basis(orthonormal_pca_basis_shape, eigenvalues_shape);
const auto rescaled_pca_basis_shape = morphablemodel::rescale_pca_basis(orthonormal_pca_basis_shape, eigenvalues_shape);
morphablemodel::PcaModel shape_model(mean_shape, rescaled_pca_basis_shape, eigenvalues_shape, triangle_list);
// Reading the colour (albedo) model:
......@@ -226,7 +226,7 @@ int main(int argc, char *argv[])
}
// We read the orthonormal basis from the file. Now let's rescale it and store the rescaled basis separately.
const auto rescaled_pca_basis_color = morphablemodel::normalise_pca_basis(orthonormal_pca_basis_color, eigenvalues_color);
const auto rescaled_pca_basis_color = morphablemodel::rescale_pca_basis(orthonormal_pca_basis_color, eigenvalues_color);
morphablemodel::PcaModel color_model(mean_color, rescaled_pca_basis_color, eigenvalues_color, triangle_list);
file.close();
......
Markdown is supported
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