Commit 693f6db6 authored by remicres's avatar remicres

Fix polygon filling process

parent b9f39c5f
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define __GRM_GRAPH_TO_OTBIMAGE_TXX #define __GRM_GRAPH_TO_OTBIMAGE_TXX
#include "grmGraphToOtbImage.h" #include "grmGraphToOtbImage.h"
#include "itkImageRegionIterator.h" #include "itkImageRegionIterator.h"
#include "itkGrayscaleFillholeImageFilter.h"
namespace grm namespace grm
{ {
...@@ -40,11 +41,7 @@ namespace grm ...@@ -40,11 +41,7 @@ namespace grm
LabelImageType::Pointer label_img = LabelImageType::New(); LabelImageType::Pointer label_img = LabelImageType::New();
label_img->SetRegions(region); label_img->SetRegions(region);
label_img->Allocate(); label_img->Allocate();
label_img->FillBuffer(0);
using LabelImageIterator = itk::ImageRegionIterator<LabelImageType>;
LabelImageIterator it(label_img, label_img->GetLargestPossibleRegion());
for(it.GoToBegin();!it.IsAtEnd(); ++it)
it.Set(0);
// Start at 1 (value 0 can be used for invalid pixels) // Start at 1 (value 0 can be used for invalid pixels)
unsigned int label = 1; unsigned int label = 1;
...@@ -62,17 +59,13 @@ namespace grm ...@@ -62,17 +59,13 @@ namespace grm
++label; ++label;
} }
unsigned int pixelValue = 0; // Fill holes
for(it.GoToBegin(); !it.IsAtEnd(); ++it) typedef itk::GrayscaleFillholeImageFilter<LabelImageType,LabelImageType> FillholeFilterType;
{ FillholeFilterType::Pointer fillFilter = FillholeFilterType::New();
auto pixel = it.Get(); fillFilter->SetInput(label_img);
if(pixel == 0) fillFilter->Update();
it.Set(pixelValue);
else
pixelValue = pixel;
}
return label_img; return fillFilter->GetOutput();
} }
template<class TGraph> template<class TGraph>
...@@ -96,48 +89,31 @@ namespace grm ...@@ -96,48 +89,31 @@ namespace grm
clusterImg->Allocate(); clusterImg->Allocate();
ClusteredImageType::PixelType pixelValue; ClusteredImageType::PixelType pixelValue;
pixelValue.Reserve(3); pixelValue.SetSize(3);
pixelValue[0] = 255; pixelValue.Fill(255);
pixelValue[1] = 255;
pixelValue[2] = 255;
using ClusterImageIterator = itk::ImageRegionIterator<ClusteredImageType>; clusterImg->FillBuffer(pixelValue);
ClusterImageIterator it(clusterImg, clusterImg->GetLargestPossibleRegion()); LabelImageType::Pointer label_img = this->GetLabelImage(graph, width, height);
for(it.GoToBegin();!it.IsAtEnd(); ++it)
it.Set(pixelValue);
srand(time(NULL)); typedef typename itk::ImageRegionConstIterator<LabelImageType> LabelImageIteratorType;
unsigned char c1, c2, c3; typedef typename itk::ImageRegionIterator<ClusteredImageType> ClusteredImageIteratorType;
for(auto& node : graph.m_Nodes)
{
auto rv = rand() % 255;
c1 = rv;//rand() % 256;
c2 = rv;//rand() % 256;
c3 = rv;//rand() % 256;
lp::CellLists borderPixels; LabelImageIteratorType it1 (label_img, region);
ContourOperator::GenerateBorderCells(borderPixels, node->m_Contour, node->m_Id, width); ClusteredImageIteratorType it2 (clusterImg, region);
for (auto& pix : borderPixels)
{
index[0] = pix % width;
index[1] = pix / width;
pixelValue[0] = c1;
pixelValue[1] = c2;
pixelValue[2] = c3;
clusterImg->SetPixel(index, pixelValue);
}
}
// Generate a random color vector
for(it.GoToBegin(); !it.IsAtEnd(); ++it) srand(time(NULL));
{ std::vector<double> colorMap;
auto pixel = it.Get(); colorMap.reserve(graph.m_Nodes.size());
if(pixel[0] == 255 && pixel[1] == 255 && pixel[2] == 255) std::generate_n(std::back_inserter(colorMap), graph.m_Nodes.size(), rand);
it.Set(pixelValue);
else for (it1.GoToBegin(), it2.GoToBegin() ; !it1.IsAtEnd() ; ++it1, ++it2)
pixelValue = pixel; {
} pixelValue[0] = colorMap[it1.Get()];
pixelValue[1] = (16807 * pixelValue[0]) % 255 ;
pixelValue[2] = (16807 * pixelValue[1]) % 255 ;
it2.Set(pixelValue);
}
return clusterImg; return clusterImg;
} }
......
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