Hi to all,<br><br> I am trying to develop my first filter in itk using visualstudio2010 and cmake. This filter devides my input image into neighborhoods of nine pixels and finds their maximum value. Then, this value is transfered to one pixel of my output image. I have written the following code, but I have some failures that I cannot understand. Could someone help me to overide my problems? Furthermore, I would like to know if it is possible to write my own filter only with .cxx and .txt files, like<i> <a href="http://www.itk.org/Wiki/ITK/Examples/Iterators/ConstNeighborhoodIterator">http://www.itk.org/Wiki/ITK/Examples/Iterators/ConstNeighborhoodIterator</a></i>. <br>
<br>Thanks<br><br><br>---------------------------max_value_neighborhood.cxx-----------------------------<br>--------------------------------------------------------------------------------------------------<br>#include &quot;itkImage.h&quot;<br>
#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br> <br>#include &quot;max_value_filter.h&quot;<br> <br>int main(int, char*[])<br>{<br>  // Setup types<br>  typedef itk::Image&lt;unsigned char, 2&gt;   ImageType;<br>
  typedef itk::max_value_filter&lt;ImageType&gt;  FilterType;<br> <br>  typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;<br>  ReaderType::Pointer reader = ReaderType::New();<br>  reader-&gt;SetFileName(&quot;test.png&quot;);<br>
  reader-&gt;Update();<br> <br>  // Create and the filter<br>  FilterType::Pointer filter = FilterType::New();<br>  filter-&gt;SetInput(reader-&gt;GetOutput());<br>  filter-&gt;Update();<br> <br>  typedef  itk::ImageFileWriter&lt; ImageType  &gt; WriterType;<br>
  WriterType::Pointer writer = WriterType::New();<br>  writer-&gt;SetFileName(&quot;result.png&quot;);<br>  writer-&gt;SetInput(filter-&gt;GetOutput());<br>  writer-&gt;Update();<br> <br>  return EXIT_SUCCESS;<br>}<br><br>
<br>------------------------------------------max_value_filter.h-----------------------<br>--------------------------------------------------------------------------------------<br>#ifndef __itkmax_value_filter_h<br>#define __itkmax_value_filter_h<br>
 <br>#include &quot;itkImageToImageFilter.h&quot;<br> <br>namespace itk<br>{<br>template&lt; class TImage&gt;<br>class max_value_filter:public ImageToImageFilter&lt; TImage, TImage &gt;<br>{<br>public:<br>  /** Standard class typedefs. */<br>
  typedef max_value_filter             Self;<br>  typedef ImageToImageFilter&lt; TImage, TImage &gt; Superclass;<br>  typedef SmartPointer&lt; Self &gt;        Pointer;<br> <br>  /** Method for creation through the object factory. */<br>
  itkNewMacro(Self);<br> <br>  /** Run-time type information (and related methods). */<br>  itkTypeMacro(max_value_filter, ImageToImageFilter);<br> <br>protected:<br>  max_value_filter(){}<br>  ~max_value_filter(){}<br> <br>
  /** Does the real work. */<br>  virtual void GenerateData();<br> <br>private:<br>  max_value_filter(const Self &amp;); //purposely not implemented<br>  void operator=(const Self &amp;);  //purposely not implemented<br> <br>
};<br>} //namespace ITK<br> <br> <br>#ifndef ITK_MANUAL_INSTANTIATION<br>#include &quot;max_value_filter.txx&quot;<br>#endif<br> <br> <br>#endif // __max_value_filter_h<br><br><br>----------------------------max_value_filter.txx--------------------------------<br>
-------------------------------------------------------------------------------------<br>#ifndef __itkmax_value_filter_txx<br>#define __itkmax_value_filter_txx<br> <br>#include &quot;max_value_filter.h&quot;<br>#include &quot;itkObjectFactory.h&quot;<br>
#include &quot;itkImageRegionIterator.h&quot;<br>#include &quot;itkConstNeighborhoodIterator.h&quot;<br> <br>namespace itk<br>{<br> <br>template&lt; class TImage&gt;<br>void max_value_filter&lt; TImage&gt;<br>::GenerateData()<br>
{<br>  typename TImage::ConstPointer input = this-&gt;GetInput();<br> <br>  typename TImage::Pointer output = this-&gt;GetOutput();<br>  output-&gt;SetRegions(input-&gt;GetLargestPossibleRegion());<br>  output-&gt;Allocate();  <br>
 <br>  itk::ImageRegionIterator&lt;TImage&gt; outputIterator(output, output-&gt;GetLargestPossibleRegion());<br>  itk::ImageRegionConstIterator&lt;TImage&gt; inputIterator(input, input-&gt;GetLargestPossibleRegion());<br>
 <br> <br><br><br>  while(!inputIterator.IsAtEnd())<br>    {<br><br>TImage::IndexType max = inputIterator.GetIndex(0);<br><br>    for(unsigned int i = 1; i &lt; 9; i++)<br>      {<br>      TImage::IndexType index = inputIterator.GetIndex(i);<br>
     <br><br>        if (max&lt;index) <br>                      {<br>                        max = inputIterator.GetIndex(i);                       <br>                      }<br><br> <br>      bool IsInBounds;<br>      inputIterator.GetPixel(i, IsInBounds);<br>
 <br>      }<br><br>    outputIterator.Set(inputIterator.Get(max));<br><br>    ++inputIterator;<br>    ++outputIterator;<br>    }<br><br> <br>}<br> <br>}// end namespace<br> <br> <br>#endif<br><br><br><br>----------------------CMakeLists.txt------------------------------<br>
------------------------------------------------------------------------<br>cmake_minimum_required(VERSION 2.6)<br> <br>PROJECT(max_value_filter)<br> <br>FIND_PACKAGE(ITK REQUIRED)<br>INCLUDE(${ITK_USE_FILE})<br> <br>ADD_EXECUTABLE(max_value_filter max_value_neighborhood.cxx)<br>
TARGET_LINK_LIBRARIES(max_value_filter ITKBasicFilters ITKIO ITKCommon)<br>