21 #ifndef __itkBSplineResampleImageFilterBase_txx
22 #define __itkBSplineResampleImageFilterBase_txx
33 template <
class TInputImage,
class TOutputImage>
40 this->SetSplineOrder(SplineOrder);
46 template <
class TInputImage,
class TOutputImage>
53 Superclass::PrintSelf( os, indent );
54 os << indent <<
"Spline Order: " << m_SplineOrder << std::endl;
60 template <
class TInputImage,
class TOutputImage>
104 m_G[10] = -0.00480004;
105 m_G[11] = -0.00320734;
106 m_G[12] = 0.00214306;
107 m_G[13] = 0.00143195;
108 m_G[14] = -0.0009568;
109 m_G[15] = -0.000639312;
117 m_H[7] = -0.00295859;
119 m_H[9] = 0.000507614;
136 m_G[10] = -0.00861788;
137 m_G[11] = -0.00627964;
138 m_G[12] = 0.00456713;
139 m_G[13] = 0.00332464;
140 m_G[14] = -0.00241916;
141 m_G[15] = -0.00176059;
142 m_G[16] = 0.00128128;
143 m_G[17] = 0.000932349;
144 m_G[18] = -0.000678643;
145 m_G[19] = -0.000493682;
153 m_H[7] = -0.00914725;
157 m_H[11] = -0.000656743;
163 err.
SetDescription(
"SplineOrder for l2 pyramid filter must be between 1 and 3. Requested spline order has not been implemented." );
170 template <
class TInputImage,
class TOutputImage>
174 if (splineOrder == m_SplineOrder)
178 m_SplineOrder = splineOrder;
180 this->InitializePyramidSplineFilter(m_SplineOrder);
189 template <
class TInputImage,
class TOutputImage>
197 unsigned int outK, inK;
198 unsigned int outTraverseSize = inTraverseSize/2;
199 inTraverseSize = outTraverseSize*2;
201 inModK = inTraverseSize - 1;
210 for (outK = 0; outK < outTraverseSize; outK++)
214 if (i2 > (
int) inModK )
219 i2 = inModK - (i2 % inModK);
221 out.
Set( static_cast<OutputImagePixelType> ( ( in[inK] + in[i2] ) / 2.0 ) );
229 for (outK = 0; outK < outTraverseSize; outK++)
233 outVal = in[inK] * m_G[0];
235 for (
int i = 1; i < m_GSize; i++)
248 if (i2 > (
int) inModK)
255 outVal = outVal + m_G[i]*(in[i1] + in[i2]);
257 out.
Set( static_cast<OutputImagePixelType> (outVal) );
268 template <
class TInputImage,
class TOutputImage>
277 unsigned int outTraverseSize = inTraverseSize * 2;
280 inModK = inTraverseSize - 1;
289 for (inK = 0; inK < inTraverseSize; inK++)
291 out.
Set( static_cast<OutputImagePixelType> (in[inK]) );
293 out.
Set( static_cast<OutputImagePixelType> (in[inK]) );
301 for (outK = 0; outK < (int) outTraverseSize; outK++)
304 for (
int k = (outK % 2); k < (int) m_HSize; k += 2)
306 i1 = ( outK - k ) / 2;
314 outVal = outVal + m_H[k] * in[i1];
316 for(
int k = 2 - ( outK % 2); k < (int) m_HSize; k += 2 )
327 outVal += m_H[k] * in[i2];
330 out.
Set( static_cast<OutputImagePixelType> (outVal) );
341 template <
class TInputImage,
class TOutputImage>
351 startSize = inputPtr->GetBufferedRegion().GetSize();
354 InitializeScratch(startSize);
355 typename TOutputImage::Pointer scratchImage;
356 scratchImage = TOutputImage::New();
357 scratchImage->CopyInformation( inputPtr );
359 scratchRegion = inputPtr->GetBufferedRegion();
360 currentSize = startSize;
365 currentSize[0] = currentSize[0]/2;
366 scratchRegion.SetSize( currentSize );
367 scratchImage->SetRegions( scratchRegion );
368 scratchImage->Allocate();
371 currentSize = startSize;
372 validRegion.SetSize( currentSize );
373 validRegion.SetIndex ( inputPtr->GetBufferedRegion().GetIndex() );
386 typename TInputImage::ConstPointer workingImage;
387 workingImage = inputPtr;
389 unsigned int count = scratchRegion.GetNumberOfPixels() * ImageDimension;
391 for (
unsigned int n=0; n < ImageDimension; n++)
413 currentSize[n] = currentSize[n]/2;
414 validRegion.SetSize(currentSize);
417 if (n == ( ImageDimension - 1) )
420 outIterator = outItr;
428 while (!inIterator1.
IsAtEnd() )
431 this->CopyInputLineToScratch( inIterator1 );
433 this->Reduce1DImage( m_Scratch, outIterator, startSize[n], progress );
440 while (!inIterator2.
IsAtEnd() )
443 this->CopyOutputLineToScratch( inIterator2 );
445 this->Reduce1DImage( m_Scratch, outIterator, startSize[n], progress );
460 template <
class TInputImage,
class TOutputImage>
471 startSize = inputPtr->GetBufferedRegion().GetSize();
475 InitializeScratch(startSize);
476 typename TOutputImage::Pointer scratchImage;
477 scratchImage = TOutputImage::New();
478 scratchImage->CopyInformation( inputPtr );
480 scratchRegion = inputPtr->GetBufferedRegion();
481 currentSize = startSize;
485 for (
unsigned int n = 0; n < ImageDimension; n++)
487 currentSize[n] = currentSize[n] * 2;
489 scratchRegion.SetSize( currentSize );
490 scratchImage->SetBufferedRegion( scratchRegion );
491 scratchImage->Allocate();
494 currentSize = startSize;
495 validRegion.SetSize( currentSize );
496 validRegion.SetIndex ( inputPtr->GetBufferedRegion().GetIndex() );
509 typename TInputImage::ConstPointer workingImage;
510 workingImage = inputPtr;
514 unsigned int count = scratchRegion.GetNumberOfPixels() * ImageDimension;
516 for (
unsigned int n=0; n < ImageDimension; n++)
536 currentSize[n] = currentSize[n] * 2;
537 validRegion.SetSize(currentSize);
540 if (n == ( ImageDimension - 1) )
543 outIterator = outItr;
552 while (!inIterator1.
IsAtEnd() )
555 this->CopyInputLineToScratch( inIterator1 );
557 this->Expand1DImage( m_Scratch, outIterator, startSize[n], progress );
564 while (!inIterator2.
IsAtEnd() )
567 this->CopyOutputLineToScratch( inIterator2 );
569 this->Expand1DImage( m_Scratch, outIterator, startSize[n], progress );
580 template <
class TInputImage,
class TOutputImage>
584 unsigned int maxLength = 0;
585 for (
unsigned int n = 0; n < ImageDimension; n++ )
587 if ( DataLength[n] > maxLength )
589 maxLength = DataLength[n];
592 m_Scratch.resize( maxLength );
595 template <
class TInputImage,
class TOutputImage>
602 m_Scratch[j] =
static_cast<double>( Iter.
Get() );
609 template <
class TInputImage,
class TOutputImage>
616 m_Scratch[j] =
static_cast<double>( Iter.
Get() );
622 template <
class TInputImage,
class TOutputImage>
629 m_Scratch[j] =
static_cast<double>( Iter.
Get() );