Commit 07554cbf authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

FIX: fixed some 64-bit type related problems for large images under Windows

No related merge requests found
Showing with 46 additions and 13 deletions
+46 -13
...@@ -88,6 +88,7 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -88,6 +88,7 @@ void Controller<TSegmenter>::RunSegmentation()
// Run first partial segmentation // Run first partial segmentation
boost::timer t; t.restart(); boost::timer t; t.restart();
auto accumulatedMemory = RunFirstPartialSegmentation<TSegmenter>( auto accumulatedMemory = RunFirstPartialSegmentation<TSegmenter>(
m_InputImage, m_InputImage,
m_SpecificParameters, m_SpecificParameters,
...@@ -140,7 +141,7 @@ void Controller<TSegmenter>::RunSegmentation() ...@@ -140,7 +141,7 @@ void Controller<TSegmenter>::RunSegmentation()
numberOfIterationsRemaining -= numberOfIterationsForPartialSegmentations; numberOfIterationsRemaining -= numberOfIterationsForPartialSegmentations;
} }
} }
#ifdef OTB_USE_MPI #ifdef OTB_USE_MPI
// Only the master process is doing the next part // Only the master process is doing the next part
// TODO: Use the MPI process wich has the largest amount of memory // TODO: Use the MPI process wich has the largest amount of memory
......
...@@ -98,7 +98,8 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph, ...@@ -98,7 +98,8 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
const unsigned int nbTilesY, const unsigned int nbTilesY,
std::unordered_map<std::size_t, std::unordered_map<std::size_t,
std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap, std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
const unsigned int imageWidth); const unsigned int imageWidth,
bool merging = false);
template<class TSegmenter> template<class TSegmenter>
void InsertNodesFromTile(typename TSegmenter::GraphType& graph, void InsertNodesFromTile(typename TSegmenter::GraphType& graph,
......
...@@ -69,7 +69,7 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -69,7 +69,7 @@ MergeAllGraphsAndAchieveSegmentation(
std::cout << "\tBuildBorderPixelMap..." << std::endl; std::cout << "\tBuildBorderPixelMap..." << std::endl;
BuildBorderPixelMap<TSegmenter>(segmenter.m_Graph, tiles[row*nbTilesX + col], row, col, BuildBorderPixelMap<TSegmenter>(segmenter.m_Graph, tiles[row*nbTilesX + col], row, col,
nbTilesX, nbTilesY, borderPixelMap, imageWidth); nbTilesX, nbTilesY, borderPixelMap, imageWidth, true);
std::cout << "\tRemoveDuplicatedNodes..." << std::endl; std::cout << "\tRemoveDuplicatedNodes..." << std::endl;
...@@ -93,7 +93,9 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -93,7 +93,9 @@ MergeAllGraphsAndAchieveSegmentation(
segmenter.SetNumberOfIterations(numberOfIterations); segmenter.SetNumberOfIterations(numberOfIterations);
grm::GraphOperations<TSegmenter>::PerfomAllIterationsWithLMBFAndConstThreshold(segmenter); grm::GraphOperations<TSegmenter>::PerfomAllIterationsWithLMBFAndConstThreshold(segmenter);
// patch raf (sort using node id directly --> seems ok)
// Sort the nodes top-->down and left-->right // Sort the nodes top-->down and left-->right
/*
std::sort(segmenter.m_Graph.m_Nodes.begin(), segmenter.m_Graph.m_Nodes.end(), std::sort(segmenter.m_Graph.m_Nodes.begin(), segmenter.m_Graph.m_Nodes.end(),
[imageWidth](const auto & a, const auto & b) -> bool [imageWidth](const auto & a, const auto & b) -> bool
{ {
...@@ -101,8 +103,10 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -101,8 +103,10 @@ MergeAllGraphsAndAchieveSegmentation(
lp::ContourOperations::GenerateBorderCells(borderPixelsA, a->m_Contour, a->m_Id, imageWidth); lp::ContourOperations::GenerateBorderCells(borderPixelsA, a->m_Contour, a->m_Id, imageWidth);
lp::ContourOperations::GenerateBorderCells(borderPixelsB, b->m_Contour, b->m_Id, imageWidth); lp::ContourOperations::GenerateBorderCells(borderPixelsB, b->m_Contour, b->m_Id, imageWidth);
unsigned int offA = 0; // patch raf (were unsigned int)
unsigned int offB = 0; std::size_t offA = 0;
std::size_t offB = 0;
// end patch
for (auto& pix: borderPixelsA) for (auto& pix: borderPixelsA)
if (pix>offA) if (pix>offA)
offA=pix; offA=pix;
...@@ -113,6 +117,13 @@ MergeAllGraphsAndAchieveSegmentation( ...@@ -113,6 +117,13 @@ MergeAllGraphsAndAchieveSegmentation(
return offA > offB; return offA > offB;
}); });
*/
std::sort(segmenter.m_Graph.m_Nodes.begin(), segmenter.m_Graph.m_Nodes.end(),
[](const auto & a, const auto & b) -> bool
{
return a->m_Id < b->m_Id;
});
// end patch
return segmenter.m_Graph; return segmenter.m_Graph;
} }
...@@ -466,7 +477,8 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph, ...@@ -466,7 +477,8 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
const unsigned int nbTilesY, const unsigned int nbTilesY,
std::unordered_map<std::size_t, std::unordered_map<std::size_t,
std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap, std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
const unsigned int imageWidth) const unsigned int imageWidth,
bool merging)
{ {
unsigned int rowPixel, colPixel; unsigned int rowPixel, colPixel;
unsigned int rowMin = (tile.rows[0] > 0) ? tile.rows[0] - 1 : tile.rows[0]; unsigned int rowMin = (tile.rows[0] > 0) ? tile.rows[0] - 1 : tile.rows[0];
...@@ -483,6 +495,15 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph, ...@@ -483,6 +495,15 @@ void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
{ {
continue; continue;
} }
// patch raf (exclude nodes all outside tiles - on merging stage only)
else if(merging && (node->m_Bbox.m_UX > tile.columns[1] ||
node->m_Bbox.m_UY > tile.rows[1] ||
node->m_Bbox.m_UX + node->m_Bbox.m_W - 1 < tile.columns[0] ||
node->m_Bbox.m_UY + node->m_Bbox.m_H - 1 < tile.rows[0]))
{
continue;
}
// end patch
else else
{ {
lp::CellLists borderPixels; lp::CellLists borderPixels;
...@@ -618,9 +639,11 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -618,9 +639,11 @@ long long unsigned int RunFirstPartialSegmentation(
std::cout << "--- Running fist partial segmentation...\nNumber of neighbor layers " << numberOfNeighborLayers << std::endl; std::cout << "--- Running fist partial segmentation...\nNumber of neighbor layers " << numberOfNeighborLayers << std::endl;
for(unsigned int row = 0; row < nbTilesY; ++row) //for(unsigned int row = 0; row < nbTilesY; ++row)
for(unsigned int row = 24; row < 25; ++row)
{ {
for(unsigned int col = 0; col < nbTilesX; col++) //for(unsigned int col = 0; col < nbTilesX; col++)
for(unsigned int col = 30; col < 31; col++)
{ {
#ifdef OTB_USE_MPI #ifdef OTB_USE_MPI
if (MyTurn(row*nbTilesX + col)) if (MyTurn(row*nbTilesX + col))
...@@ -645,7 +668,7 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -645,7 +668,7 @@ long long unsigned int RunFirstPartialSegmentation(
segmenter.SetNumberOfIterations(niter); segmenter.SetNumberOfIterations(niter);
segmenter.SetInput(imageTile); segmenter.SetInput(imageTile);
segmenter.Update(); segmenter.Update();
if(segmenter.GetComplete() == false) if(segmenter.GetComplete() == false)
isFusion = true; isFusion = true;
...@@ -658,7 +681,7 @@ long long unsigned int RunFirstPartialSegmentation( ...@@ -658,7 +681,7 @@ long long unsigned int RunFirstPartialSegmentation(
tileWidth, tileWidth,
tileHeight, tileHeight,
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, currentTile, imageWidth); RemoveUnstableSegments<TSegmenter>(segmenter.m_Graph, currentTile, imageWidth);
...@@ -991,7 +1014,7 @@ void RescaleGraph(typename TSegmenter::GraphType& graph, ...@@ -991,7 +1014,7 @@ void RescaleGraph(typename TSegmenter::GraphType& graph,
// Start pixel index of the node (in the image) // Start pixel index of the node (in the image)
rowNodeImg = rowTile * tileHeight + rowNodeTile - tile.margin[0]; rowNodeImg = rowTile * tileHeight + rowNodeTile - tile.margin[0];
colNodeImg = colTile * tileWidth + colNodeTile - tile.margin[3]; colNodeImg = colTile * tileWidth + colNodeTile - tile.margin[3];
node->m_Id = rowNodeImg * imageWidth + colNodeImg; node->m_Id = (std::size_t)rowNodeImg * (std::size_t)imageWidth + (std::size_t)colNodeImg;
// Change also its bounding box // Change also its bounding box
node->m_Bbox.m_UX = colTile * tileWidth + node->m_Bbox.m_UX - tile.margin[3]; node->m_Bbox.m_UX = colTile * tileWidth + node->m_Bbox.m_UX - tile.margin[3];
......
...@@ -131,9 +131,17 @@ StreamingGraphToImageFilter<TGraph, TLabelImage> ...@@ -131,9 +131,17 @@ StreamingGraphToImageFilter<TGraph, TLabelImage>
for (auto& pix: borderPixels) for (auto& pix: borderPixels)
{ {
index[0] = pix % m_OutputSize[0]; // patch raf (catch exception if position of pixel to set is not correct)
index[1] = pix / m_OutputSize[0]; try {
index[0] = (unsigned int)(pix % (std::size_t)(m_OutputSize[0]));
index[1] = (unsigned int)(pix / (std::size_t)(m_OutputSize[0]));
labelImage->SetPixel(index, res.second); labelImage->SetPixel(index, res.second);
} catch (std::exception e) {
std::cout << "Pixel ID: " << pix << std::endl;
std::cout << "Derived index: " << index[0] << "," << index[1] << std::endl;
std::cout << "Node position in list: " << res.second << std::endl;
}
// end patch
} }
} }
itkDebugMacro( << "Burning boundaries ok "); itkDebugMacro( << "Burning boundaries ok ");
......
Supports Markdown
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