Skip to content
Snippets Groups Projects
Commit 922f6f27 authored by Sebastien Harasse's avatar Sebastien Harasse
Browse files

ENH: Region merging: adding clustered output

parent 08305dba
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,8 @@ public:
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::RegionType OutputRegionType;
typedef TInputSpectralImage OutputClusteredImageType;
itkStaticConstMacro(ImageDimension, unsigned int, InputLabelImageType::ImageDimension);
/** LabelMap typedefs */
......@@ -105,6 +107,10 @@ public:
const OutputLabelImageType * GetLabelOutput() const;
/** Returns the image of region labels */
OutputLabelImageType * GetLabelOutput();
/** Returns the const clustered output image, with one spectral value per region */
const OutputClusteredImageType * GetClusteredOutput() const;
/** Returns the clustered output image, with one spectral value per region */
OutputClusteredImageType * GetClusteredOutput();
void SetInputLabelImage( const InputLabelImageType * labelImage);
void SetInputSpectralImage( const InputSpectralImageType * spectralImage);
......
......@@ -35,6 +35,10 @@ LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabe
this->SetNumberOfRequiredInputs( 2 );
this->SetNumberOfOutputs(2);
this->SetNthOutput(0, OutputLabelImageType::New());
this->SetNthOutput(1, OutputClusteredImageType::New());
}
template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage>
......@@ -103,6 +107,30 @@ LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabe
return static_cast<OutputLabelImageType *>(this->itk::ProcessObject::GetOutput(0));
}
template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage>
typename LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabelImage>::OutputClusteredImageType *
LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabelImage>
::GetClusteredOutput()
{
if (this->GetNumberOfOutputs() < 2)
{
return 0;
}
return static_cast<OutputClusteredImageType *>(this->itk::ProcessObject::GetOutput(1));
}
template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage>
const typename LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabelImage>::OutputClusteredImageType *
LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabelImage>
::GetClusteredOutput() const
{
if (this->GetNumberOfOutputs() < 2)
{
return 0;
}
return static_cast<OutputClusteredImageType *>(this->itk::ProcessObject::GetOutput(1));
}
template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage>
void
......@@ -113,10 +141,13 @@ LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabe
typename InputSpectralImageType::Pointer spectralImage = this->GetInputSpectralImage();
typename InputLabelImageType::Pointer inputLabelImage = this->GetInputLabelImage();
typename OutputLabelImageType::Pointer outputLabelImage = this->GetLabelOutput();
typename OutputClusteredImageType::Pointer outputClusteredImage = this->GetClusteredOutput();
// Allocate the output
// Allocate output
outputLabelImage->SetBufferedRegion( outputLabelImage->GetRequestedRegion() );
outputLabelImage->Allocate();
outputClusteredImage->SetBufferedRegion( outputClusteredImage->GetRequestedRegion() );
outputClusteredImage->Allocate();
m_NumberOfComponentsPerPixel = spectralImage->GetNumberOfComponentsPerPixel();
......@@ -337,6 +368,19 @@ LabelImageRegionMergingFilter<TInputLabelImage, TInputSpectralImage, TOutputLabe
} // end of main iteration loop
std::cout << "merge iterations: " << mergeIterations << std::endl;
std::cout << "number of label objects: " << regionCount << std::endl;
// Generate clustered output
itk::ImageRegionIterator<OutputClusteredImageType> outputClusteredIt(outputClusteredImage, outputClusteredImage->GetRequestedRegion() );
outputClusteredIt.GoToBegin();
outputIt.GoToBegin();
while( !outputClusteredIt.IsAtEnd() )
{
LabelType label = outputIt.Get();
const SpectralPixelType & p = m_Modes[ label ];
outputClusteredIt.Set(p);
++outputClusteredIt;
++outputIt;
}
}
template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment