Commit 520bdd3d authored by Cédric Traizet's avatar Cédric Traizet
Browse files

test vec

parent 94cdfe60
......@@ -168,29 +168,44 @@ private:
regionMergingFilter->SetInputLabelImage( labelIn );
regionMergingFilter->SetInputSpectralImage( imageIn );
regionMergingFilter->SetLabelPopulation( labelStatsFilter->GetLabelPopulationMap() );
regionMergingFilter->SetLabelStatistic( labelStatsFilter->GetMeanValueMap() );
auto myMap = labelStatsFilter->GetLabelPopulationMap();
std::vector<double> Test;
for (int i =0; i < myMap.rbegin()->first; i++)
{
Test.push_back(myMap[i]);
}
//regionMergingFilter->SetLabelPopulation( labelStatsFilter->GetLabelPopulationMap() );
regionMergingFilter->SetLabelPopulation( Test );
regionMergingFilter->SetLabelStatistic( labelStatsFilter->GetMeanValueMap() );
clock_t tic2 = clock();
for (unsigned int size = 1 ; size < minSize ; size++)
{
regionMergingFilter->SetSize( size );
regionMergingFilter->Update();
}
clock_t toc2 = clock();
std::cout <<"Elapsed timeaazaed : "<<(double)(toc2 - tic2) / CLOCKS_PER_SEC<<" seconds" << std::endl;
//Relabelling
auto changeLabelFilter = ChangeLabelImageFilterType::New();
changeLabelFilter->SetInput(labelIn);
auto correspondanceMap = regionMergingFilter->GetCorrespondanceMap();
for (auto correspondance : correspondanceMap)
/*for (auto correspondance : correspondanceMap)
{
if (correspondance.first != correspondance.second)
{
std::cout << correspondance.first << " " << correspondance.second << std::endl;
changeLabelFilter->SetChange(correspondance.first, correspondance.second);
}
}
}*/ //TODO
for(int i = 0; i<correspondanceMap.size(); ++i)
{
if(i!=correspondanceMap[i])
{
changeLabelFilter->SetChange(i,correspondanceMap[i]);
}
}
SetParameterOutputImage("out", changeLabelFilter->GetOutput());
RegisterPipeline();
clock_t toc = clock();
......
......@@ -77,10 +77,17 @@ public:
typedef typename TInputSpectralImage::PixelType SpectralPixelType;
typedef itk::VariableLengthVector<double> RealVectorPixelType;
typedef std::map<InputLabelType, double> LabelPopulationMapType;
//typedef std::map<InputLabelType, double> LabelPopulationMapType;
typedef std::vector<double> LabelPopulationMapType;
typedef std::map<InputLabelType, std::set<InputLabelType> > NeigboursMapType;
typedef std::map<InputLabelType, RealVectorPixelType > LabelStatisticMapType;
typedef std::map<InputLabelType, InputLabelType> CorrespondanceMapType;
//typedef std::map<InputLabelType, InputLabelType> CorrespondanceMapType;
typedef std::vector<double> CorrespondanceMapType;
/** Sets the input image where the value of a pixel is the region id */
void SetInputLabelImage( const InputLabelImageType * labelImage);
/** Sets the input image representing spectral values */
......@@ -95,7 +102,7 @@ public:
itkSetMacro(Size , unsigned int);
/** Set/Get the Label population map and initialize the correspondance map*/
void SetLabelPopulation( LabelPopulationMapType const & labelPopulation )
/*void SetLabelPopulation( LabelPopulationMapType const & labelPopulation )
{
m_LabelPopulation = labelPopulation;
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
......@@ -104,6 +111,17 @@ public:
m_CorrespondanceMap[ label.first ] = label.first;
}
}
*/
void SetLabelPopulation( LabelPopulationMapType const & labelPopulation )
{
m_LabelPopulation = labelPopulation;
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
m_CorrespondanceMap.resize( labelPopulation.size() );
for (int i =0; i <labelPopulation.size(); i++)
{
m_CorrespondanceMap[ i ] = i;
}
}
LabelPopulationMapType const & GetLabelPopulation() const
{
......
......@@ -27,7 +27,7 @@
#include "itkConstShapedNeighborhoodIterator.h"
#include "itkProgressReporter.h"
#include <time.h>
namespace otb
{
template <class TInputLabelImage, class TInputSpectralImage>
......@@ -83,8 +83,6 @@ void
PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralImage>
::Reset()
{
std::cout << "Reset" << std::endl;
m_NeighboursMapsTmp.clear();
m_NeighboursMapsTmp.resize( this->GetNumberOfThreads() );
}
......@@ -95,7 +93,7 @@ void
PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralImage>
::Synthetize()
{
std::cout << "Synthetize" << std::endl;
clock_t tic = clock();
NeigboursMapType neighboursMap;
// Merge the neighbours maps from all threads
for( unsigned int threadId = 0; threadId < this->GetNumberOfThreads(); threadId++)
......@@ -130,38 +128,24 @@ PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralIma
proximity = distance;
closestNeighbour = neighbour;
}
std::cout << label << " " << neighbour << " " << distance << " " << closestNeighbour <<std::endl;
}
m_CorrespondanceMap[label] = closestNeighbour;
//InputLabelType neighbor = itLabel->first;
//
/*for (auto itNeigh = itLabel->second.begin(); itNeigh != itLabel->second.end(); ++itNeigh)
{
// Compute squared distance between the current label and the current neighbour
//double dist = std::abs( std::pow( m_labelStatistic[itLabel->first], 2) - std::pow( m_labelStatistic[*itNeigh], 2) );
for (auto
}*/
// Update Stats
m_LabelStatistic[closestNeighbour] = (m_LabelStatistic[closestNeighbour]*m_LabelPopulation[closestNeighbour] +
m_LabelStatistic[label]*m_LabelPopulation[label] ) / (m_LabelPopulation[label]+m_LabelPopulation[closestNeighbour]);
m_LabelPopulation[closestNeighbour] += m_LabelPopulation[label];
}
// We have to update corresponding label to propagate the correspondance between the labels.
for (auto & corres : m_CorrespondanceMap)
{
corres.second = FindCorrespondingLabel(corres.second);
std::cout << "label : " << corres.first << " closest : " << corres.second << std::endl;
corres = FindCorrespondingLabel(corres);
// corres.second = FindCorrespondingLabel(corres.second); //TODO
}
/*
for (auto it = m_NeighboursMap.begin(); it != m_NeighboursMap.end(); it++)
{
std::cout << it->first << " " ;
for (auto itSet = it->second.begin(); itSet != it->second.end(); itSet++)
std::cout << *itSet << " " ;
std::cout << std::endl;
}*/
clock_t toc = clock();
std::cout << "Synthetize : " << (double)(toc - tic) / CLOCKS_PER_SEC << std::endl;
}
template <class TInputLabelImage, class TInputSpectralImage>
......@@ -172,7 +156,7 @@ PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralIma
{
auto correspondingLabel = m_CorrespondanceMap[label];
while (label != correspondingLabel)
{std::cout << "yo" << std::endl;
{
label = correspondingLabel;
correspondingLabel = m_CorrespondanceMap[correspondingLabel];
}
......@@ -193,16 +177,19 @@ template <class TInputLabelImage, class TInputSpectralImage>
void
PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralImage>
::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId )
{
std::cout << threadId << " " << outputRegionForThread.GetSize() << " " << outputRegionForThread.GetIndex() << std::endl;
{
clock_t tic = clock();
using IteratorType = itk::ImageRegionConstIterator< TInputLabelImage >;
using NeighborhoodIteratorType = itk::ConstShapedNeighborhoodIterator< TInputLabelImage >;
typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
auto labelImage = this->GetInputLabelImage();
IteratorType it(labelImage, outputRegionForThread);
NeighborhoodIteratorType itN(radius, labelImage, outputRegionForThread);
......@@ -215,25 +202,26 @@ PersistentLabelImageSmallRegionMergingFilter<TInputLabelImage, TInputSpectralIma
itN.ActivateOffset(right);
typename IteratorType::OffsetType left = {{-1,0}};
itN.ActivateOffset(left);
for (it.GoToBegin(); ! it.IsAtEnd(); ++it, ++itN)
{
assert( !itN.IsAtEnd() );
//if ( it.Get() == m_Size )
if ( m_LabelPopulation[it.Get()] == m_Size )
{
//std::cout << it.Get() << std::endl;
for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++)
{
int neighbourLabel = FindCorrespondingLabel(ci.Get() );
std::cout << neighbourLabel << " " << ci.Get() << " " << it.Get() << std::endl;
if (neighbourLabel != it.Get() && m_LabelPopulation[neighbourLabel] > m_Size)
m_NeighboursMapsTmp[threadId][ it.Get() ].insert( neighbourLabel );
}
}
}
clock_t toc = clock();
if (threadId==0)
std::cout << threadId << " " << this->GetNumberOfThreads() << " Elapsed time : " << (double)(toc - tic) / CLOCKS_PER_SEC << std::endl;
}
......
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