[Insight-users] ImageToImageFilter output problem

Luis Ibanez luis.ibanez at kitware.com
Sat Aug 15 20:25:12 EDT 2009


HI Michael,

Please check that the pixel at index 250,250 actually
has an intensity inside the range : 0 to 800.

    Regards,


              Luis


-----------------------------------------------------------
On Wed, Aug 12, 2009 at 5:28 AM, Michael Siegesmund <
TheSmashingPumpkin at web.de> wrote:

> Hi itk users,
>
> I tried to write my own filter class (inherited from ImageToImageFilter),
> which encapsulates the functionality of ConnectedThresholdImageFilter.cxx
> from examples/segmentation.
> So I took CompositeFilterExample.cxx (from examples/filters) as a template
> and replaced the core code with the one of
> ConnectedThresholdImageFilter.cxx.
> Afterwards I figured out, that I can use my new class for filtering a png
> file but if I want to process a CT-image from a dicom reader (which works
> fine with other filters!) I always get a black screen.
> And it doesn't matter whether I use an imageviewer or a filewriter for
> output.
> The problem sounds like I forgot an important thing to do, for example
> initialize something. I tried hard, but couldn't find the bug.
>
> Do someone has an idea or a working example?
>
> Thanks in advance
>
>
>
> /////////////////////////////the header///////////////////////////////////
> #ifndef __ConnectedThresholdFilter_h
> #define __ConnectedThresholdFilter_h
>
> #ifdef _USE_ITK
>
>
> #include "itkImageToImageFilter.h"
> #include "itkCurvatureFlowImageFilter.h"
> #include "itkConnectedThresholdImageFilter.h"
> #include "itkCastImageFilter.h"
> #include "itkNumericTraits.h"
>
>
> namespace itk {
>
> template <class TImageType, class TOutputType>
> class ITK_EXPORT ConnectedThresholdFilter : public
> ImageToImageFilter<TImageType, TOutputType>
> {
> public:
>
>    typedef ConnectedThresholdFilter                 Self;
>    typedef ImageToImageFilter<TImageType,TOutputType>  Superclass;
>    typedef SmartPointer<Self>                          Pointer;
>    typedef SmartPointer<const Self>                    ConstPointer;
>
>    itkNewMacro(Self);
>    itkTypeMacro(ConnectedThresholdFilter, ImageToImageFilter);
>
>    void PrintSelf( std::ostream& os, Indent indent ) const;
>
> protected:
>
>    ConnectedThresholdFilter();
>
> protected:
>
>    typedef itk::Image< float, 3> FloatType;
>
>    typedef itk::CurvatureFlowImageFilter< TImageType, FloatType >
>  CurvatureFlowImageFilterType;
>    typedef itk::ConnectedThresholdImageFilter< FloatType, FloatType >
>  ConnectedFilterType;
>    typedef itk::CastImageFilter< FloatType, TOutputType >
>  CastingFilterType;
>
>    void GenerateData();
>
> private:
>
>  ConnectedThresholdFilter(Self&);   // intentionally not implemented
>  void operator=(const Self&);          // intentionally not implemented
>
>  typename CurvatureFlowImageFilterType::Pointer smoothing;
>  typename ConnectedFilterType::Pointer connectedThreshold;
>  typename CastingFilterType::Pointer caster;
>
> };
>
> } /* namespace itk */
>
> #ifndef ITK_MANUAL_INSTANTIATION
> #include "ConnectedThresholdFilter.cpp"
> #endif
>
> #endif _USE_ITK
>
> #endif
>
>
>
> //////////the class/////////////////////////////////////////
> #ifndef __ConnectedThresholdFilter_cpp
> #define __ConnectedThresholdFilter_cpp
>
> #ifdef _USE_ITK
>
> #include "ConnectedThresholdFilter.h"
>
>
> namespace itk
> {
>
> template <class TImageType, class TOutputType>
> ConnectedThresholdFilter<TImageType,
> TOutputType>::ConnectedThresholdFilter()
> {
>    smoothing = CurvatureFlowImageFilterType::New();
>    connectedThreshold = ConnectedFilterType::New();
>    caster = CastingFilterType::New();
>
>    connectedThreshold->SetInput( smoothing->GetOutput() );
>    caster->SetInput( connectedThreshold->GetOutput() );
>
>    smoothing->SetNumberOfIterations( 5 );
>    smoothing->SetTimeStep( 0.125 );
>
>    connectedThreshold->SetLower(  0  );
>    connectedThreshold->SetUpper(  800  );
>    connectedThreshold->SetReplaceValue( 255 );
>
>    TImageType::IndexType  index;
>    index[0] = 250;
>    index[1] = 250;
>    connectedThreshold->SetSeed( index );
> }
>
> template <class TImageType, class TOutputType>
> void ConnectedThresholdFilter<TImageType, TOutputType>::GenerateData()
> {
>    smoothing->SetInput(this->GetInput());
>    caster->GraftOutput( this->GetOutput() );
>    caster->Update();
>    this->GraftOutput( caster->GetOutput() );
> }
>
>
> template <class TImageType, class TOutputType>
> void ConnectedThresholdFilter<TImageType, TOutputType>::PrintSelf(
> std::ostream& os, Indent indent ) const
> {
>  Superclass::PrintSelf(os,indent);
>  //not implemented yet
> }
>
> } /* end namespace itk */
>
>
> #endif _USE_ITK
>
> #endif
>
>
>
> ///////this is how i call it //////////////////////////
>    typedef itk::Image<short, 3>                        ImageType;
>    typedef itk::Image<unsigned char, 3>                OutputType;
>    typedef itk::ImageFileWriter<OutputType>             WriterType;
>    typedef itk::ConnectedThresholdFilter<ImageType,OutputType> FilterType1;
>
>    WriterType::Pointer writer = WriterType::New();
>    FilterType1::Pointer filter = FilterType1::New();
>
>    //the input works!
>    filter->SetInput(m_Dicomreader->GetITKOutput() );
>    writer->SetInput( filter->GetOutput() );
>    writer->SetFileName( "c://example.png" );
>
>    try
>    {
>        writer->Update(); // so here I got a black image
>    }
>    catch ( itk::ExceptionObject e )
>    {
>        std::cerr << "Error: " << e << std::endl;
>    }
>
>
>
> ________________________________________________________________
> Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090815/18d41df5/attachment.htm>


More information about the Insight-users mailing list