[Insight-users] how to write a filter
Luis Ibanez
luis . ibanez at kitware . com
Fri, 14 Nov 2003 00:48:19 -0500
Hi Bing,
Even though your filter produces the same output region
as the input region you still need to declare and define
the GenerateOutputInformation() method.
You can simply copy/paste the one of the
itkUnaryFunctorFilter class in
Insight/Code/BasicFilters/itkUnaryFunctorFilter.txx
The region that you should process is the GenerateData()
method is the
"RequestedRegion"
of the output image.
You should not attempt to use the LargestPossible region
since it is possible that the entire image is not loaded
into memory.
Regards,
Luis
-------------------
Bing Jian wrote:
> Hi,
>
> I'm trying to study how to write my own ITK-style filters.
> I read the Chapter 13 "How to write a filter" in software guide.
> But still confused, especially about the region part.
>
> I started from a very simple one: the output image is just
> exactly copied from the input image. Since I want to keep
> the image size and other information, I thought I don't need
> to override the GenerateOutputInformation(). The only thing
> I did is to write the GenerateData() function as follows:
>
> template <class TInputImage, class TOutputImage>
> void MyFirstFilter<TInputImage,TOutputImage>
> ::GenerateData( )
> {
> InputImagePointer inputPtr = this->GetInput();
> OutputImagePointer outputPtr = this->GetOutput();
>
> unsigned int total = (outputPtr->GetRequestedRegion()).GetNumberOfPixels();
> std::cout << "total = " << total << std::endl;
>
> ImageRegionConstIterator<TInputImage> inputIt(inputPtr,
> inputPtr->GetLargestPossibleRegion()); // which region should be used
> ImageRegionIterator<TOutputImage> outputIt(outputPtr,
> inputPtr->GetLargestPossibleRegion()); // which region should be used
>
> unsigned int pos = 0;
> inputIt.GoToBegin();
> outputIt.GoToBegin();
> while(!outputIt.IsAtEnd())
> {
> outputIt.Set(inputIt.Get()); //*
> ++inputIt;
> ++outputIt;
> pos ++;
> }
> }
>
> I am not sure in the definition of iterators what kind of region
> should be used. The size of (outputPtr->GetBufferedRegion()) is 0.
> Although the size of outputPtr->GetRequestedRegion() and
> LargestPossibleRegion are correct, but if I use them, error occured
> during the walking of iterator. It turned out that when iterator
> passed through the first row, the program crashed. I don't know why?
> I thought I must miss something. Can anybody help me out?
> Thanks!
>
>
> --
> Best wishes,
> Bing Jian
> bjian at cise . ufl . edu
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>