HI Michael,<br><br>Please check that the pixel at index 250,250 actually<br>has an intensity inside the range : 0 to 800.<br><br>    Regards,<br><br><br>              Luis<br>  <br><br>-----------------------------------------------------------<br>
<div class="gmail_quote">On Wed, Aug 12, 2009 at 5:28 AM, Michael Siegesmund <span dir="ltr">&lt;<a href="mailto:TheSmashingPumpkin@web.de">TheSmashingPumpkin@web.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi itk users,<br>
<br>
I tried to write my own filter class (inherited from ImageToImageFilter), which encapsulates the functionality of ConnectedThresholdImageFilter.cxx from examples/segmentation.<br>
So I took CompositeFilterExample.cxx (from examples/filters) as a template and replaced the core code with the one of ConnectedThresholdImageFilter.cxx.<br>
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.<br>
And it doesn&#39;t matter whether I use an imageviewer or a filewriter for output.<br>
The problem sounds like I forgot an important thing to do, for example initialize something. I tried hard, but couldn&#39;t find the bug.<br>
<br>
Do someone has an idea or a working example?<br>
<br>
Thanks in advance<br>
<br>
<br>
<br>
/////////////////////////////the header///////////////////////////////////<br>
#ifndef __ConnectedThresholdFilter_h<br>
#define __ConnectedThresholdFilter_h<br>
<br>
#ifdef _USE_ITK<br>
<br>
<br>
#include &quot;itkImageToImageFilter.h&quot;<br>
#include &quot;itkCurvatureFlowImageFilter.h&quot;<br>
#include &quot;itkConnectedThresholdImageFilter.h&quot;<br>
#include &quot;itkCastImageFilter.h&quot;<br>
#include &quot;itkNumericTraits.h&quot;<br>
<br>
<br>
namespace itk {<br>
<br>
template &lt;class TImageType, class TOutputType&gt;<br>
class ITK_EXPORT ConnectedThresholdFilter : public ImageToImageFilter&lt;TImageType, TOutputType&gt;<br>
{<br>
public:<br>
<br>
    typedef ConnectedThresholdFilter                 Self;<br>
    typedef ImageToImageFilter&lt;TImageType,TOutputType&gt;  Superclass;<br>
    typedef SmartPointer&lt;Self&gt;                          Pointer;<br>
    typedef SmartPointer&lt;const Self&gt;                    ConstPointer;<br>
<br>
    itkNewMacro(Self);<br>
    itkTypeMacro(ConnectedThresholdFilter, ImageToImageFilter);<br>
<br>
    void PrintSelf( std::ostream&amp; os, Indent indent ) const;<br>
<br>
protected:<br>
<br>
    ConnectedThresholdFilter();<br>
<br>
protected:<br>
<br>
    typedef itk::Image&lt; float, 3&gt; FloatType;<br>
<br>
    typedef itk::CurvatureFlowImageFilter&lt; TImageType, FloatType &gt;      CurvatureFlowImageFilterType;<br>
    typedef itk::ConnectedThresholdImageFilter&lt; FloatType, FloatType &gt;  ConnectedFilterType;<br>
    typedef itk::CastImageFilter&lt; FloatType, TOutputType &gt;              CastingFilterType;<br>
<br>
    void GenerateData();<br>
<br>
private:<br>
<br>
  ConnectedThresholdFilter(Self&amp;);   // intentionally not implemented<br>
  void operator=(const Self&amp;);          // intentionally not implemented<br>
<br>
  typename CurvatureFlowImageFilterType::Pointer smoothing;<br>
  typename ConnectedFilterType::Pointer connectedThreshold;<br>
  typename CastingFilterType::Pointer caster;<br>
<br>
};<br>
<br>
} /* namespace itk */<br>
<br>
#ifndef ITK_MANUAL_INSTANTIATION<br>
#include &quot;ConnectedThresholdFilter.cpp&quot;<br>
#endif<br>
<br>
#endif _USE_ITK<br>
<br>
#endif<br>
<br>
<br>
<br>
//////////the class/////////////////////////////////////////<br>
#ifndef __ConnectedThresholdFilter_cpp<br>
#define __ConnectedThresholdFilter_cpp<br>
<br>
#ifdef _USE_ITK<br>
<br>
#include &quot;ConnectedThresholdFilter.h&quot;<br>
<br>
<br>
namespace itk<br>
{<br>
<br>
template &lt;class TImageType, class TOutputType&gt;<br>
ConnectedThresholdFilter&lt;TImageType, TOutputType&gt;::ConnectedThresholdFilter()<br>
{<br>
    smoothing = CurvatureFlowImageFilterType::New();<br>
    connectedThreshold = ConnectedFilterType::New();<br>
    caster = CastingFilterType::New();<br>
<br>
    connectedThreshold-&gt;SetInput( smoothing-&gt;GetOutput() );<br>
    caster-&gt;SetInput( connectedThreshold-&gt;GetOutput() );<br>
<br>
    smoothing-&gt;SetNumberOfIterations( 5 );<br>
    smoothing-&gt;SetTimeStep( 0.125 );<br>
<br>
    connectedThreshold-&gt;SetLower(  0  );<br>
    connectedThreshold-&gt;SetUpper(  800  );<br>
    connectedThreshold-&gt;SetReplaceValue( 255 );<br>
<br>
    TImageType::IndexType  index;<br>
    index[0] = 250;<br>
    index[1] = 250;<br>
    connectedThreshold-&gt;SetSeed( index );<br>
}<br>
<br>
template &lt;class TImageType, class TOutputType&gt;<br>
void ConnectedThresholdFilter&lt;TImageType, TOutputType&gt;::GenerateData()<br>
{<br>
    smoothing-&gt;SetInput(this-&gt;GetInput());<br>
    caster-&gt;GraftOutput( this-&gt;GetOutput() );<br>
    caster-&gt;Update();<br>
    this-&gt;GraftOutput( caster-&gt;GetOutput() );<br>
}<br>
<br>
<br>
template &lt;class TImageType, class TOutputType&gt;<br>
void ConnectedThresholdFilter&lt;TImageType, TOutputType&gt;::PrintSelf( std::ostream&amp; os, Indent indent ) const<br>
{<br>
  Superclass::PrintSelf(os,indent);<br>
  //not implemented yet<br>
}<br>
<br>
} /* end namespace itk */<br>
<br>
<br>
#endif _USE_ITK<br>
<br>
#endif<br>
<br>
<br>
<br>
///////this is how i call it //////////////////////////<br>
    typedef itk::Image&lt;short, 3&gt;                        ImageType;<br>
    typedef itk::Image&lt;unsigned char, 3&gt;                OutputType;<br>
    typedef itk::ImageFileWriter&lt;OutputType&gt;             WriterType;<br>
    typedef itk::ConnectedThresholdFilter&lt;ImageType,OutputType&gt; FilterType1;<br>
<br>
    WriterType::Pointer writer = WriterType::New();<br>
    FilterType1::Pointer filter = FilterType1::New();<br>
<br>
    //the input works!<br>
    filter-&gt;SetInput(m_Dicomreader-&gt;GetITKOutput() );<br>
    writer-&gt;SetInput( filter-&gt;GetOutput() );<br>
    writer-&gt;SetFileName( &quot;c://example.png&quot; );<br>
<br>
    try<br>
    {<br>
        writer-&gt;Update(); // so here I got a black image<br>
    }<br>
    catch ( itk::ExceptionObject e )<br>
    {<br>
        std::cerr &lt;&lt; &quot;Error: &quot; &lt;&lt; e &lt;&lt; std::endl;<br>
    }<br>
<br>
<br>
<br>
________________________________________________________________<br>
Neu: <a href="http://WEB.DE" target="_blank">WEB.DE</a> Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate<br>
für nur 19,99 Euro/mtl.!* <a href="http://produkte.web.de/go/02/" target="_blank">http://produkte.web.de/go/02/</a><br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br>