11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit d2d403bc authored by schultezub's avatar schultezub

* fixed issues in RandomWalksLib regarding copy-construction/assignment of ConfidenceMaps2DFacade

 * fixed and parallelized ConfidenceMapGenerator

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@453 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 27df6733
#include "ConfidenceMaps2DFacade.h"
#include "ConfidenceMaps2D.h"
ConfidenceMaps2DFacade::ConfidenceMaps2DFacade()
{
maps2D = new ConfidenceMaps2D();
}
ConfidenceMaps2DFacade::~ConfidenceMaps2DFacade()
{
if(maps2D!=0)
delete maps2D;
maps2D = 0;
}
std::vector<double> ConfidenceMaps2DFacade::computeMap(double beta, double gamma)
{
maps2D->setBeta(beta);
maps2D->setGamma(gamma);
maps2D.setBeta(beta);
maps2D.setGamma(gamma);
std::vector<double> map;
map = maps2D->solve();
map = maps2D.solve();
return map;
}
void ConfidenceMaps2DFacade::setImage(std::vector<double> &image, int rows, int cols, double alpha, bool normalizeValues)
{
maps2D->setAlpha(alpha);
maps2D->setMatrix2D(&image,rows,cols,normalizeValues);
maps2D.setAlpha(alpha);
maps2D.setMatrix2D(&image,rows,cols,normalizeValues);
this->seeds.clear();
this->labels.clear();
......@@ -59,10 +55,10 @@ void ConfidenceMaps2DFacade::setImage(std::vector<double> &image, int rows, int
labels.push_back(1);
}
maps2D->setLabeling(&seeds,&labels,0,2);
maps2D.setLabeling(&seeds,&labels,0,2);
}
void ConfidenceMaps2DFacade::setSolver(std::string solver, int iterations, double tolerance)
{
maps2D->setSolver(solver,iterations,tolerance);
maps2D.setSolver(solver,iterations,tolerance);
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
#ifndef CONFIDENCE_MAPS_2D_FACADE_H__
#define CONFIDENCE_MAPS_2D_FACADE_H__
#include "ConfidenceMaps2D.h"
#include <vector>
/** \brief Facade for computing confidence map for 2D image
......@@ -36,7 +37,7 @@ public:
/// Set desired solver (default Eigen LLT)
void setSolver(std::string solver, int iterations = 2000, double tolerance = 1.0e-7);
private:
ConfidenceMaps2D * maps2D; ///< Implementation of confidence estimation
ConfidenceMaps2D maps2D; ///< Implementation of confidence estimation
std::vector<int> seeds; ///< Seeds/boundary conditions
std::vector<int> labels; ///< Labels for seeds
};
......
......@@ -29,6 +29,7 @@
#include "confidencemapgenerator.h"
#include "tbb/tbb.h"
#include "tgt/logmanager.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
......@@ -39,11 +40,78 @@
namespace campvis {
static const GenericOption<std::string> filterModes[2] = {
GenericOption<std::string>("median", "Median"),
GenericOption<std::string>("gauss", "Gauss"),
static const GenericOption<std::string> solvers[4] = {
GenericOption<std::string>("Eigen-LLT", "Eigen-LLT"),
GenericOption<std::string>("Eigen-CG", "Eigen-CG"),
GenericOption<std::string>("Eigen-BiCGSTAB", "Eigen-BiCGSTAB"),
GenericOption<std::string>("Eigen-CG-Custom", "Eigen-CG-Custom"),
};
class CMGenerator {
public:
CMGenerator(const ImageRepresentationLocal* input, float* output, const std::string& solver, float alpha, float beta, float gamma, bool normalizeValues)
: _input(input)
, _output(output)
, _solver(solver)
, _alpha(alpha)
, _beta(beta)
, _gamma(gamma)
, _normalizeValues(normalizeValues)
{
tgtAssert(input != 0, "Pointer to Input must not be 0.");
tgtAssert(output != 0, "Pointer to Output must not be 0.");
_numElementsPerSlice = tgt::hmul(_input->getSize().xy());
}
void operator() (const tbb::blocked_range<size_t>& range) const {
// Get each slice of the range through the confidence map generator
ConfidenceMaps2DFacade _cmGenerator;
_cmGenerator.setSolver(_solver);
std::vector<double> inputValues;
const tgt::svec3& imageSize = _input->getSize();
inputValues.resize(_numElementsPerSlice);
size_t offset = _numElementsPerSlice * range.begin();
for (size_t slice = range.begin(); slice < range.end(); ++slice) {
// Since the confidence map generator expects a vector of double, we need to copy the image data...
// meanwhile, we transform the pixel order to column-major:
for (size_t i = 0; i < _numElementsPerSlice; ++i) {
size_t row = i / imageSize.y;
size_t column = i % imageSize.y;
size_t index = row + imageSize.x * column;
inputValues[i] = static_cast<double>(_input->getElementNormalized(index + offset, 0));
}
// compute confidence map
_cmGenerator.setImage(inputValues, _input->getSize().y, _input->getSize().x, _alpha, _normalizeValues);
std::vector<double> tmp = _cmGenerator.computeMap(_beta, _gamma);
// copy back
for (size_t i = 0; i < _numElementsPerSlice; ++i) {
size_t row = i / imageSize.y;
size_t column = i % imageSize.y;
size_t index = row + imageSize.x * column;
_output[index + offset] = static_cast<float>(tmp[i]);
}
offset += _numElementsPerSlice;
}
}
protected:
const ImageRepresentationLocal* _input;
float* _output;
size_t _numElementsPerSlice;
std::string _solver;
float _alpha;
float _beta;
float _gamma;
bool _normalizeValues;
};
// ================================================================================================
const std::string ConfidenceMapGenerator::loggerCat_ = "CAMPVis.modules.classification.ConfidenceMapGenerator";
ConfidenceMapGenerator::ConfidenceMapGenerator()
......@@ -54,7 +122,7 @@ namespace campvis {
, p_beta("Beta", "Beta Parameter", 100.f, 1.f, 1000.f)
, p_gamma("Gamma", "Gamma Parameter", .06f, .01f, 1.f)
, p_normalizeValues("NormalizeValues", "Noramlize Values", false)
, p_solver("FilterMode", "Filter Mode", filterModes, 2)
, p_solver("FilterMode", "Filter Mode", solvers, 4)
{
addProperty(&p_sourceImageID);
addProperty(&p_targetImageID);
......@@ -75,32 +143,11 @@ namespace campvis {
if (input != 0 && input->getDimensionality() >= 2 && input->getParent()->getNumChannels() == 1) {
const tgt::svec3& imageSize = input->getSize();
size_t numElements = input->getNumElements();
size_t numElementsPerSlice = tgt::hmul(imageSize.xy());
ConfidenceMaps2DFacade cmGenerator;
std::vector<double> inputValues;
inputValues.resize(numElementsPerSlice);
float* outputValues = new float[numElements];
// Get each slice through the confidence map generator
size_t offset = 0;
for (size_t slice = 0; slice < imageSize.z; ++slice) {
// Since the confidence map generator expects a vector of double, we need to copy the image data...
for (size_t i = 0; i < numElementsPerSlice; ++i) {
inputValues[i] = static_cast<double>(input->getElementNormalized(i + offset, 0));
}
// compute confidence map
cmGenerator.setImage(inputValues, imageSize.x, imageSize.y, p_alpha.getValue(), p_normalizeValues.getValue());
std::vector<double> tmp = cmGenerator.computeMap(p_beta.getValue(), p_gamma.getValue());
// copy back
for (size_t i = 0; i < numElementsPerSlice; ++i) {
outputValues[i + offset] = static_cast<float>(tmp[i]);
}
offset += numElementsPerSlice;
}
tbb::parallel_for(
tbb::blocked_range<size_t>(0, imageSize.z, imageSize.z),
CMGenerator(input, outputValues, p_solver.getOptionValue(), p_alpha.getValue(), p_beta.getValue(), p_gamma.getValue(), p_normalizeValues.getValue()));
ImageData* output = new ImageData(input->getDimensionality(), input->getSize(), 1);
GenericImageRepresentationLocal<float, 1>* confidenceMap = GenericImageRepresentationLocal<float, 1>::create(output, outputValues);
......
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