Commit 0bd6724f authored by remicres's avatar remicres
Browse files

REFAC: clean functions prototypes (remove some unused variables)

parent 972a814a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "lsrmGetInternalMemory.h" #include "lsrmGetInternalMemory.h"
#include "lsgrmSplitter.h" #include "lsgrmSplitter.h"
#include "lsgrmGraphOperations.h" #include "lsgrmGraphOperations.h"
#include "itkMacro.h"
namespace lsgrm namespace lsgrm
{ {
...@@ -28,7 +29,8 @@ namespace lsgrm ...@@ -28,7 +29,8 @@ namespace lsgrm
void SetTemporaryDirectory(const std::string& str); void SetTemporaryDirectory(const std::string& str);
void SetTileWidth(const unsigned int v); void SetTileWidth(const unsigned int v);
void SetTileHeight(const unsigned int v); void SetTileHeight(const unsigned int v);
void SetNumberOfFirstIterations(const unsigned int v); void SetNumberOfFirstIterations(const unsigned int v);
void SetNumberOfIterations(const unsigned int v);
void SetSpecificParameters(const SegmentationParameterType& params); void SetSpecificParameters(const SegmentationParameterType& params);
void SetThreshold(const float& t); void SetThreshold(const float& t);
void SetInternalMemoryAvailable(long long unsigned int v); // expecting a value in Mbytes. void SetInternalMemoryAvailable(long long unsigned int v); // expecting a value in Mbytes.
...@@ -36,6 +38,8 @@ namespace lsgrm ...@@ -36,6 +38,8 @@ namespace lsgrm
typename LabelImageType::Pointer GetLabeledClusteredOutput(); typename LabelImageType::Pointer GetLabeledClusteredOutput();
itkGetMacro(ListOfTemporaryFiles, std::vector<std::string>);
private: private:
void GetAutomaticConfiguration(); void GetAutomaticConfiguration();
...@@ -55,13 +59,15 @@ namespace lsgrm ...@@ -55,13 +59,15 @@ namespace lsgrm
/* Internal attribute members.*/ /* Internal attribute members.*/
unsigned int m_NbTilesX; unsigned int m_NbTilesX;
unsigned int m_NbTilesY; unsigned int m_NbTilesY;
unsigned int m_NumberOfFirstIterations; unsigned int m_NumberOfFirstIterations;
unsigned int m_NumberOfIterations;
unsigned int m_Margin; unsigned int m_Margin;
unsigned int m_TileWidth; unsigned int m_TileWidth;
unsigned int m_TileHeight; unsigned int m_TileHeight;
bool m_AutomaticTilingLayout; bool m_AutomaticTilingLayout;
std::vector<ProcessingTile> m_Tiles; std::vector<ProcessingTile> m_Tiles;
std::vector<std::string> m_ListOfTemporaryFiles;
typename LabelImageType::Pointer m_LabelImage; typename LabelImageType::Pointer m_LabelImage;
}; };
......
...@@ -19,8 +19,12 @@ template<class TSegmenter> ...@@ -19,8 +19,12 @@ template<class TSegmenter>
void Controller<TSegmenter>::RunSegmentation() void Controller<TSegmenter>::RunSegmentation()
{ {
// TODO: smarter value?
const unsigned int numberOfIterationsForPartialSegmentations = 3;
unsigned int numberOfIterations = m_NumberOfIterations;
// Automatic procedure // Automatic procedure
if(m_Memory < 1) if(m_Memory == 0)
{ {
this->GetAutomaticConfiguration(); this->GetAutomaticConfiguration();
} }
...@@ -45,17 +49,18 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -45,17 +49,18 @@ void Controller<TSegmenter>::RunSegmentation()
m_SpecificParameters, m_SpecificParameters,
m_Threshold, m_Threshold,
m_NumberOfFirstIterations, m_NumberOfFirstIterations,
3, numberOfIterationsForPartialSegmentations,
m_Tiles, m_Tiles,
m_NbTilesX, m_NbTilesX,
m_NbTilesY, m_NbTilesY,
m_TileWidth, m_TileWidth,
m_TileHeight, m_TileHeight,
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
m_InputImage->GetLargestPossibleRegion().GetSize()[1],
m_TemporaryDirectory, m_TemporaryDirectory,
isFusion); isFusion);
// Update the given number of iterations
numberOfIterations -= m_NumberOfFirstIterations;
// Gathering useful variables // Gathering useful variables
GatherUsefulVariables(accumulatedMemory, isFusion); GatherUsefulVariables(accumulatedMemory, isFusion);
...@@ -69,7 +74,7 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -69,7 +74,7 @@ void Controller<TSegmenter>::RunSegmentation()
accumulatedMemory = RunPartialSegmentation<TSegmenter>( accumulatedMemory = RunPartialSegmentation<TSegmenter>(
m_SpecificParameters, m_SpecificParameters,
m_Threshold, m_Threshold,
3, numberOfIterationsForPartialSegmentations,
m_Tiles, m_Tiles,
m_TemporaryDirectory, m_TemporaryDirectory,
m_NbTilesX, m_NbTilesX,
...@@ -79,6 +84,9 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -79,6 +84,9 @@ void Controller<TSegmenter>::RunSegmentation()
m_InputImage->GetNumberOfComponentsPerPixel(), m_InputImage->GetNumberOfComponentsPerPixel(),
isFusion); isFusion);
// Update the given number of iterations
numberOfIterations -= numberOfIterationsForPartialSegmentations;
// Gathering useful variables // Gathering useful variables
GatherUsefulVariables(accumulatedMemory, isFusion); GatherUsefulVariables(accumulatedMemory, isFusion);
...@@ -104,7 +112,8 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -104,7 +112,8 @@ void Controller<TSegmenter>::RunSegmentation()
m_NbTilesY, m_NbTilesY,
m_InputImage->GetLargestPossibleRegion().GetSize()[0], m_InputImage->GetLargestPossibleRegion().GetSize()[0],
m_InputImage->GetLargestPossibleRegion().GetSize()[1], m_InputImage->GetLargestPossibleRegion().GetSize()[1],
m_InputImage->GetNumberOfComponentsPerPixel()); m_InputImage->GetNumberOfComponentsPerPixel(),
numberOfIterations);
// ShowTime(t); // ShowTime(t);
...@@ -280,6 +289,12 @@ void Controller<TSegmenter>::SetNumberOfFirstIterations(const unsigned int v) ...@@ -280,6 +289,12 @@ void Controller<TSegmenter>::SetNumberOfFirstIterations(const unsigned int v)
m_Margin = static_cast<unsigned int>(pow(2, m_NumberOfFirstIterations + 1) - 2);// 2^{n+1}-2 m_Margin = static_cast<unsigned int>(pow(2, m_NumberOfFirstIterations + 1) - 2);// 2^{n+1}-2
} }
template<class TSegmenter>
void Controller<TSegmenter>::SetNumberOfIterations(const unsigned int v)
{
m_NumberOfIterations = v;
}
template<class TSegmenter> template<class TSegmenter>
void Controller<TSegmenter>::SetSpecificParameters(const SegmentationParameterType& params) void Controller<TSegmenter>::SetSpecificParameters(const SegmentationParameterType& params)
{ {
......
...@@ -35,7 +35,8 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -35,7 +35,8 @@ MergeAllGraphsAndAchieveSegmentation(
const unsigned int nbTilesY, const unsigned int nbTilesY,
const unsigned int imageWidth, const unsigned int imageWidth,
const unsigned int imageHeight, const unsigned int imageHeight,
const unsigned int imageBands); const unsigned int imageBands,
unsigned int numberOfIterations);
template<class TSegmenter> template<class TSegmenter>
long long unsigned int RunFirstPartialSegmentation( long long unsigned int RunFirstPartialSegmentation(
...@@ -49,8 +50,6 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -49,8 +50,6 @@ long long unsigned int RunFirstPartialSegmentation(
const unsigned int nbTilesY, const unsigned int nbTilesY,
const unsigned int tileWidth, const unsigned int tileWidth,
const unsigned int tileHeight, const unsigned int tileHeight,
const unsigned int imageWidth,
const unsigned int imageHeight,
const std::string& tmpDir, const std::string& tmpDir,
bool& isFusion); bool& isFusion);
......
...@@ -32,7 +32,8 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -32,7 +32,8 @@ MergeAllGraphsAndAchieveSegmentation(
const unsigned int nbTilesY, const unsigned int nbTilesY,
const unsigned int imageWidth, const unsigned int imageWidth,
const unsigned int imageHeight, const unsigned int imageHeight,
const unsigned int imageBands) const unsigned int imageBands,
unsigned int numberOfIterations)
{ {
// TODO parallelize this ... // TODO parallelize this ...
...@@ -104,7 +105,7 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -104,7 +105,7 @@ MergeAllGraphsAndAchieveSegmentation(
segmenter.SetParam(params); segmenter.SetParam(params);
segmenter.SetThreshold(threshold); segmenter.SetThreshold(threshold);
segmenter.SetDoBFSegmentation(true); segmenter.SetDoBFSegmentation(true);
segmenter.SetNumberOfIterations(75); segmenter.SetNumberOfIterations(numberOfIterations);
lsrm::GraphOperations<TSegmenter>::PerfomAllIterationsWithLMBFAndConstThreshold(segmenter); lsrm::GraphOperations<TSegmenter>::PerfomAllIterationsWithLMBFAndConstThreshold(segmenter);
...@@ -143,8 +144,9 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet ...@@ -143,8 +144,9 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
if (MyTurn(row*nbTilesX + col)) if (MyTurn(row*nbTilesX + col))
{ {
TSegmenter segmenter; TSegmenter segmenter;
std::cout << "Tile " << row << " " << col << std::endl; std::cout << "Processing tile " << row << ", " << col << std::endl;
std::cout << "\tLoad graph..." << std::endl; std::cout << "\tLoad graph..." << std::endl;
// Load the graph // Load the graph
nodesPath = tmpDir + "tile_nodes_" + std::to_string(row) + "_" + std::to_string(col) + ".bin"; nodesPath = tmpDir + "tile_nodes_" + std::to_string(row) + "_" + std::to_string(col) + ".bin";
edgesPath = tmpDir + "tile_edges_" + std::to_string(row) + "_" + std::to_string(col) + ".bin"; edgesPath = tmpDir + "tile_edges_" + std::to_string(row) + "_" + std::to_string(col) + ".bin";
...@@ -692,13 +694,13 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -692,13 +694,13 @@ long long unsigned int RunFirstPartialSegmentation(
const unsigned int nbTilesY, const unsigned int nbTilesY,
const unsigned int tileWidth, const unsigned int tileWidth,
const unsigned int tileHeight, const unsigned int tileHeight,
const unsigned int imageWidth,
const unsigned int imageHeight,
const std::string& tmpDir, const std::string& tmpDir,
bool& isFusion) bool& isFusion)
{ {
using ImageType = typename TSegmenter::ImageType; using ImageType = typename TSegmenter::ImageType;
const unsigned int imageWidth = inputPtr->GetLargestPossibleRegion().GetSize()[0];
const unsigned int imageHeight = inputPtr->GetLargestPossibleRegion().GetSize()[1];
long long unsigned int accumulatedMemory = 0; long long unsigned int accumulatedMemory = 0;
isFusion = false; isFusion = false;
...@@ -736,7 +738,7 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -736,7 +738,7 @@ long long unsigned int RunFirstPartialSegmentation(
isFusion = true; isFusion = true;
// Rescale the graph to be in the reference of the image // Rescale the graph to be in the reference of the image
std::cout << "\tRescale graph" << std::endl; std::cout << "\tRescaling graph..." << std::endl;
RescaleGraph<TSegmenter>(segmenter.m_Graph, RescaleGraph<TSegmenter>(segmenter.m_Graph,
tiles[row*nbTilesX + col], tiles[row*nbTilesX + col],
row, row,
...@@ -746,19 +748,20 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -746,19 +748,20 @@ long long unsigned int RunFirstPartialSegmentation(
imageWidth); imageWidth);
// Remove unstable segments // Remove unstable segments
std::cout << "\tRemoving unstable segments" << std::endl; std::cout << "\tRemoving unstable segments..." << std::endl;
RemoveUnstableSegments<TSegmenter>(segmenter.m_Graph, tiles[row*nbTilesX + col], imageWidth); RemoveUnstableSegments<TSegmenter>(segmenter.m_Graph, tiles[row*nbTilesX + col], imageWidth);
// Retrieve the amount of memory to store this graph // Retrieve the amount of memory to store this graph
std::cout << "\tGet graph memory" << std::endl; std::cout << "\tRetrieving graph memory..." << std::endl;
accumulatedMemory += GetGraphMemory<TSegmenter>(segmenter.m_Graph); accumulatedMemory += GetGraphMemory<TSegmenter>(segmenter.m_Graph);
// Write graph to temporay directory (warning specific to Baatz & Schape !!!) // Write graph to temporay directory (warning specific to Baatz & Schape !!!)
std::cout << "\tWrite graph" << std::endl; std::cout << "\tWriting graph..." << std::endl;
WriteGraph<TSegmenter>(segmenter.m_Graph, tmpDir, row, col); WriteGraph<TSegmenter>(segmenter.m_Graph, tmpDir, row, col);
// Extract stability margin for all borders different from 0 imageWidth-1 et imageHeight -1 // Extract stability margin for all borders different from 0 imageWidth-1 et imageHeight -1
// and write them to the stability margin // and write them to the stability margin
std::cout << "\tComputing stability margin..." << std::endl;
{ {
std::unordered_map<typename TSegmenter::NodePointerType, unsigned int> borderNodeMap; std::unordered_map<typename TSegmenter::NodePointerType, unsigned int> borderNodeMap;
...@@ -1230,34 +1233,37 @@ void RescaleGraph(typename TSegmenter::GraphType& graph, ...@@ -1230,34 +1233,37 @@ void RescaleGraph(typename TSegmenter::GraphType& graph,
unsigned int rowNodeTile, colNodeTile; unsigned int rowNodeTile, colNodeTile;
unsigned int rowNodeImg, colNodeImg; unsigned int rowNodeImg, colNodeImg;
unsigned int currTileWidth = tile.columns[1] - tile.columns[0] + 1; // unsigned int currTileWidth = tile.columns[1] - tile.columns[0] + 1;
unsigned int diffHeightMargin = tile.margin[0]; // currTileWidth += tile.margin[1];
currTileWidth += tile.margin[1]; // currTileWidth += tile.margin[3];
unsigned int diffWidthMargin = tile.margin[3]; // unsigned int diffHeightMargin = tile.margin[0];
currTileWidth += tile.margin[3]; // unsigned int diffWidthMargin = tile.margin[3];
unsigned int count = 0;
for(auto& node : graph.m_Nodes) for(auto& node : graph.m_Nodes)
{ {
// Row of the start pixel of the node // // Row of the start pixel of the node
rowNodeTile = node->m_Id / currTileWidth; // rowNodeTile = node->m_Id / currTileWidth;
// Col of the start pixel of the node // // Col of the start pixel of the node
colNodeTile = node->m_Id % currTileWidth; // colNodeTile = node->m_Id % currTileWidth;
//
// Row of the start pixel of the node in the image // // Row of the start pixel of the node in the image
rowNodeImg = rowTile * tileHeight + rowNodeTile - diffHeightMargin; // rowNodeImg = rowTile * tileHeight + rowNodeTile - diffHeightMargin;
// Col of the start pixel of the node in the image // // Col of the start pixel of the node in the image
colNodeImg = colTile * tileWidth + colNodeTile - diffWidthMargin; // colNodeImg = colTile * tileWidth + colNodeTile - diffWidthMargin;
//
// New id of the node in the image // node->m_Id = rowNodeImg * imageWidth + colNodeImg;
rowNodeTile = node->m_Id / tile.region.GetSize()[0];
colNodeTile = node->m_Id % tile.region.GetSize()[0];
rowNodeImg = rowTile * tileHeight + rowNodeTile - tile.margin[0];
colNodeImg = colTile * tileWidth + colNodeTile - tile.margin[3];
node->m_Id = rowNodeImg * imageWidth + colNodeImg; node->m_Id = rowNodeImg * imageWidth + colNodeImg;
// Change also its bounding box // Change also its bounding box
node->m_Bbox.m_UX = colTile * tileWidth + node->m_Bbox.m_UX - diffWidthMargin; node->m_Bbox.m_UX = colTile * tileWidth + node->m_Bbox.m_UX - tile.margin[3];
node->m_Bbox.m_UY = rowTile * tileHeight + node->m_Bbox.m_UY - diffHeightMargin; node->m_Bbox.m_UY = rowTile * tileHeight + node->m_Bbox.m_UY - tile.margin[0];
++count;
} }
} }
} }
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