Пример #1
0
void mitk::OverwriteSliceImageFilter::ItkImageProcessing(const itk::Image<TPixel1, VImageDimension1> *inputImage,
                                                         itk::Image<TPixel2, VImageDimension2> *outputImage)
{
  typedef itk::Image<TPixel1, VImageDimension1> SliceImageType;
  typedef itk::Image<short signed int, VImageDimension1> DiffImageType;
  typedef itk::Image<TPixel2, VImageDimension2> VolumeImageType;

  typedef itk::ImageSliceIteratorWithIndex<VolumeImageType> OutputSliceIteratorType;
  typedef itk::ImageRegionConstIterator<SliceImageType> InputSliceIteratorType;
  typedef itk::ImageRegionIterator<DiffImageType> DiffSliceIteratorType;

  typename VolumeImageType::RegionType sliceInVolumeRegion;

  sliceInVolumeRegion = outputImage->GetLargestPossibleRegion();
  sliceInVolumeRegion.SetSize(m_SliceDimension, 1);             // just one slice
  sliceInVolumeRegion.SetIndex(m_SliceDimension, m_SliceIndex); // exactly this slice, please

  OutputSliceIteratorType outputIterator(outputImage, sliceInVolumeRegion);
  outputIterator.SetFirstDirection(m_Dimension0);
  outputIterator.SetSecondDirection(m_Dimension1);

  InputSliceIteratorType inputIterator(inputImage, inputImage->GetLargestPossibleRegion());

  typename DiffImageType::Pointer diffImage;
  CastToItkImage(m_SliceDifferenceImage, diffImage);
  DiffSliceIteratorType diffIterator(diffImage, diffImage->GetLargestPossibleRegion());

  // iterate over output slice (and over input slice simultaneously)
  outputIterator.GoToBegin();
  inputIterator.GoToBegin();
  diffIterator.GoToBegin();
  while (!outputIterator.IsAtEnd())
  {
    while (!outputIterator.IsAtEndOfSlice())
    {
      while (!outputIterator.IsAtEndOfLine())
      {
        diffIterator.Set(static_cast<short signed int>(inputIterator.Get() -
                                                       outputIterator.Get())); // oh oh, not good for bigger values
        outputIterator.Set((TPixel2)inputIterator.Get());
        ++outputIterator;
        ++inputIterator;
        ++diffIterator;
      }
      outputIterator.NextLine();
    }
    outputIterator.NextSlice();
  }
}
void mitk::CorrectorAlgorithm::ItkCalculateDifferenceImage( itk::Image<TPixel, VImageDimension>* originalImage, Image* modifiedMITKImage )
{
  typedef itk::Image<ipMITKSegmentationTYPE, VImageDimension>                     ModifiedImageType;
  typedef itk::Image<short signed int, VImageDimension>                           DiffImageType;
  typedef itk::ImageRegionConstIterator< itk::Image<TPixel,VImageDimension> >     OriginalSliceIteratorType;
  typedef itk::ImageRegionConstIterator< ModifiedImageType >                      ModifiedSliceIteratorType;
  typedef itk::ImageRegionIterator< DiffImageType >                               DiffSliceIteratorType;

  typename ModifiedImageType::Pointer modifiedImage;
  CastToItkImage( modifiedMITKImage, modifiedImage );
  
  // create new image as a copy of the input
  // this new image is the output of this filter class
  typename DiffImageType::Pointer diffImage;
  m_DifferenceImage = Image::New();
  PixelType pixelType( typeid(short signed int) );
  m_DifferenceImage->Initialize( pixelType, 2, modifiedMITKImage->GetDimensions() );
  CastToItkImage( m_DifferenceImage, diffImage );

  // iterators over both input images (original and modified) and the output image (diff)
  ModifiedSliceIteratorType modifiedIterator( modifiedImage, diffImage->GetLargestPossibleRegion() );
  OriginalSliceIteratorType originalIterator( originalImage, diffImage->GetLargestPossibleRegion() );
  DiffSliceIteratorType         diffIterator( diffImage,     diffImage->GetLargestPossibleRegion() );

  modifiedIterator.GoToBegin();
  originalIterator.GoToBegin();
  diffIterator.GoToBegin();
 
  while ( !diffIterator.IsAtEnd() )
  {
    short signed int difference = static_cast<short signed int>( static_cast<signed int>(modifiedIterator.Get()) - 
                                                          static_cast<signed int>(originalIterator.Get())); // not good for bigger values ?!
    diffIterator.Set( difference );
    
    ++modifiedIterator;
    ++originalIterator;
    ++diffIterator;
  }
}