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"><<a href="mailto:TheSmashingPumpkin@web.de">TheSmashingPumpkin@web.de</a>></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'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'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 "itkImageToImageFilter.h"<br>
#include "itkCurvatureFlowImageFilter.h"<br>
#include "itkConnectedThresholdImageFilter.h"<br>
#include "itkCastImageFilter.h"<br>
#include "itkNumericTraits.h"<br>
<br>
<br>
namespace itk {<br>
<br>
template <class TImageType, class TOutputType><br>
class ITK_EXPORT ConnectedThresholdFilter : public ImageToImageFilter<TImageType, TOutputType><br>
{<br>
public:<br>
<br>
typedef ConnectedThresholdFilter Self;<br>
typedef ImageToImageFilter<TImageType,TOutputType> Superclass;<br>
typedef SmartPointer<Self> Pointer;<br>
typedef SmartPointer<const Self> ConstPointer;<br>
<br>
itkNewMacro(Self);<br>
itkTypeMacro(ConnectedThresholdFilter, ImageToImageFilter);<br>
<br>
void PrintSelf( std::ostream& os, Indent indent ) const;<br>
<br>
protected:<br>
<br>
ConnectedThresholdFilter();<br>
<br>
protected:<br>
<br>
typedef itk::Image< float, 3> FloatType;<br>
<br>
typedef itk::CurvatureFlowImageFilter< TImageType, FloatType > CurvatureFlowImageFilterType;<br>
typedef itk::ConnectedThresholdImageFilter< FloatType, FloatType > ConnectedFilterType;<br>
typedef itk::CastImageFilter< FloatType, TOutputType > CastingFilterType;<br>
<br>
void GenerateData();<br>
<br>
private:<br>
<br>
ConnectedThresholdFilter(Self&); // intentionally not implemented<br>
void operator=(const Self&); // 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 "ConnectedThresholdFilter.cpp"<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 "ConnectedThresholdFilter.h"<br>
<br>
<br>
namespace itk<br>
{<br>
<br>
template <class TImageType, class TOutputType><br>
ConnectedThresholdFilter<TImageType, TOutputType>::ConnectedThresholdFilter()<br>
{<br>
smoothing = CurvatureFlowImageFilterType::New();<br>
connectedThreshold = ConnectedFilterType::New();<br>
caster = CastingFilterType::New();<br>
<br>
connectedThreshold->SetInput( smoothing->GetOutput() );<br>
caster->SetInput( connectedThreshold->GetOutput() );<br>
<br>
smoothing->SetNumberOfIterations( 5 );<br>
smoothing->SetTimeStep( 0.125 );<br>
<br>
connectedThreshold->SetLower( 0 );<br>
connectedThreshold->SetUpper( 800 );<br>
connectedThreshold->SetReplaceValue( 255 );<br>
<br>
TImageType::IndexType index;<br>
index[0] = 250;<br>
index[1] = 250;<br>
connectedThreshold->SetSeed( index );<br>
}<br>
<br>
template <class TImageType, class TOutputType><br>
void ConnectedThresholdFilter<TImageType, TOutputType>::GenerateData()<br>
{<br>
smoothing->SetInput(this->GetInput());<br>
caster->GraftOutput( this->GetOutput() );<br>
caster->Update();<br>
this->GraftOutput( caster->GetOutput() );<br>
}<br>
<br>
<br>
template <class TImageType, class TOutputType><br>
void ConnectedThresholdFilter<TImageType, TOutputType>::PrintSelf( std::ostream& 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<short, 3> ImageType;<br>
typedef itk::Image<unsigned char, 3> OutputType;<br>
typedef itk::ImageFileWriter<OutputType> WriterType;<br>
typedef itk::ConnectedThresholdFilter<ImageType,OutputType> FilterType1;<br>
<br>
WriterType::Pointer writer = WriterType::New();<br>
FilterType1::Pointer filter = FilterType1::New();<br>
<br>
//the input works!<br>
filter->SetInput(m_Dicomreader->GetITKOutput() );<br>
writer->SetInput( filter->GetOutput() );<br>
writer->SetFileName( "c://example.png" );<br>
<br>
try<br>
{<br>
writer->Update(); // so here I got a black image<br>
}<br>
catch ( itk::ExceptionObject e )<br>
{<br>
std::cerr << "Error: " << e << 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>