+++ /dev/null
-
-int main( int argc, char* argv[] )
-{
- return( 0 );
-}
-
-
-// eof - $RCSfile$
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>600</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralwidget">
- <widget class="QWidget" name="Viewer" native="true">
- <property name="geometry">
- <rect>
- <x>60</x>
- <y>150</y>
- <width>461</width>
- <height>331</height>
- </rect>
- </property>
- </widget>
- </widget>
- <widget class="QMenuBar" name="menubar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>20</height>
- </rect>
- </property>
- <widget class="QMenu" name="menuFile">
- <property name="title">
- <string>File</string>
- </property>
- <addaction name="aOpenRawImage"/>
- <addaction name="separator"/>
- <addaction name="aOpenMoriImage"/>
- <addaction name="aSaveMoriImage"/>
- <addaction name="separator"/>
- <addaction name="aOpenRWImage"/>
- <addaction name="aSaveRWImage"/>
- <addaction name="separator"/>
- <addaction name="aOpenSeedsFile"/>
- <addaction name="aSaveSeedsFile"/>
- <addaction name="separator"/>
- <addaction name="aExit"/>
- </widget>
- <addaction name="menuFile"/>
- </widget>
- <widget class="QStatusBar" name="statusbar"/>
- <widget class="QToolBar" name="toolBar">
- <property name="windowTitle">
- <string>toolBar</string>
- </property>
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- <addaction name="aMori"/>
- <addaction name="aRW"/>
- </widget>
- <action name="aOpenRawImage">
- <property name="text">
- <string>Open raw image</string>
- </property>
- </action>
- <action name="aOpenMoriImage">
- <property name="text">
- <string>Open "mori" image</string>
- </property>
- </action>
- <action name="aOpenRWImage">
- <property name="text">
- <string>Open "random walker" image</string>
- </property>
- </action>
- <action name="aExit">
- <property name="text">
- <string>Exit</string>
- </property>
- </action>
- <action name="aOpenSeedsFile">
- <property name="text">
- <string>Open seeds file</string>
- </property>
- </action>
- <action name="aSaveSeedsFile">
- <property name="text">
- <string>Save seeds file</string>
- </property>
- </action>
- <action name="aSaveMoriImage">
- <property name="text">
- <string>Save "mori" image</string>
- </property>
- </action>
- <action name="aSaveRWImage">
- <property name="text">
- <string>Save "random walker" image</string>
- </property>
- </action>
- <action name="aMori">
- <property name="text">
- <string>Mori</string>
- </property>
- </action>
- <action name="aRW">
- <property name="text">
- <string>RandomWalker</string>
- </property>
- </action>
- </widget>
- <resources/>
- <connections/>
-</ui>
+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __CTBronchi__Mori__h__
-#define __CTBronchi__Mori__h__
-
-#include <map>
-#include <CTBronchi/Functions.h>
-#include <fpa/Filters/Image/Mori.h>
-
-namespace CTBronchi
-{
- // -----------------------------------------------------------------------
- template< class _TInputPtr, class _TOutputPtr, class _TSeed >
- typename _TInputPtr::ObjectType::PixelType Mori(
- _TOutputPtr& output, const _TInputPtr& input, _TSeed& seed,
- std::map< std::string, std::string >& args
- )
- {
- typedef typename _TInputPtr::ObjectType _TInput;
- typedef typename _TOutputPtr::ObjectType _TOutput;
- typedef fpa::Filters::Image::Mori< _TInput, _TOutput > _TMori;
- typedef typename _TInput::PixelType _TInputPixel;
- typedef typename _TOutput::PixelType _TOutputPixel;
-
- _TOutputPixel i_val = _TOutputPixel( 1 );
- _TOutputPixel o_val = _TOutputPixel( 0 );
-
- typename _TMori::Pointer mori = _TMori::New( );
- mori->SetInput( input );
- mori->SetSeed( seed );
- mori->SetInsideValue( i_val );
- mori->SetOutsideValue( o_val );
- mori->SetMinimumThreshold(
- _TInputPixel( std::atof( args[ "mori_minimum_threshold" ].c_str( ) ) )
- );
- mori->SetSignalKernelSize(
- std::atoi( args[ "mori_signal_kernel_size" ].c_str( ) )
- );
- mori->SetSignalThreshold(
- std::atof( args[ "mori_signal_threshold" ].c_str( ) )
- );
- mori->SetSignalInfluence(
- std::atof( args[ "mori_signal_influence" ].c_str( ) )
- );
- mori->SetThresholds(
- _TInputPixel( std::atof( args[ "mori_lower_threshold" ].c_str( ) ) ),
- _TInputPixel( std::atof( args[ "mori_upper_threshold" ].c_str( ) ) ),
- _TInputPixel( std::atof( args[ "mori_delta_threshold" ].c_str( ) ) )
- );
- double t = CTBronchi::MeasureTime( mori );
- std::cout << "Mori executed in " << t << " s" << std::endl;
- output = mori->GetOutput( );
-
- std::map< std::string, std::string >::const_iterator i =
- args.find( "out_mori" );
- if( i != args.end( ) )
- CTBronchi::WriteImage( output, i->second );
-
- i = args.find( "out_signal" );
- if( i != args.end( ) )
- {
- std::stringstream signal;
- unsigned long nthr = mori->GetNumberOfEvaluatedThresholds( );
- signal << "# nThr = " << nthr << std::endl;
- signal << "# Opt = " << mori->GetOptimumThreshold( ) << std::endl;
- for( unsigned long j = 0; j < nthr; ++j )
- {
- typename _TMori::TPeak p;
- double x, y;
- mori->GetSignalValues( j, x, y, p );
- signal << x << " " << y << std::endl;
-
- } // rof
- std::ofstream signals_str( i->second.c_str( ) );
- signals_str << signal.str( );
- signals_str.close( );
-
- } // fi
- output->DisconnectPipeline( );
- return( mori->GetOptimumThreshold( ) );
- }
-
-} // ecapseman
-
-#endif // __CTBronchi__Functions__h__
-
-// eof - $RCSfile$
#include <chrono>
#include <map>
+
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
-#include <fpa/Filters/Image/Mori.h>
+#include <itkRegionOfInterestImageFilter.h>
+
+#include <fpa/Filters/BaseMarksInterface.h>
+#include <fpa/Filters/Image/SeedsFromLabelsInterface.h>
+#include <fpa/Filters/Image/DefaultTraits.h>
+#include <fpa/Filters/Image/RegionGrow.h>
+#include <fpa/Functors/RegionGrow/BinaryThreshold.h>
// -------------------------------------------------------------------------
const unsigned int Dim = 3;
typedef itk::Image< TPixel, Dim > TImage;
typedef itk::Image< TLabel, Dim > TLabels;
+/**
+ */
+class MoriLabellingTraits
+ : public fpa::Filters::Image::DefaultTraits< TImage, TLabels, TLabel >
+{
+public:
+ typedef fpa::Filters::Image::DefaultTraits< TImage, TLabels, TLabel > Superclass;
+ typedef typename Superclass::TInternalTraits TInternalTraits;
+ typedef typename Superclass::TMarksImage TMarksImage;
+ typedef typename Superclass::TFilterInterface TFilterInterface;
+
+ typedef fpa::Filters::BaseMarksInterface< TInternalTraits > TMarksInterface;
+ typedef fpa::Filters::Image::SeedsFromLabelsInterface< TInternalTraits > TSeedsInterface;
+};
+
+/**
+ */
+class MoriLabelling
+ : public fpa::Filters::Image::RegionGrow< TImage, TLabels, TLabel, MoriLabellingTraits >
+{
+public:
+ typedef MoriLabellingTraits TTraits;
+ fpaTraitsMacro( TTraits );
+
+ typedef fpa::Filters::Image::RegionGrow< TImage, TLabels, TMark, TTraits > Superclass;
+ typedef MoriLabelling Self;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+ typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor;
+
+public:
+ itkNewMacro( Self );
+ itkTypeMacro( MoriLabelling, fpa::Filters::Image::RegionGrow );
+
+ itkGetConstMacro( LastThreshold, TInputValue );
+ itkSetMacro( LastThreshold, TInputValue );
+
+ itkGetConstMacro( MinVertex, TVertex );
+ itkGetConstMacro( MaxVertex, TVertex );
+
+ fpaFilterInputMacro( InputLabels, TLabels );
+
+public:
+ TInputValue GetUpperThreshold( ) const
+ {
+ return( this->m_Functor->GetUpperThreshold( ) );
+ }
+ void SetUpperThreshold( TInputValue t )
+ {
+ this->m_Functor->SetUpperThreshold( t );
+ }
+
+protected:
+ MoriLabelling( )
+ : Superclass( ),
+ m_LastThreshold( TInputValue( 0 ) )
+ {
+ fpaFilterInputConfigureMacro( InputLabels, TLabels );
+ this->m_Functor = TFunctor::New( );
+ this->SetPredicate( this->m_Functor );
+ }
+
+ virtual ~MoriLabelling( )
+ {
+ }
+
+ virtual const itk::DataObject* _GetReferenceInput( ) const override
+ {
+ return( this->GetInputLabels( ) );
+ }
+ virtual void _BeforeGenerateData( ) override
+ {
+ this->Superclass::_BeforeGenerateData( );
+ this->m_FirstVertex = true;
+ }
+
+ virtual void _PostComputeOutputValue( TNode& n ) override
+ {
+ this->Superclass::_PostComputeOutputValue( n );
+ if( n.Value == this->GetInsideValue( ) )
+ {
+ const TImage* input = this->GetInput( );
+ const TLabels* labels = this->GetInputLabels( );
+ double x = input->GetPixel( n.Vertex );
+ /* TODO
+ double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
+ double b = std::fabs( x - double( this->m_LastThreshold ) );
+ */
+ if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
+ n.Value = 0;
+
+ if( !( this->m_FirstVertex ) )
+ {
+ for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
+ {
+ if( n.Vertex[ d ] < this->m_MinVertex[ d ] )
+ this->m_MinVertex[ d ] = n.Vertex[ d ];
+ if( this->m_MaxVertex[ d ] < n.Vertex[ d ] )
+ this->m_MaxVertex[ d ] = n.Vertex[ d ];
+
+ } // rof
+ }
+ else
+ {
+ this->m_MinVertex = n.Vertex;
+ this->m_MaxVertex = n.Vertex;
+ this->m_FirstVertex = false;
+
+ } // fi
+
+ } // fi
+ }
+
+private:
+ // Purposely not implemented.
+ MoriLabelling( const Self& other );
+ Self& operator=( const Self& other );
+
+protected:
+ TFunctor::Pointer m_Functor;
+ TInputValue m_LastThreshold;
+ bool m_FirstVertex;
+ TVertex m_MinVertex;
+ TVertex m_MaxVertex;
+};
+
// -------------------------------------------------------------------------
double MeasureTime( itk::ProcessObject* f )
{
// -------------------------------------------------------------------------
template< class _TImage >
-void WriteImage( const _TImage*image, const std::string& fname )
+void WriteImage( const _TImage* image, const std::string& fname )
{
typedef itk::ImageFileWriter< _TImage > _TWriter;
typename _TWriter::Pointer writer = _TWriter::New( );
std::cout << "Wrote " << fname << " in " << t << " s" << std::endl;
}
+// -------------------------------------------------------------------------
+template< class _TImagePtr, class _TRegion >
+void ROI(
+ _TImagePtr& output,
+ const typename _TImagePtr::ObjectType* input,
+ const _TRegion& roi
+ )
+{
+ typedef typename _TImagePtr::ObjectType _TImage;
+ typedef itk::RegionOfInterestImageFilter< _TImage, _TImage > _TFilter;
+
+ typename _TFilter::Pointer filter = _TFilter::New( );
+ filter->SetInput( input );
+ filter->SetRegionOfInterest( roi );
+ double t = MeasureTime( filter );
+ std::cout << "ROI computed in " << t << " s" << std::endl;
+ output = filter->GetOutput( );
+ output->DisconnectPipeline( );
+}
+
// -------------------------------------------------------------------------
bool ParseArgs(
std::map< std::string, std::string >& args, int argc, char* argv[]
<< "\t-in filename" << std::endl
<< "\t-out filename" << std::endl
<< "\t-labels filename" << std::endl
+ << "\t[-roi] filename" << std::endl
<< "\t[-upper_threshold value]" << std::endl;
return( false );
TLabels::Pointer input_labels;
ReadImage( input_labels, args[ "labels" ] );
- // Mori segmentation
+ // Mori labelling
+ MoriLabelling::Pointer labelling = MoriLabelling::New( );
+ labelling->SetInput( input_image );
+ labelling->SetInputLabels( input_labels );
+ labelling->SetOutsideValue( 2 );
+ labelling->SetInsideValue( 1 );
+ labelling->SetUpperThreshold(
+ TPixel( std::atof( args[ "upper_threshold" ].c_str( ) ) )
+ );
/* TODO
- typedef fpa::Filters::Image::Mori< TImage, TLabels > TMori;
- TMori::Pointer mori = TMori::New( );
- mori->SetInput( input_image );
- mori->SetSeed( seed );
- mori->SetInsideValue( 1 );
- mori->SetOutsideValue( 0 );
- mori->SetMinimumThreshold(
- TPixel( std::atof( args[ "minimum_threshold" ].c_str( ) ) )
- );
- mori->SetSignalKernelSize(
- std::atoi( args[ "signal_kernel_size" ].c_str( ) )
- );
- mori->SetSignalThreshold(
- std::atof( args[ "signal_threshold" ].c_str( ) )
- );
- mori->SetSignalInfluence(
- std::atof( args[ "signal_influence" ].c_str( ) )
- );
- mori->SetThresholds(
- TPixel( std::atof( args[ "lower_threshold" ].c_str( ) ) ),
- TPixel( std::atof( args[ "upper_threshold" ].c_str( ) ) ),
- TPixel( std::atof( args[ "delta_threshold" ].c_str( ) ) )
- );
- double t = MeasureTime( mori );
- std::cout << "Mori executed in " << t << " s" << std::endl;
- WriteImage( mori->GetOutput( ), args[ "out" ] );
-
- std::map< std::string, std::string >::const_iterator i =
- args.find( "out_signal" );
- if( i != args.end( ) )
- {
- std::stringstream signal;
- unsigned long nthr = mori->GetNumberOfEvaluatedThresholds( );
- signal << "# nThr = " << nthr << std::endl;
- signal << "# Opt = " << mori->GetOptimumThreshold( ) << std::endl;
- for( unsigned long j = 0; j < nthr; ++j )
- {
- typename TMori::TPeak p;
- double x, y;
- mori->GetSignalValues( j, x, y, p );
- signal << x << " " << y << std::endl;
-
- } // rof
- std::ofstream signals_str( i->second.c_str( ) );
- signals_str << signal.str( );
- signals_str.close( );
-
- } // fi
+ labelling->SetLastThreshold( last_thr );
*/
+ double t = MeasureTime( labelling );
+ std::cout << "Labelling executed in " << t << " s" << std::endl;
+
+ std::map< std::string, std::string >::const_iterator i =
+ args.find( "roi" );
+ if( i != args.end( ) )
+ {
+ TImage::IndexType minV = labelling->GetMinVertex( );
+ TImage::IndexType maxV = labelling->GetMaxVertex( );
+ TImage::SizeType roiS;
+ for( unsigned d = 0; d < TImage::ImageDimension; ++d )
+ roiS[ d ] = maxV[ d ] - minV[ d ] + 1;
+ TImage::RegionType roi;
+ roi.SetIndex( minV );
+ roi.SetSize( roiS );
+
+ // ROI input image
+ TImage::Pointer input_image_roi;
+ ROI( input_image_roi, input_image.GetPointer( ), roi );
+ WriteImage( input_image_roi.GetPointer( ), i->second );
+
+ // ROI output image
+ TLabels::Pointer output_roi;
+ ROI( output_roi, labelling->GetOutput( ), roi );
+ WriteImage( output_roi.GetPointer( ), args[ "out" ] );
+ }
+ else
+ WriteImage( labelling->GetOutput( ), args[ "out" ] );
}
else
return( 1 );
+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __CTBronchi__MoriLabelling__h__
-#define __CTBronchi__MoriLabelling__h__
-
-#include <map>
-#include <fpa/Filters/BaseMarksInterface.h>
-#include <fpa/Filters/Image/SeedsFromLabelsInterface.h>
-#include <fpa/Filters/Image/DefaultTraits.h>
-#include <fpa/Filters/Image/RegionGrow.h>
-#include <fpa/Functors/RegionGrow/BinaryThreshold.h>
-
-namespace CTBronchi
-{
- /**
- */
- template< class _TInputImage, class _TLabelImage >
- class MoriLabellingTraits
- : public fpa::Filters::Image::DefaultTraits< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType >
- {
- public:
- typedef _TInputImage TInputImage;
- typedef _TLabelImage TLabelImage;
- typedef typename TLabelImage::PixelType TLabel;
- typedef fpa::Filters::Image::DefaultTraits< TInputImage, TLabelImage, TLabel > Superclass;
- typedef typename Superclass::TInternalTraits TInternalTraits;
- typedef typename Superclass::TMarksImage TMarksImage;
- typedef typename Superclass::TFilterInterface TFilterInterface;
-
- typedef fpa::Filters::BaseMarksInterface< TInternalTraits > TMarksInterface;
- typedef fpa::Filters::Image::SeedsFromLabelsInterface< TInternalTraits > TSeedsInterface;
- };
-
- /**
- */
- template< class _TInputImage, class _TLabelImage >
- class MoriLabelling
- : public fpa::Filters::Image::RegionGrow< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType, CTBronchi::MoriLabellingTraits< _TInputImage, _TLabelImage > >
- {
- public:
- typedef _TInputImage TInputImage;
- typedef _TLabelImage TLabelImage;
- typedef CTBronchi::MoriLabellingTraits< TInputImage, TLabelImage > TTraits;
- fpaTraitsMacro( typename TTraits );
-
- typedef fpa::Filters::Image::RegionGrow< TInputImage, TLabelImage, TMark, TTraits > Superclass;
- typedef MoriLabelling Self;
- typedef itk::SmartPointer< Self > Pointer;
- typedef itk::SmartPointer< const Self > ConstPointer;
- typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor;
-
- public:
- itkNewMacro( Self );
- itkTypeMacro( CTBronchi::MoriLabelling, fpa::Filters::Image::RegionGrow );
-
- itkGetConstMacro( LastThreshold, TInputValue );
- itkSetMacro( LastThreshold, TInputValue );
-
- fpaFilterInputMacro( InputLabels, TLabelImage );
-
- public:
- TInputValue GetUpperThreshold( ) const;
- void SetUpperThreshold( TInputValue t );
-
- protected:
- MoriLabelling( );
- virtual ~MoriLabelling( );
-
- virtual const itk::DataObject* _GetReferenceInput( ) const override;
- virtual void _PostComputeOutputValue( TNode& n ) override;
-
- private:
- // Purposely not implemented.
- MoriLabelling( const Self& other );
- Self& operator=( const Self& other );
-
- protected:
- typename TFunctor::Pointer m_Functor;
- TInputValue m_LastThreshold;
- };
-
-} // ecapseman
-
-#ifndef ITK_MANUAL_INSTANTIATION
-# include <CTBronchi/MoriLabelling.hxx>
-#endif // ITK_MANUAL_INSTANTIATION
-#endif // __CTBronchi__MoriLabelling__h__
-
-// eof - $RCSfile$
+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __CTBronchi__MoriLabelling__hxx__
-#define __CTBronchi__MoriLabelling__hxx__
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetUpperThreshold( ) const
-{
- return( this->m_Functor->GetUpperThreshold( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetUpperThreshold( TInputValue t )
-{
- this->m_Functor->SetUpperThreshold( t );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-MoriLabelling( )
- : Superclass( ),
- m_LastThreshold( TInputValue( 0 ) )
-{
- fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
- this->m_Functor = TFunctor::New( );
- this->SetPredicate( this->m_Functor );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-~MoriLabelling( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-const itk::DataObject*
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-_GetReferenceInput( ) const
-{
- return( this->GetInputLabels( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-_PostComputeOutputValue( TNode& n )
-{
- this->Superclass::_PostComputeOutputValue( n );
- if( n.Value == this->GetInsideValue( ) )
- {
- const _TInputImage* input = this->GetInput( );
- const TLabelImage* labels = this->GetInputLabels( );
- double x = input->GetPixel( n.Vertex );
- /* TODO
- double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
- double b = std::fabs( x - double( this->m_LastThreshold ) );
- */
- if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
- n.Value = 0;
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-namespace CTBronchi
-{
- template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
- void Label(
- _TOutputPtr& output,
- const _TInputPtr& input, const _TOutputPtr& input_labels,
- const _TInputValue& last_thr,
- std::map< std::string, std::string >& args
- )
- {
- typedef typename _TInputPtr::ObjectType _TInput;
- typedef typename _TOutputPtr::ObjectType _TOutput;
- typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
-
- typename _TLabelling::Pointer labelling = _TLabelling::New( );
- labelling->SetInput( input );
- labelling->SetInputLabels( input_labels );
- labelling->SetOutsideValue( 2 );
- labelling->SetInsideValue( 1 );
- labelling->SetUpperThreshold(
- _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
- );
- labelling->SetLastThreshold( last_thr );
- double t = MeasureTime( labelling );
- std::cout << "Labelling executed in " << t << " s" << std::endl;
- output = labelling->GetOutput( );
- std::map< std::string, std::string >::const_iterator i =
- args.find( "out_labels" );
- if( i != args.end( ) )
- WriteImage( output, i->second );
- output->DisconnectPipeline( );
- }
-
-} // ecapseman
-#endif // __CTBronchi__MoriLabelling__hxx__
-
-// eof - $RCSfile$
// -------------------------------------------------------------------------
template< class _TImage >
-void WriteImage( const _TImage*image, const std::string& fname )
+void WriteImage( const _TImage* image, const std::string& fname )
{
typedef itk::ImageFileWriter< _TImage > _TWriter;
typename _TWriter::Pointer writer = _TWriter::New( );
+++ /dev/null
-// =========================================================================
-// @author Leonardo Florez Valencia
-// @email florez-l@javeriana.edu.co
-// =========================================================================
-#ifndef __CTBronchi__RandomWalker__h__
-#define __CTBronchi__RandomWalker__h__
-
-#include <map>
-#include <CTBronchi/Functions.h>
-#include <fpa/Filters/Image/RandomWalker.h>
-#include <fpa/Functors/Dijkstra/Image/Gaussian.h>
-
-namespace CTBronchi
-{
- // -----------------------------------------------------------------------
- template< class _TInputPtr, class _TLabelPtr >
- void RandomWalker(
- _TLabelPtr& output,
- const _TInputPtr& input, const _TLabelPtr& labels,
- std::map< std::string, std::string >& args
- )
- {
- typedef typename _TInputPtr::ObjectType _TInput;
- typedef typename _TLabelPtr::ObjectType _TLabel;
- typedef float _TScalar;
- typedef fpa::Filters::Image::RandomWalker< _TInput, _TLabel, _TScalar > _TRandomWalker;
- typedef fpa::Functors::Dijkstra::Image::Gaussian< _TInput, _TScalar > _TWeight;
-
- typename _TWeight::Pointer weight = _TWeight::New( );
- weight->SetAlpha( std::atof( args[ "random_walker_alpha" ].c_str( ) ) );
- weight->SetBeta( std::atof( args[ "random_walker_beta" ].c_str( ) ) );
-
- typename _TRandomWalker::Pointer rw = _TRandomWalker::New( );
- rw->SetInputImage( input );
- rw->SetInputLabels( labels );
- rw->SetWeightFunction( weight );
- double t = CTBronchi::MeasureTime( rw );
- std::cout << "RandomWalker executed in " << t << " s" << std::endl;
- output = rw->GetOutputLabels( );
- output->DisconnectPipeline( );
- }
-
-} // ecapseman
-
-#endif // __CTBronchi__Functions__h__
-
-// eof - $RCSfile$
// Allocate outputs
this->AllocateOutputs( );
- // Build boundary triplets and count labels
- _TTriplets St, Bt;
- std::map< TLabel, unsigned long > labels;
- this->_Boundary( St, labels );
- struct _TTripletsOrd
- {
- bool operator()( const _TTriplet& a, const _TTriplet& b )
- {
- return( a.row( ) < b.row( ) );
- }
- };
- std::sort( St.begin( ), St.end( ), _TTripletsOrd( ) );
- for( unsigned long i = 0; i < St.size( ); ++i )
- Bt.push_back( _TTriplet( i, labels[ St[ i ].col( ) ], St[ i ].value( ) ) );
-
- // Laplacian triplets
- _TTriplets At, Rt;
- this->_Laplacian( At, Rt, St );
-
- // Matrices
- TRegion region = input->GetRequestedRegion( );
- unsigned long nSeeds = St.size( );
- unsigned long nLabels = labels.size( );
- unsigned long N = region.GetNumberOfPixels( );
-
- std::vector< TLabel > invLabels( nLabels );
- for( typename std::map< TLabel, unsigned long >::value_type s: labels )
- invLabels[ s.second ] = s.first;
-
- _TMatrix B( nSeeds, nLabels );
- B.setFromTriplets( Bt.begin( ), Bt.end( ) );
- B.makeCompressed( );
-
- _TMatrix R( N - nSeeds, nSeeds );
- R.setFromTriplets( Rt.begin( ), Rt.end( ) );
- R.makeCompressed( );
-
- _TMatrix A( N - nSeeds, N - nSeeds );
- A.setFromTriplets( At.begin( ), At.end( ) );
- A.makeCompressed( );
+ // Persisting objects
+ _TMatrix A( 1, 1 ), C( 1, 1 );
+ _TTriplets St;
+ std::vector< TLabel > invLabels;
+
+ { // begin
+ // Build boundary triplets and count labels
+ _TTriplets Bt;
+ std::map< TLabel, unsigned long > labels;
+ itkDebugMacro( << "Building boundary matrix..." );
+ this->_Boundary( St, labels );
+ struct _TTripletsOrd
+ {
+ bool operator()( const _TTriplet& a, const _TTriplet& b )
+ {
+ return( a.row( ) < b.row( ) );
+ }
+ };
+ itkDebugMacro( << "Sorting boundary pixels..." );
+ std::sort( St.begin( ), St.end( ), _TTripletsOrd( ) );
+ itkDebugMacro( << "Assigning boundary pixels..." );
+ for( unsigned long i = 0; i < St.size( ); ++i )
+ Bt.push_back(
+ _TTriplet( i, labels[ St[ i ].col( ) ], St[ i ].value( ) )
+ );
+
+ // Laplacian triplets
+ itkDebugMacro( << "Building laplacian matrix..." );
+ _TTriplets At, Rt;
+ this->_Laplacian( At, Rt, St );
+
+ // Matrices
+ TRegion region = input->GetRequestedRegion( );
+ unsigned long nSeeds = St.size( );
+ unsigned long nLabels = labels.size( );
+ unsigned long N = region.GetNumberOfPixels( );
+
+ itkDebugMacro( << "Creating inverse labels..." );
+ invLabels.resize( nLabels );
+ for( typename std::map< TLabel, unsigned long >::value_type s: labels )
+ invLabels[ s.second ] = s.first;
+
+ itkDebugMacro( << "Creating B matrix..." );
+ _TMatrix B( nSeeds, nLabels );
+ B.setFromTriplets( Bt.begin( ), Bt.end( ) );
+ B.makeCompressed( );
+
+ itkDebugMacro( << "Creating R matrix..." );
+ _TMatrix R( N - nSeeds, nSeeds );
+ R.setFromTriplets( Rt.begin( ), Rt.end( ) );
+ R.makeCompressed( );
+
+ itkDebugMacro( << "Creating C matrix..." );
+ C = R * B;
+
+ itkDebugMacro( << "Creating A matrix..." );
+ A.resize( N - nSeeds, N - nSeeds );
+ A.setFromTriplets( At.begin( ), At.end( ) );
+ A.makeCompressed( );
+ } // end
// Solve dirichlet problem
_TSolver solver;
+ itkDebugMacro( << "Factorizing problem..." );
solver.compute( A );
if( solver.info( ) != Eigen::Success )
itkExceptionMacro( << "Error decomposing matrix." );
- _TMatrix x = solver.solve( R * B );
+ itkDebugMacro( << "Solving problem..." );
+ _TMatrix x = solver.solve( C );
if( solver.info( ) != Eigen::Success )
itkExceptionMacro( << "Error solving system." );
// Fill outputs
+ itkDebugMacro( << "Filling output..." );
this->_Output( x, St, invLabels );
}
filter->SetInput( input );
filter->SetInputLabels( labels );
filter->SetEdgeFunction( edge );
+ filter->DebugOn( );
double t = MeasureTime( filter );
output_labels = filter->GetOutput( );
output_probabilities = filter->GetOutputProbabilities( );
beta, epsilon
);
- WriteImage( original_labels, "orig.png" );
- WriteImage( fp_labels, "fp.png" );
+ WriteImage( original_labels, "orig.mhd" );
+ WriteImage( fp_labels, "fp.mhd" );
return( 0 );
}