20 #include <itkImageRegionIterator.h>
35 : m_Image( inputImage )
59 for(GradientDirectionsContainerType::ConstIterator gdcitOld = directions->Begin();
60 gdcitOld != directions->End(); ++gdcitOld)
64 for(GradientDirectionsContainerType::ConstIterator gdcitNew = newDirections->Begin();
65 gdcitNew != newDirections->End(); ++gdcitNew)
67 if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision))
77 newDirections->push_back(gdcitOld.Value());
91 CalcAveragedDirectionSet(precision, oldDirs);
94 if(oldDirs->size() == newDirs->size())
101 newITKImage->SetSpacing( oldImage->GetSpacing() );
102 newITKImage->SetOrigin( oldImage->GetOrigin() );
103 newITKImage->SetDirection( oldImage->GetDirection() );
104 newITKImage->SetLargestPossibleRegion( oldImage->GetLargestPossibleRegion() );
105 newITKImage->SetVectorLength( newDirs->size() );
106 newITKImage->SetBufferedRegion( oldImage->GetLargestPossibleRegion() );
107 newITKImage->Allocate();
110 itk::ImageRegionIterator< ImageType > newIt(newITKImage, newITKImage->GetLargestPossibleRegion());
112 itk::ImageRegionIterator< ImageType > oldIt(oldImage, oldImage->GetLargestPossibleRegion());
117 newVec.SetSize(newDirs->size());
118 newVec.AllocateElements(newDirs->size());
122 std::vector<std::vector<int> > dirIndices;
123 for(GradientDirectionsContainerType::ConstIterator gdcitNew = newDirs->Begin();
124 gdcitNew != newDirs->End(); ++gdcitNew)
126 dirIndices.push_back(std::vector<int>(0));
127 for(GradientDirectionsContainerType::ConstIterator gdcitOld = oldDirs->Begin();
128 gdcitOld != oldDirections->End(); ++gdcitOld)
130 if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision))
133 dirIndices[gdcitNew.Index()].push_back(gdcitOld.Index());
139 while(!newIt.IsAtEnd())
152 for(
unsigned int i=0; i<dirIndices.size(); i++)
155 const unsigned int numavg = dirIndices[i].size();
156 unsigned int sum = 0;
157 for(
unsigned int j=0; j<numavg; j++)
160 sum += oldVec[dirIndices[i].at(j)];
164 MITK_ERROR <<
"VectorImage: Error on averaging. Possibly due to corrupted data";
167 newVec[i] = sum / numavg;
180 ApplyMeasurementFrame();
182 std::cout << std::endl;
199 if( originalDirections.IsNull() || ( originalDirections->size() == 0 ) )
206 for(GradientDirectionsContainerType::ConstIterator gdcit = originalDirections->Begin();
207 gdcit != originalDirections->End(); ++gdcit)
209 vnl_vector<double> vec = gdcit.Value();
210 vec = vec.pre_multiply(measurementFrame);
211 directions->InsertElement(c, vec);
230 if(!b_ValueMap.empty())
239 GradientDirectionsContainerType::ConstIterator gdcit;
240 for( gdcit = directions->Begin(); gdcit != directions->End(); ++gdcit)
242 b_ValueMap[GetB_Value(gdcit.Index())].push_back(gdcit.Index());
255 return diff.two_norm() < precision || diff2.two_norm() < precision;
264 if(i > directions->Size()-1)
267 if(directions->ElementAt(i).one_norm() <= 0.0)
273 double twonorm = directions->ElementAt(i).two_norm();
274 double bval = b_value*twonorm*twonorm;
277 bval = ceil(bval - 0.5);
279 bval = floor(bval + 0.5);
287 this->ApplyMeasurementFrame();
288 this->UpdateBValueMap();
296 identity.set_identity();
305 if ( node->
GetData()==nullptr )
307 return IsDiffusionWeightedImage(dynamic_cast<mitk::Image *>(node->
GetData()));
313 bool isDiffusionWeightedImage(
true );
315 if( image ==
nullptr )
317 isDiffusionWeightedImage =
false;
320 if( isDiffusionWeightedImage )
324 if( referenceBValue.IsNull() )
326 isDiffusionWeightedImage =
false;
331 unsigned int gradientDirections( 0 );
332 if( isDiffusionWeightedImage )
336 if( gradientDirectionsProperty.IsNull() )
338 isDiffusionWeightedImage =
false;
342 gradientDirections = gradientDirectionsProperty->GetGradientDirectionsContainer()->size();
346 if( isDiffusionWeightedImage )
350 if( components != gradientDirections )
352 isDiffusionWeightedImage =
false;
356 return isDiffusionWeightedImage;
376 identity.set_identity();
380 return mf->GetMeasurementFrame();
395 return IsDiffusionWeightedImage(m_Image);
400 return GetBValueMap(m_Image);
405 return GetReferenceBValue(m_Image);
410 return GetMeasurementFrame(m_Image);
415 return GetOriginalGradientContainer(m_Image);
420 return GetGradientContainer(m_Image);
bool IsDiffusionWeightedImage() const
const MeasurementFrameType & GetMeasurementFrame() const
void AverageRedundantGradients(double precision)
static const std::string REFERENCEBVALUEPROPERTYNAME
itk::SmartPointer< Self > Pointer
mitk::BValueMapProperty::BValueMap BValueMapType
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
~DiffusionPropertyHelper()
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
static const std::string MEASUREMENTFRAMEPROPERTYNAME
const BValueMapType & GetBValueMap() const
DiffusionPropertyHelper()
void InitializeImage()
Make certain the owned image is up to date with all necessary properties.
static ImageType::Pointer GetItkVectorImage(Image *image)
Image class for storing images.
void ApplyMeasurementFrame()
Apply the previouse set MeasurementFrame to all gradients in the GradientsDirectionContainer (m_Direc...
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
const GradientDirectionsContainerType::Pointer GetGradientDirectionsContainer() const
GradientDirectionsProperty::GradientDirectionType GradientDirectionType
GradientDirectionsContainerType::Pointer CalcAveragedDirectionSet(double precision, GradientDirectionsContainerType::Pointer directions)
void UpdateBValueMap()
Update the BValueMap (m_B_ValueMap) using the current gradient directions (m_Directions) ...
bool AreAlike(GradientDirectionType g1, GradientDirectionType g2, double precision)
Determines whether gradients can be considered to be equal.
float GetReferenceBValue() const
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
float GetB_Value(unsigned int i)
Get the b value belonging to an index.
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
GradientDirectionsContainerType::Pointer GetGradientContainer() const
GradientDirectionsContainerType::Pointer GetOriginalGradientContainer() const
mitk::MeasurementFrameProperty::MeasurementFrameType MeasurementFrameType
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
static const std::string GRADIENTCONTAINERPROPERTYNAME
static const std::string MODALITY
static const std::string BVALUEMAPPROPERTYNAME
Class for nodes of the DataTree.
static const std::string ORIGINALGRADIENTCONTAINERPROPERTYNAME
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.