[Insight-users] creating my first finding max value in neighborhood

john smith mkitkinsightuser at gmail.com
Tue Mar 1 05:12:11 EST 2011


Hello to all,
 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. I have made some changes in my .txx file,
but  I am still having some problems when I build the project and I would
like some help:

#ifndef __itkmax_value_filter_txx
#define __itkmax_value_filter_txx

#include "max_value_filter.h"
#include "itkObjectFactory.h"
#include "itkImageRegionIterator.h"
#include "itkConstNeighborhoodIterator.h"

namespace itk
{

template< class TImage>
void max_value_filter< TImage>
::GenerateData()
{
  typename TImage::ConstPointer input = this->GetInput();

  typename TImage::Pointer output = this->GetOutput();
  output->SetRegions(input->GetLargestPossibleRegion());
  output->Allocate();

  itk::ImageRegionIterator<TImage> outputIterator(output,
output->GetLargestPossibleRegion());

  TImage::SizeType radius;
  radius[0] = 1;
  radius[1] = 1;

  itk::ConstNeighborhoodIterator<TImage> inputIterator(radius,input);
error C2664:
'itk::ConstNeighborhoodIterator<TImage>::ConstNeighborhoodIterator(const
itk::ConstNeighborhoodIterator<TImage> &)' : cannot convert parameter 1 from
'itk::Size<VDimension>' to 'const itk::ConstNeighborhoodIterator<TImage> &




  while(!inputIterator.IsAtEnd())
    {

    for(unsigned int i = 1; i < 9; i++)
      {
      TImage::IndexType index = inputIterator.GetIndex(i);

      }

    outputIterator.Set(index->GetMax());
 error C2065: 'index' : undeclared identifier
 error C2227: left of '->GetMax' must point to class/struct/union/generic
type

    ++inputIterator;
    ++outputIterator;
    }


}

}// end namespace


#endif

2011/3/1 Ryan Smith <ryanleesmith at gmail.com>

> Hi John-
> Did you get this up and running? Myself and others on the list would be
> interested in the final code you developed.  Thanks-
> -Ryan
>
> On Mon, Feb 28, 2011 at 8:05 AM, john smith <mkitkinsightuser at gmail.com>wrote:
>
>> I get these failures when I build my project.In the following lines I
>> write again my code and I highlight all the failures under the line on which
>> they have occured. Can you explain some of these mistakes as I am still
>> influenced in C?
>>
>>
>> ---------------------------
>> max_value_neighborhood.cxx-----------------------------
>>
>> --------------------------------------------------------------------------------------------------
>> #include "itkImage.h"
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>>
>> #include "max_value_filter.h"
>>
>> int main(int, char*[])
>> {
>>   // Setup types
>>   typedef itk::Image<unsigned char, 2>   ImageType;
>>   typedef itk::max_value_filter<ImageType>  FilterType;
>>
>>   typedef itk::ImageFileReader<ImageType> ReaderType;
>>   ReaderType::Pointer reader = ReaderType::New();
>>   reader->SetFileName("test.png");
>>   reader->Update();
>>
>>   // Create and the filter
>>   FilterType::Pointer filter = FilterType::New();
>>  see reference to class template instantiation
>> 'itk::max_value_filter<TImage>' being compiled
>>
>>   filter->SetInput(reader->GetOutput());
>>   filter->Update();
>>
>>   typedef  itk::ImageFileWriter< ImageType  > WriterType;
>>   WriterType::Pointer writer = WriterType::New();
>>   writer->SetFileName("result.png");
>>   writer->SetInput(filter->GetOutput());
>>   writer->Update();
>>
>>   return EXIT_SUCCESS;
>> }
>>
>>
>>
>> ----------------------------
>> max_value_filter.txx--------------------------------
>>
>> -------------------------------------------------------------------------------------
>> #ifndef __itkmax_value_filter_txx
>> #define __itkmax_value_filter_txx
>>
>> #include "max_value_filter.h"
>> #include "itkObjectFactory.h"
>> #include "itkImageRegionIterator.h"
>> #include "itkConstNeighborhoodIterator.h"
>>
>> namespace itk
>> {
>>
>> template< class TImage>
>> void max_value_filter< TImage>
>> ::GenerateData()
>> {
>>  while compiling class template member function 'void
>> itk::max_value_filter<TImage>::GenerateData(void)'
>>
>>   typename TImage::ConstPointer input = this->GetInput();
>>
>>   typename TImage::Pointer output = this->GetOutput();
>>   output->SetRegions(input->GetLargestPossibleRegion());
>>   output->Allocate();
>>
>>   itk::ImageRegionIterator<TImage> outputIterator(output,
>> output->GetLargestPossibleRegion());
>>   itk::ImageRegionConstIterator<TImage> inputIterator(input,
>> input->GetLargestPossibleRegion());
>>
>>
>>
>>
>>   while(!inputIterator.IsAtEnd())
>>     {
>>
>> TImage::IndexType max = inputIterator.GetIndex(0);
>>  'itk::ImageConstIterator<TImage>::GetIndex' : function does not take 1
>> arguments
>>
>>
>>     for(unsigned int i = 1; i < 9; i++)
>>       {
>>       TImage::IndexType index = inputIterator.GetIndex(i);
>>
>>
>>         if (max<index)
>> error C2676: binary '<' : 'itk::Index<VIndexDimension>' does not define
>> this operator or a conversion to a type acceptable to the predefined
>> operator
>>                       {
>>                         max = inputIterator.GetIndex(i);
>> error C2660: 'itk::ImageConstIterator<TImage>::GetIndex' : function does
>> not take 1 arguments
>>                        }
>>
>>
>>       bool IsInBounds;
>>       inputIterator.GetPixel(i, IsInBounds);
>>  'GetPixel' : is not a member of 'itk::ImageRegionConstIterator<TImage>'
>>
>>
>>       }
>>
>>     outputIterator.Set(inputIterator.Get(max));
>> error C2660: 'itk::ImageConstIterator<TImage>::Get' : function does not
>> take 1 arguments
>>
>>
>>     ++inputIterator;
>>     ++outputIterator;
>>     }
>>
>>
>> }
>>
>> }// end namespace
>>
>>
>> #endif
>>
>>
>>
>>
>>
>> 2011/2/28 David Doria <daviddoria at gmail.com>
>>
>> On Mon, Feb 28, 2011 at 10:22 AM, john smith <mkitkinsightuser at gmail.com>wrote:
>>>
>>>> Hi to all,
>>>>
>>>>  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*
>>>> http://www.itk.org/Wiki/ITK/Examples/Iterators/ConstNeighborhoodIterator
>>>> *.
>>>>
>>>> Thanks
>>>>
>>>>
>>> Can you describe the failures? Are they compiler errors? Crashes?
>>> Incorrect results?
>>>
>>> David
>>>
>>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.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/20110301/f02b5815/attachment.htm>


More information about the Insight-users mailing list