Commit 693f6db6 authored by remicres's avatar remicres

Fix polygon filling process

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