diff --git a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionImageFilter.txx b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionImageFilter.txx index 966cf87cbe..9e80f6288f 100644 --- a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionImageFilter.txx +++ b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionImageFilter.txx @@ -1,118 +1,119 @@ /*========================================================================= Program: Insight Segmentation & Registration Toolkit Language: C++ Date: $Date: 2006-07-19 15:11:41 $ Version: $Revision: 1.11 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __itkB0ImageExtractionImageFilter_txx #define __itkB0ImageExtractionImageFilter_txx #include "itkB0ImageExtractionImageFilter.h" + namespace itk { template< class TInputImagePixelType, class TOutputImagePixelType > B0ImageExtractionImageFilter< TInputImagePixelType, TOutputImagePixelType > ::B0ImageExtractionImageFilter() { // At least 1 inputs is necessary for a vector image. // For images added one at a time we need at least six this->SetNumberOfRequiredInputs( 1 ); } template< class TInputImagePixelType, class TOutputImagePixelType > void B0ImageExtractionImageFilter< TInputImagePixelType, TOutputImagePixelType > ::GenerateData() { typename GradientDirectionContainerType::Iterator begin = m_Directions->Begin(); typename GradientDirectionContainerType::Iterator end = m_Directions->End(); // Find the index of the b0 image std::vector indices; int index = 0; while(begin!=end) { GradientDirectionType grad = begin->Value(); if(grad[0] == 0 && grad[1] == 0 && grad[2] == 0) { indices.push_back(index); } ++index; ++begin; } typedef itk::Image TempImageType; TempImageType::Pointer tmp = TempImageType::New(); typename TempImageType::RegionType region = this->GetInput()->GetLargestPossibleRegion(); tmp->SetSpacing(this->GetInput()->GetSpacing()); tmp->SetOrigin(this->GetInput()->GetOrigin()); tmp->SetDirection(this->GetInput()->GetDirection()); tmp->SetRegions(region); tmp->Allocate(); itk::ImageRegionIterator it(tmp.GetPointer(), tmp->GetLargestPossibleRegion() ); itk::ImageRegionConstIterator vectorIt(this->GetInput(), this->GetInput()->GetLargestPossibleRegion() ); it.GoToBegin(); while(!it.IsAtEnd()) { it.Set(0); ++it; } //Sum all images that have zero diffusion weighting (indices stored in vector index) for(std::vector::iterator indexIt = indices.begin(); indexIt != indices.end(); indexIt++) { it.GoToBegin(); vectorIt.GoToBegin(); while(!it.IsAtEnd() && !vectorIt.IsAtEnd()) { typename InputImageType::PixelType vec = vectorIt.Get(); it.Set((1.0 * it.Get()) + (1.0 * vec[*indexIt]) / (1.0 * indices.size())); ++it; ++vectorIt; } } typename OutputImageType::Pointer b0Image = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0)); typename OutputImageType::RegionType outregion = this->GetInput()->GetLargestPossibleRegion(); b0Image->SetSpacing(this->GetInput()->GetSpacing()); b0Image->SetOrigin(this->GetInput()->GetOrigin()); b0Image->SetDirection(this->GetInput()->GetDirection()); b0Image->SetRegions(outregion); b0Image->Allocate(); itk::ImageRegionIterator itIn(tmp, tmp->GetLargestPossibleRegion() ); itk::ImageRegionIterator itOut(b0Image, b0Image->GetLargestPossibleRegion() ); itIn.GoToBegin(); itOut.GoToBegin(); while(!itIn.IsAtEnd()) { itOut.Set(itIn.Get()); ++itIn; ++itOut; } } } #endif // __itkB0ImageExtractionImageFilter_txx diff --git a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx index 0196078323..8e57627dc4 100644 --- a/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx +++ b/Modules/DiffusionImaging/Algorithms/itkB0ImageExtractionToSeparateImageFilter.txx @@ -1,39 +1,87 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __itkB0ImageExtractionToSeparateImageFilter_txx #define __itkB0ImageExtractionToSeparateImageFilter_txx #include "itkB0ImageExtractionToSeparateImageFilter.h" template< class TInputImagePixelType, class TOutputImagePixelType> itk::B0ImageExtractionToSeparateImageFilter< TInputImagePixelType, TOutputImagePixelType > ::B0ImageExtractionToSeparateImageFilter() : B0ImageExtractionImageFilter< TInputImagePixelType, TOutputImagePixelType >() { } template< class TInputImagePixelType, class TOutputImagePixelType> void itk::B0ImageExtractionToSeparateImageFilter< TInputImagePixelType, TOutputImagePixelType >::GenerateData() { + typename GradientDirectionContainerType::Iterator begin = m_Directions->Begin(); + typename GradientDirectionContainerType::Iterator end = m_Directions->End(); + + // Find the index of the b0 image + std::vector indices; + int index = 0; + while(begin!=end) + { + GradientDirectionType grad = begin->Value(); + + if(grad[0] == 0 && grad[1] == 0 && grad[2] == 0) + { + indices.push_back(index); + } + ++index; + ++begin; + } + + typedef itk::Image TempImageType; + TempImageType::Pointer tmp = TempImageType::New(); + typename TempImageType::RegionType region = this->GetInput()->GetLargestPossibleRegion(); + + // allocate image with + // - dimension: [DimX, DimY, DimZ, NumOfb0 ] + // - spacing: old one, 1.0 time + + TempImageType::SpacingType spacing; + spacing.Fill(1); + + TempImageType::OriginType origin; + origin.Fill(0); + + for (unsigned int i=0; i< 3; i++) + { + spacing[i] = (this->GetInput()->GetSpacing())[i]; + origin[i] = (this->GetInput()->GetOrigin())[i]; + } + + // extract b0 and insert them as a new time step + //Sum all images that have zero diffusion weighting (indices stored in vector index) + for(std::vector::iterator indexIt = indices.begin(); + indexIt != indices.end(); + indexIt++) + { + + } + + } #endif // ifndef __itkB0ImageExtractionToSeparateImageFilter_txx