Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Cresson Remi
LSGRM
Commits
bb65d2e0
Commit
bb65d2e0
authored
Aug 23, 2016
by
remicres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REFAC: functions use ProcesingTiles instead of many numeric and string variables
parent
69882db5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
399 deletions
+121
-399
include/lsgrmController.h
include/lsgrmController.h
+6
-8
include/lsgrmController.txx
include/lsgrmController.txx
+7
-10
include/lsgrmGraphOperations.h
include/lsgrmGraphOperations.h
+18
-10
include/lsgrmGraphOperations.txx
include/lsgrmGraphOperations.txx
+90
-371
No files found.
include/lsgrmController.h
View file @
bb65d2e0
...
@@ -49,13 +49,12 @@ public:
...
@@ -49,13 +49,12 @@ public:
typename
LabelImageType
::
Pointer
GetLabeledClusteredOutput
();
typename
LabelImageType
::
Pointer
GetLabeledClusteredOutput
();
itkGetMacro
(
Margin
,
unsigned
int
);
itkGetMacro
(
Margin
,
unsigned
int
);
itkGetMacro
(
TemporaryFilesList
,
std
::
vector
<
std
::
string
>
);
itkGetMacro
(
CleanTemporary
Directory
,
bool
);
itkGetMacro
(
CleanTemporary
Files
,
bool
);
itkSetMacro
(
CleanTemporary
Directory
,
bool
);
itkSetMacro
(
CleanTemporary
Files
,
bool
);
itkGetMacro
(
Temporary
Directory
,
std
::
string
);
itkGetMacro
(
Temporary
FilesPrefix
,
std
::
string
);
itkSetMacro
(
Temporary
Directory
,
std
::
string
);
itkSetMacro
(
Temporary
FilesPrefix
,
std
::
string
);
itkGetMacro
(
Threshold
,
float
);
itkGetMacro
(
Threshold
,
float
);
itkSetMacro
(
Threshold
,
float
);
itkSetMacro
(
Threshold
,
float
);
...
@@ -94,8 +93,8 @@ private:
...
@@ -94,8 +93,8 @@ private:
long
unsigned
int
GetMaximumNumberOfNodesInMemory
();
long
unsigned
int
GetMaximumNumberOfNodesInMemory
();
/* Parameters given by the user */
/* Parameters given by the user */
std
::
string
m_Temporary
Directory
;
//
Directory
used to store intermediate files during the process.
std
::
string
m_Temporary
FilesPrefix
;
//
Path
used to store intermediate files during the process.
bool
m_CleanTemporary
Directory
;
// Clean
the
temporary
directory.
bool
m_CleanTemporary
Files
;
// Clean temporary
files
ImageType
*
m_InputImage
;
// Input image
ImageType
*
m_InputImage
;
// Input image
/* Segmentation parameters */
/* Segmentation parameters */
...
@@ -117,7 +116,6 @@ private:
...
@@ -117,7 +116,6 @@ private:
LSGRMTilingMode
m_TilingMode
;
// tiling mode (none/user/auto)
LSGRMTilingMode
m_TilingMode
;
// tiling mode (none/user/auto)
unsigned
int
m_Margin
;
// stability margin related to m_NumberOfFirstIterations
unsigned
int
m_Margin
;
// stability margin related to m_NumberOfFirstIterations
std
::
vector
<
ProcessingTile
>
m_Tiles
;
// list of tiles
std
::
vector
<
ProcessingTile
>
m_Tiles
;
// list of tiles
std
::
vector
<
std
::
string
>
m_TemporaryFilesList
;
// list of temporary files
typename
LabelImageType
::
Pointer
m_LabelImage
;
// output label image
typename
LabelImageType
::
Pointer
m_LabelImage
;
// output label image
};
};
}
// end of namespace lsgrm
}
// end of namespace lsgrm
...
...
include/lsgrmController.txx
View file @
bb65d2e0
...
@@ -14,7 +14,7 @@ Controller<TSegmenter>::Controller()
...
@@ -14,7 +14,7 @@ Controller<TSegmenter>::Controller()
m_TileWidth = 0;
m_TileWidth = 0;
m_NbTilesX = 0;
m_NbTilesX = 0;
m_NbTilesY = 0;
m_NbTilesY = 0;
m_CleanTemporary
Directory
= true;
m_CleanTemporary
Files
= true;
m_Threshold = 75;
m_Threshold = 75;
m_Memory = 0;
m_Memory = 0;
}
}
...
@@ -53,8 +53,8 @@ void Controller<TSegmenter>::RunSegmentation()
...
@@ -53,8 +53,8 @@ void Controller<TSegmenter>::RunSegmentation()
"\n\tTiling layout: " << m_NbTilesX << " x " << m_NbTilesY << std::endl;
"\n\tTiling layout: " << m_NbTilesX << " x " << m_NbTilesY << std::endl;
// Compute the splitting scheme
// Compute the splitting scheme
SplitOTBImage<ImageType>(m_InputImage, m_TileWidth, m_TileHeight, m_Margin,
m_Tiles =
SplitOTBImage<ImageType>(m_InputImage, m_TileWidth, m_TileHeight, m_Margin,
m_NbTilesX, m_NbTilesY, m_T
iles
);
m_NbTilesX, m_NbTilesY, m_T
emporaryFilesPrefix
);
// Boolean indicating if there are remaining fusions
// Boolean indicating if there are remaining fusions
bool isFusion = false;
bool isFusion = false;
...
@@ -72,9 +72,7 @@ void Controller<TSegmenter>::RunSegmentation()
...
@@ -72,9 +72,7 @@ void Controller<TSegmenter>::RunSegmentation()
m_NbTilesY,
m_NbTilesY,
m_TileWidth,
m_TileWidth,
m_TileHeight,
m_TileHeight,
m_TemporaryDirectory,
isFusion);
isFusion);
// long long unsigned int accumulatedMemory = 19373051714;
// Update the given number of iterations
// Update the given number of iterations
numberOfIterationsRemaining -= m_NumberOfFirstIterations;
numberOfIterationsRemaining -= m_NumberOfFirstIterations;
...
@@ -96,7 +94,6 @@ void Controller<TSegmenter>::RunSegmentation()
...
@@ -96,7 +94,6 @@ void Controller<TSegmenter>::RunSegmentation()
m_Threshold,
m_Threshold,
numberOfIterationsForPartialSegmentations,
numberOfIterationsForPartialSegmentations,
m_Tiles,
m_Tiles,
m_TemporaryDirectory,
m_NbTilesX,
m_NbTilesX,
m_NbTilesY,
m_NbTilesY,
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
...
@@ -127,7 +124,6 @@ void Controller<TSegmenter>::RunSegmentation()
...
@@ -127,7 +124,6 @@ void Controller<TSegmenter>::RunSegmentation()
m_SpecificParameters,
m_SpecificParameters,
m_Threshold,
m_Threshold,
m_Tiles,
m_Tiles,
m_TemporaryDirectory,
m_NbTilesX,
m_NbTilesX,
m_NbTilesY,
m_NbTilesY,
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
m_InputImage->GetLargestPossibleRegion().GetSize()[0],
...
@@ -176,7 +172,7 @@ unsigned int Controller<TSegmenter>::GetNodeMemory()
...
@@ -176,7 +172,7 @@ unsigned int Controller<TSegmenter>::GetNodeMemory()
lsrm::GraphOperations<TSegmenter>::InitNodes(onePixelImage,segmenter,FOUR);
lsrm::GraphOperations<TSegmenter>::InitNodes(onePixelImage,segmenter,FOUR);
unsigned int memory = segmenter.GetGraphMemory() / (n*n);
unsigned int memory = segmenter.GetGraphMemory() / (n*n);
itk
Warnin
gMacro(<<"Size of a node is " << memory);
itk
Debu
gMacro(<<"Size of a node is " << memory);
return memory;
return memory;
}
}
...
@@ -198,7 +194,8 @@ long unsigned int Controller<TSegmenter>::GetMaximumNumberOfNodesInMemory()
...
@@ -198,7 +194,8 @@ long unsigned int Controller<TSegmenter>::GetMaximumNumberOfNodesInMemory()
}
}
template<class TSegmenter>
template<class TSegmenter>
void Controller<TSegmenter>::ComputeMaximumStabilityMargin(unsigned int width,
void
Controller<TSegmenter>::ComputeMaximumStabilityMargin(unsigned int width,
unsigned int height, unsigned int &niter, unsigned int &margin)
unsigned int height, unsigned int &niter, unsigned int &margin)
{
{
itkDebugMacro(<< "Computing maximum stability margin");
itkDebugMacro(<< "Computing maximum stability margin");
...
@@ -331,7 +328,7 @@ void Controller<TSegmenter>::GetAutomaticConfiguration()
...
@@ -331,7 +328,7 @@ void Controller<TSegmenter>::GetAutomaticConfiguration()
long long unsigned int memoryUsed = GetNodeMemory();
long long unsigned int memoryUsed = GetNodeMemory();
memoryUsed *= static_cast<long long unsigned int>(m_TileHeight + 2*m_Margin);
memoryUsed *= static_cast<long long unsigned int>(m_TileHeight + 2*m_Margin);
memoryUsed *= static_cast<long long unsigned int>(m_TileWidth + 2*m_Margin);
memoryUsed *= static_cast<long long unsigned int>(m_TileWidth + 2*m_Margin);
itk
Warnin
gMacro(<< "An amount of " << memoryUsed/(1024.0*1024.0) << " Mbytes of RAM will be used for regular tiles of size "
itk
Debu
gMacro(<< "An amount of " << memoryUsed/(1024.0*1024.0) << " Mbytes of RAM will be used for regular tiles of size "
<< (m_TileWidth + 2*m_Margin) << "x" << (m_TileHeight + 2*m_Margin) );
<< (m_TileWidth + 2*m_Margin) << "x" << (m_TileHeight + 2*m_Margin) );
}
}
...
...
include/lsgrmGraphOperations.h
View file @
bb65d2e0
...
@@ -16,6 +16,12 @@ struct ProcessingTile
...
@@ -16,6 +16,12 @@ struct ProcessingTile
long
int
tileNeighbors
[
8
];
// tile Neighbors at (top, top right, right, bottom right, bottom, bottom left, left, top left)
long
int
tileNeighbors
[
8
];
// tile Neighbors at (top, top right, right, bottom right, bottom, bottom left, left, top left)
long
int
margin
[
4
];
// Is there a margin at top, left, bottom or right
long
int
margin
[
4
];
// Is there a margin at top, left, bottom or right
otb
::
VectorImage
<
double
>::
RegionType
region
;
// The image region
otb
::
VectorImage
<
double
>::
RegionType
region
;
// The image region
// Temporary files
std
::
string
nodeFileName
;
std
::
string
edgeFileName
;
std
::
string
nodeMarginFileName
;
std
::
string
edgeMarginFileName
;
};
};
// Read an image region
// Read an image region
...
@@ -30,7 +36,6 @@ MergeAllGraphsAndAchieveSegmentation(
...
@@ -30,7 +36,6 @@ MergeAllGraphsAndAchieveSegmentation(
const
typename
TSegmenter
::
ParameterType
&
params
,
const
typename
TSegmenter
::
ParameterType
&
params
,
const
float
&
threshold
,
const
float
&
threshold
,
std
::
vector
<
ProcessingTile
>&
tiles
,
std
::
vector
<
ProcessingTile
>&
tiles
,
const
std
::
string
&
tmpDir
,
const
unsigned
int
nbTilesX
,
const
unsigned
int
nbTilesX
,
const
unsigned
int
nbTilesY
,
const
unsigned
int
nbTilesY
,
const
unsigned
int
imageWidth
,
const
unsigned
int
imageWidth
,
...
@@ -50,7 +55,6 @@ long long unsigned int RunFirstPartialSegmentation(
...
@@ -50,7 +55,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
std
::
string
&
tmpDir
,
bool
&
isFusion
);
bool
&
isFusion
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
...
@@ -59,7 +63,6 @@ long long unsigned int RunPartialSegmentation(
...
@@ -59,7 +63,6 @@ long long unsigned int RunPartialSegmentation(
const
float
&
threshold
,
const
float
&
threshold
,
const
unsigned
int
niter
,
const
unsigned
int
niter
,
std
::
vector
<
ProcessingTile
>&
tiles
,
std
::
vector
<
ProcessingTile
>&
tiles
,
const
std
::
string
&
tmpDir
,
const
unsigned
int
nbTilesX
,
const
unsigned
int
nbTilesX
,
const
unsigned
int
nbTilesY
,
const
unsigned
int
nbTilesY
,
const
unsigned
int
imageWidth
,
const
unsigned
int
imageWidth
,
...
@@ -101,9 +104,13 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
...
@@ -101,9 +104,13 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
std
::
vector
<
typename
TSegmenter
::
NodePointerType
>
>&
borderPixelMap
,
std
::
vector
<
typename
TSegmenter
::
NodePointerType
>
>&
borderPixelMap
,
const
unsigned
int
imageWidth
);
const
unsigned
int
imageWidth
);
template
<
class
TSegmenter
>
void
InsertNodesFromTile
(
typename
TSegmenter
::
GraphType
&
graph
,
ProcessingTile
&
tile
,
bool
margin
=
true
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
void
AddStabilityMargin
(
typename
TSegmenter
::
GraphType
&
graph
,
void
AddStabilityMargin
(
typename
TSegmenter
::
GraphType
&
graph
,
const
std
::
string
&
tmpDir
,
std
::
vector
<
ProcessingTile
>&
tiles
,
const
unsigned
int
row
,
const
unsigned
int
row
,
const
unsigned
int
col
,
const
unsigned
int
col
,
const
unsigned
int
nbTilesX
,
const
unsigned
int
nbTilesX
,
...
@@ -134,18 +141,19 @@ void DetectBorderNodes(typename TSegmenter::GraphType& graph,
...
@@ -134,18 +141,19 @@ void DetectBorderNodes(typename TSegmenter::GraphType& graph,
const
unsigned
int
imageHeight
);
const
unsigned
int
imageHeight
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
void
ReadGraph
(
typename
TSegmenter
::
GraphType
&
graph
,
void
ReadGraph
(
TSegmenter
&
segmenter
,
const
std
::
string
&
nodesPath
,
const
std
::
string
&
nodesPath
,
const
std
::
string
&
edgesPath
);
const
std
::
string
&
edgesPath
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
void
WriteGraph
(
typename
TSegmenter
::
GraphType
&
graph
,
void
ReadGraph
(
typename
TSegmenter
::
GraphType
&
graph
,
const
std
::
string
&
tmpDir
,
const
std
::
string
&
nodesPath
,
const
unsigned
int
row
,
const
std
::
string
&
edgesPath
);
const
unsigned
int
col
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
long
long
unsigned
int
GetGraphMemory
(
TSegmenter
segmenter
);
void
WriteGraph
(
typename
TSegmenter
::
GraphType
&
graph
,
const
std
::
string
&
nodesFile
,
const
std
::
string
&
edgesFile
);
template
<
class
TSegmenter
>
template
<
class
TSegmenter
>
void
RemoveUnstableSegments
(
typename
TSegmenter
::
GraphType
&
graph
,
void
RemoveUnstableSegments
(
typename
TSegmenter
::
GraphType
&
graph
,
...
...
include/lsgrmGraphOperations.txx
View file @
bb65d2e0
...
@@ -27,7 +27,6 @@ MergeAllGraphsAndAchieveSegmentation(
...
@@ -27,7 +27,6 @@ MergeAllGraphsAndAchieveSegmentation(
const typename TSegmenter::ParameterType& params,
const typename TSegmenter::ParameterType& params,
const float& threshold,
const float& threshold,
std::vector<ProcessingTile>& tiles,
std::vector<ProcessingTile>& tiles,
const std::string& tmpDir,
const unsigned int nbTilesX,
const unsigned int nbTilesX,
const unsigned int nbTilesY,
const unsigned int nbTilesY,
const unsigned int imageWidth,
const unsigned int imageWidth,
...
@@ -36,16 +35,16 @@ MergeAllGraphsAndAchieveSegmentation(
...
@@ -36,16 +35,16 @@ MergeAllGraphsAndAchieveSegmentation(
unsigned int numberOfIterations)
unsigned int numberOfIterations)
{
{
// TODO parallelize this ...
std::cout << "--- Graph aggregation...\n" << std::endl;
// TODO parallelize this ?
#ifdef OTB_USE_MPI
#ifdef OTB_USE_MPI
if (otb::MPIConfig::Instance()->GetMyRank() != 0)
if (otb::MPIConfig::Instance()->GetMyRank() != 0)
return;
return;
#endif
#endif
TSegmenter segmenter;
TSegmenter segmenter;
std::string nodesPath, edgesPath;
std::cout << "--- Graph aggregation...\n" << std::endl;
std::cout << "Reading graphs" << std::endl;
std::cout << "Reading graphs" << std::endl;
...
@@ -55,16 +54,7 @@ MergeAllGraphsAndAchieveSegmentation(
...
@@ -55,16 +54,7 @@ MergeAllGraphsAndAchieveSegmentation(
{
{
std::cout << "\tImporting graph of tile " << (row*nbTilesX + col) << " / " << (nbTilesX*nbTilesY) << std::endl;
std::cout << "\tImporting graph of tile " << (row*nbTilesX + col) << " / " << (nbTilesX*nbTilesY) << std::endl;
typename TSegmenter::GraphType graph;
InsertNodesFromTile<TSegmenter>(segmenter.m_Graph, tiles[row*nbTilesX + col], false);
// Load the graph
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";
ReadGraph<TSegmenter>(graph, nodesPath, edgesPath);
segmenter.m_Graph.m_Nodes.insert(segmenter.m_Graph.m_Nodes.end(),
graph.m_Nodes.begin(),
graph.m_Nodes.end());
}
}
}
}
...
@@ -95,7 +85,6 @@ MergeAllGraphsAndAchieveSegmentation(
...
@@ -95,7 +85,6 @@ MergeAllGraphsAndAchieveSegmentation(
}
}
}
}
std::cout << "Achieve segmentation process" ;
std::cout << "Achieve segmentation process" ;
// Segmentation of the graph
// Segmentation of the graph
...
@@ -121,7 +110,6 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -121,7 +110,6 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
const float& threshold,
const float& threshold,
const unsigned int niter,
const unsigned int niter,
std::vector<ProcessingTile>& tiles,
std::vector<ProcessingTile>& tiles,
const std::string& tmpDir,
const unsigned int nbTilesX,
const unsigned int nbTilesX,
const unsigned int nbTilesY,
const unsigned int nbTilesY,
const unsigned int imageWidth,
const unsigned int imageWidth,
...
@@ -130,7 +118,6 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -130,7 +118,6 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
bool& isFusion)
bool& isFusion)
{
{
long long unsigned int accumulatedMemory = 0;
long long unsigned int accumulatedMemory = 0;
std::string nodesPath, edgesPath;
isFusion = false;
isFusion = false;
const unsigned int numberOfNeighborLayers = static_cast<unsigned int>(pow(2, niter + 1) - 2);
const unsigned int numberOfNeighborLayers = static_cast<unsigned int>(pow(2, niter + 1) - 2);
...
@@ -143,28 +130,27 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -143,28 +130,27 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
{
{
if (MyTurn(row*nbTilesX + col))
if (MyTurn(row*nbTilesX + col))
{
{
// Get the current tile
ProcessingTile currentTile = tiles[row*nbTilesX + col];
TSegmenter segmenter;
TSegmenter segmenter;
std::cout << "Processing 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";
ReadGraph<TSegmenter>(segmenter.m_Graph, currentTile.nodeFileName, currentTile.edgeFileName);
edgesPath = tmpDir + "tile_edges_" + std::to_string(row) + "_" + std::to_string(col) + ".bin";
ReadGraph<TSegmenter>(segmenter.m_Graph, nodesPath, edgesPath);
// Add stability margin to the graph
// Add stability margin to the graph
{
{
std::cout << "\tAdd stability margin..." << std::endl;
std::cout << "\tAdd stability margin..." << std::endl;
AddStabilityMargin<TSegmenter>(segmenter.m_Graph, t
mpDir
,
AddStabilityMargin<TSegmenter>(segmenter.m_Graph, t
iles
,
row, col, nbTilesX, nbTilesY);
row, col, nbTilesX, nbTilesY);
std::unordered_map<long unsigned int,
std::unordered_map<long unsigned int,
std::vector<typename TSegmenter::NodePointerType> > borderPixelMap;
std::vector<typename TSegmenter::NodePointerType> > borderPixelMap;
std::cout << "\tBuild border pixel map..." << std::endl;
std::cout << "\tBuild border pixel map..." << std::endl;
BuildBorderPixelMap<TSegmenter>(segmenter.m_Graph,
tiles[row*nbTilesX + col]
, row, col,
BuildBorderPixelMap<TSegmenter>(segmenter.m_Graph,
currentTile
, row, col,
nbTilesX, nbTilesY, borderPixelMap, imageWidth);
nbTilesX, nbTilesY, borderPixelMap, imageWidth);
std::cout << "\tRemove duplicated nodes..." << std::endl;
std::cout << "\tRemove duplicated nodes..." << std::endl;
...
@@ -176,7 +162,7 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -176,7 +162,7 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
imageHeight);
imageHeight);
std::cout << "\tRemove useless.." << std::endl;
std::cout << "\tRemove useless.." << std::endl;
RemoveUselessNodes<TSegmenter>(
tiles[row*nbTilesX + col]
, segmenter.m_Graph,
RemoveUselessNodes<TSegmenter>(
currentTile
, segmenter.m_Graph,
row, col, nbTilesX, nbTilesY, imageWidth, numberOfNeighborLayers);
row, col, nbTilesX, nbTilesY, imageWidth, numberOfNeighborLayers);
}
}
...
@@ -198,15 +184,15 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -198,15 +184,15 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
// Remove unstable segments
// Remove unstable segments
std::cout << "\tRemove unstable segments..." << std::endl;
std::cout << "\tRemove unstable segments..." << std::endl;
RemoveUnstableSegments<TSegmenter>(segmenter.m_Graph,
tiles[row*nbTilesX + col]
, imageWidth);
RemoveUnstableSegments<TSegmenter>(segmenter.m_Graph,
currentTile
, 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 << "\tGet graph memory..." << std::endl;
accumulatedMemory += GetGraphMemory
<TSegmenter>(segmenter
);
accumulatedMemory +=
segmenter.
GetGraphMemory
(
);
// Write graph to temporay directory
(warning specific to Baatz & Schape !!!)
// Write graph to temporay directory
std::cout << "\tWrite graph..." << std::endl;
std::cout << "\tWrite graph..." << std::endl;
WriteGraph<TSegmenter>(segmenter.m_Graph,
tmpDir, row, col
);
WriteGraph<TSegmenter>(segmenter.m_Graph,
currentTile.nodeFileName, currentTile.edgeFileName
);
}
}
}
}
}
}
...
@@ -224,32 +210,24 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
...
@@ -224,32 +210,24 @@ long long unsigned int RunPartialSegmentation(const typename TSegmenter::Paramet
{
{
if (MyTurn(row*nbTilesX + col))
if (MyTurn(row*nbTilesX + col))
{
{
//
std::cout << "*" << std::flush;
//
Get current tile
typename TSegmenter::GraphType graph
;
ProcessingTile currentTile = tiles[row*nbTilesX + col]
;
// Load the graph
// Load the graph
nodesPath = tmpDir + "tile_nodes_" + std::to_string(row) + "_" + std::to_string(col) + ".bin";
typename TSegmenter::GraphType graph;
edgesPath = tmpDir + "tile_edges_" + std::to_string(row) + "_" + std::to_string(col) + ".bin";
ReadGraph<TSegmenter>(graph, currentTile.nodeFileName, currentTile.edgeFileName);
ReadGraph<TSegmenter>(graph, nodesPath, edgesPath);
// Extract stability margin for all borders different from 0 imageWidth-1 et imageHeight -
// Extract stability margin for all borders different from 0 imageWidth-1 et imageHeight -
// and write them to the stability margin
// and write them to the stability margin
{
{
std::unordered_map<typename TSegmenter::NodePointerType, unsigned int> borderNodeMap;
std::unordered_map<typename TSegmenter::NodePointerType, unsigned int> borderNodeMap;
DetectBorderNodes<TSegmenter>(graph,
tiles[row*nbTilesX + col]
,
DetectBorderNodes<TSegmenter>(graph,
currentTile
,
borderNodeMap, imageWidth, imageHeight);
borderNodeMap, imageWidth, imageHeight);
ExtractStabilityMargin<TSegmenter>(borderNodeMap, numberOfNeighborLayers);
ExtractStabilityMargin<TSegmenter>(borderNodeMap, numberOfNeighborLayers);
std::string nodesPath = tmpDir + "tile_nodes_margin_" +
WriteStabilityMargin<TSegmenter>(borderNodeMap, currentTile.nodeMarginFileName, currentTile.edgeMarginFileName);
std::to_string(row) + "_" + std::to_string(col) + ".bin";
std::string edgesPath = tmpDir + "tile_edges_margin_" +
std::to_string(row) + "_" + std::to_string(col) + ".bin";
WriteStabilityMargin<TSegmenter>(borderNodeMap, nodesPath, edgesPath);
}
}
std::cout << "Process finished on tile " << (row*nbTilesX + col) << std::endl;
std::cout << "Process finished on tile " << (row*nbTilesX + col) << std::endl;
}
}
...
@@ -529,156 +507,79 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
...
@@ -529,156 +507,79 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
}
}
}
}
template<class TSegmenter>
void InsertNodesFromTile(typename TSegmenter::GraphType& graph,
ProcessingTile& tile, bool margin = true)
{
typename TSegmenter::GraphType subgraph;
if (margin)
{
ReadGraph<TSegmenter>(subgraph, tile.nodeMarginFileName, tile.edgeMarginFileName);
}
else
{
ReadGraph<TSegmenter>(subgraph, tile.nodeFileName, tile.edgeFileName);
}
graph.m_Nodes.insert(graph.m_Nodes.end(), subgraph.m_Nodes.begin(), subgraph.m_Nodes.end());
}
template<class TSegmenter>
template<class TSegmenter>
void AddStabilityMargin(typename TSegmenter::GraphType& graph,
void AddStabilityMargin(typename TSegmenter::GraphType& graph,
const std::string& tmpDir
,
std::vector<ProcessingTile>& tiles
,
const unsigned int row,
const unsigned int row,
const unsigned int col,
const unsigned int col,
const unsigned int nbTilesX,
const unsigned int nbTilesX,
const unsigned int nbTilesY)
const unsigned int nbTilesY)
{
{
std::string nodesPath;
std::string edgesPath;
unsigned int rowNeigh;
unsigned int colNeigh;
// Margin to retrieve at top
// Margin to retrieve at top
if(row > 0)
if(row > 0)
{
{
colNeigh = col;
InsertNodesFromTile<TSegmenter>(graph, tiles[(row-1) * nbTilesX + col]);
rowNeigh = row-1;
nodesPath = tmpDir + "tile_nodes_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
edgesPath = tmpDir + "tile_edges_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
typename TSegmenter::GraphType subgraph;
ReadGraph<TSegmenter>(subgraph, nodesPath, edgesPath);
graph.m_Nodes.insert(graph.m_Nodes.end(), subgraph.m_Nodes.begin(), subgraph.m_Nodes.end());
}
}
// Margin to retrieve at right
// Margin to retrieve at right
if(col < nbTilesX - 1)
if(col < nbTilesX - 1)
{
{
colNeigh = col + 1;
InsertNodesFromTile<TSegmenter>(graph, tiles[row * nbTilesX + (col+1)]);
rowNeigh = row;
nodesPath = tmpDir + "tile_nodes_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
edgesPath = tmpDir + "tile_edges_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
typename TSegmenter::GraphType subgraph;
ReadGraph<TSegmenter>(subgraph, nodesPath, edgesPath);
graph.m_Nodes.insert(graph.m_Nodes.end(), subgraph.m_Nodes.begin(), subgraph.m_Nodes.end());
}
}
// Margin to retrieve at bottom
// Margin to retrieve at bottom
if(row < nbTilesY - 1)
if(row < nbTilesY - 1)
{
{
colNeigh = col;
InsertNodesFromTile<TSegmenter>(graph, tiles[(row+1) * nbTilesX + col]);
rowNeigh = row + 1;
nodesPath = tmpDir + "tile_nodes_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
edgesPath = tmpDir + "tile_edges_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
typename TSegmenter::GraphType subgraph;
ReadGraph<TSegmenter>(subgraph, nodesPath, edgesPath);
graph.m_Nodes.insert(graph.m_Nodes.end(), subgraph.m_Nodes.begin(), subgraph.m_Nodes.end());
}
}
// Margin to retrieve at left
// Margin to retrieve at left
if(col > 0)
if(col > 0)
{
{
colNeigh = col-1;
InsertNodesFromTile<TSegmenter>(graph, tiles[row * nbTilesX + (col-1)]);
rowNeigh = row;
nodesPath = tmpDir + "tile_nodes_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";
edgesPath = tmpDir + "tile_edges_margin_" +
std::to_string(rowNeigh) + "_" + std::to_string(colNeigh) + ".bin";