[Insight-users] (no subject)

john smith mkitkinsightuser at gmail.com
Tue Mar 1 09:38:26 EST 2011


Hello,

Well, I have made all the changes and my program gives me (I think) correct
results. But I have some questions to continue my project. As a following
step, I want to write all my max values from every neighborhood iterator in
a single pixel of an output image. How can organize my max values as an
object (maybe by creating a new region iterator?), to put it through a new
writer filter, in order to take my output image? Also, supposing that I have
taken my output image, then this project which will be consisted of an .cxx
and  .txt file format (for visual studio and cmake), could be considered as
a new developed Filter?

Thanks

#include "itkImage.h"
#include "itkImageFileReader.h"


#include "itkConstNeighborhoodIterator.h"

int main(int argc, char*argv[])
{
  unsigned int max, index, counter;

    if(argc < 2)
    {
    std::cerr << "Required: filename" << std::endl;
    return EXIT_FAILURE;
    }

  typedef itk::Image<unsigned char, 2>  ImageType;

  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(argv[1]);
  reader->Update();

  ImageType::Pointer image = reader->GetOutput();

  ImageType::SizeType regionSize;
  regionSize[0] = 50;
  regionSize[1] = 50;

  ImageType::IndexType regionIndex;
  regionIndex[0] = 0;
  regionIndex[1] = 0;

  ImageType::RegionType region;
  region.SetSize(regionSize);
  region.SetIndex(regionIndex);

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


  itk::ConstNeighborhoodIterator<ImageType> inputIterator(radius,
image,region);


 counter=0;
  while(!inputIterator.IsAtEnd())
    {

 max = inputIterator.GetPixel(0);
 counter = counter+1;
    for(unsigned int i = 1; i < 9; i++)
      {

     index = inputIterator.GetPixel(i);

        if ( max < index)
                      {
                        max ==
inputIterator.GetPixel(i);
                      }

      }

    std::cout << max << std::endl;

    ++inputIterator;

    }

 std::cout << counter << " counter" << std::endl;


  return EXIT_SUCCESS;
}

2011/3/1 David Doria <daviddoria at gmail.com>

> On Tue, Mar 1, 2011 at 6:46 AM, john smith <mkitkinsightuser at gmail.com>wrote:
>
>> Hello to everyone,
>> I am trying to read an input image, using a reader object. Then devide the
>> image, using neighborhood iterator and finally, find the max value of every
>> neighborhood iterator and get it on my command prompt window. I think that
>> this can be done wtith the following code, but when I build it, it doesn't
>> recognise the ' < ' operator.  Can somebody help me? (I use visualstudoi
>> 2010 and Cmake)
>>
>> thnaks in advance
>>
>>
> You are trying to compare two Index objects, for which the < operator is
> not implemented. I think you want to change GetIndex to GetPixel in both
> cases:
>
> ImageType::IndexType max = inputIterator.GetIndex(0);
> ...
> ImageType::IndexType index = inputIterator.GetIndex(i);
>
> David
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110301/1f17c71d/attachment.htm>


More information about the Insight-users mailing list