It would be helpful to see the error that you are receiving. The below portion of code looks odd to me because you're comparing indices:<div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "> if (max<index) <br>
{<br> max = inputIterator.GetIndex(i); <br> }</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">I previously wrote a maximum image filter by modifying the mean image filter. It has the bells and whistles of an image filter like checking boundary conditions, etc. I attached the code for you to examine for your development.</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font><div class="gmail_quote">On Mon, Feb 28, 2011 at 10:22 AM, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">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" target="_blank">http://www.itk.org/Wiki/ITK/Examples/Iterators/ConstNeighborhoodIterator</a></i>. <br>
<br>Thanks<br><br><br>---------------------------max_value_neighborhood.cxx-----------------------------<br>--------------------------------------------------------------------------------------------------<br>#include "itkImage.h"<br>
#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br> <br>#include "max_value_filter.h"<br> <br>int main(int, char*[])<br>{<br> // Setup types<br> typedef itk::Image<unsigned char, 2> ImageType;<br>
typedef itk::max_value_filter<ImageType> FilterType;<br> <br> typedef itk::ImageFileReader<ImageType> ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetFileName("test.png");<br>
reader->Update();<br> <br> // Create and the filter<br> FilterType::Pointer filter = FilterType::New();<br> filter->SetInput(reader->GetOutput());<br> filter->Update();<br> <br> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName("result.png");<br> writer->SetInput(filter->GetOutput());<br> writer->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 "itkImageToImageFilter.h"<br> <br>namespace itk<br>{<br>template< class TImage><br>class max_value_filter:public ImageToImageFilter< TImage, TImage ><br>{<br>public:<br> /** Standard class typedefs. */<br>
typedef max_value_filter Self;<br> typedef ImageToImageFilter< TImage, TImage > Superclass;<br> typedef SmartPointer< Self > 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 &); //purposely not implemented<br> void operator=(const Self &); //purposely not implemented<br>
<br>
};<br>} //namespace ITK<br> <br> <br>#ifndef ITK_MANUAL_INSTANTIATION<br>#include "max_value_filter.txx"<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 "max_value_filter.h"<br>#include "itkObjectFactory.h"<br>
#include "itkImageRegionIterator.h"<br>#include "itkConstNeighborhoodIterator.h"<br> <br>namespace itk<br>{<br> <br>template< class TImage><br>void max_value_filter< TImage><br>::GenerateData()<br>
{<br> typename TImage::ConstPointer input = this->GetInput();<br> <br> typename TImage::Pointer output = this->GetOutput();<br> output->SetRegions(input->GetLargestPossibleRegion());<br> output->Allocate(); <br>
<br> itk::ImageRegionIterator<TImage> outputIterator(output, output->GetLargestPossibleRegion());<br> itk::ImageRegionConstIterator<TImage> inputIterator(input, input->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 < 9; i++)<br> {<br> TImage::IndexType index = inputIterator.GetIndex(i);<br>
<br><br> if (max<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>
<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>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<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>
<br></blockquote></div><br></div>