25 #include "vnl/vnl_math.h"
26 #include "vnl/vnl_cost_function.h"
27 #include "vnl/vnl_least_squares_function.h"
28 #include "vnl/algo/vnl_lbfgsb.h"
29 #include "vnl/algo/vnl_lbfgs.h"
31 #include "vnl/algo/vnl_levenberg_marquardt.h"
35 #include <itkGaussianBlurImageFunction.h>
36 #include <itkUnaryFunctorImageFilter.h>
38 #include <itkImageFileWriter.h>
40 #include <itkVectorIndexSelectionCastImageFilter.h>
41 #include <itkComposeImageFilter.h>
42 #include <itkDiscreteGaussianImageFilter.h>
46 typedef itk::DiscreteGaussianImageFilter< itk::Image<DPH::DiffusionPixelType, 3 >, itk::Image<DPH::DiffusionPixelType, 3 > > GaussianFilterType;
48 typedef itk::VectorIndexSelectionCastImageFilter< DPH::ImageType, itk::Image<DPH::DiffusionPixelType, 3 > > IndexSelectionType;
50 indexSelectionFilter->SetInput( vectorImage );
52 typedef itk::ComposeImageFilter< itk::Image<DPH::DiffusionPixelType, 3>,
DPH::ImageType > ComposeFilterType;
55 for(
unsigned int i=0; i<vectorImage->GetVectorLength(); ++i)
59 indexSelectionFilter->SetIndex( i );
61 gaussian_filter->SetInput( indexSelectionFilter->GetOutput() );
62 gaussian_filter->SetVariance( sigma );
64 vec_composer->SetInput(i, gaussian_filter->GetOutput() );
66 gaussian_filter->Update();
71 vec_composer->Update();
73 catch(
const itk::ExceptionObject &e)
75 mitkThrow() <<
"[VectorImage.GaussianSmoothing] !! Failed with ITK Exception: " << e.what();
87 return smoothed_vector;
105 kurtosis_filter->SetNumberOfThreads(1);
107 KurtosisFilterType::OutputImageRegionType o_region;
108 KurtosisFilterType::OutputImageRegionType::SizeType o_size;
109 KurtosisFilterType::OutputImageRegionType::IndexType o_index;
111 o_index.Fill(0); o_size.Fill(0);
112 o_index[0] = 48; o_index[1] = 18; o_index[2] = 12;
113 o_size[0] = 16; o_size[1] = 24; o_size[2] = 1;
115 o_region.SetSize( o_size );
116 o_region.SetIndex( o_index );
117 kurtosis_filter->SetMapOutputRegion( o_region );
121 kurtosis_filter->Update();
123 catch(
const itk::ExceptionObject& e)
125 mitkThrow() <<
"Kurtosis fit failed with an ITK Exception: " << e.what();
129 d_image->InitializeByItk( kurtosis_filter->GetOutput(0) );
130 d_image->SetVolume( kurtosis_filter->GetOutput(0)->GetBufferPointer() );
133 k_image->InitializeByItk( kurtosis_filter->GetOutput(1) );
134 k_image->SetVolume( kurtosis_filter->GetOutput(1)->GetBufferPointer() );
136 std::string outputD_FileName = output_prefix +
"_ADC_map.nrrd";
137 std::string outputK_FileName = output_prefix +
"_AKC_map.nrrd";
144 catch(
const itk::ExceptionObject& e)
146 mitkThrow() <<
"Failed to save the KurtosisFit Results due to exception: " << e.what();
151 int main(
int argc,
char* argv[] )
157 parser.
setTitle(
"Diffusion IVIM (Kurtosis) Fit");
172 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
173 if (parsedArgs.size()==0)
177 std::string inFileName =
us::any_cast<std::string>(parsedArgs[
"input"]);
178 std::string out_prefix =
us::any_cast<std::string>(parsedArgs[
"output"]);
179 std::string fit_name =
us::any_cast<std::string>(parsedArgs[
"fit"]);
184 MITK_ERROR(
"DiffusionIVIMFit.Input") <<
"No valid diffusion-weighted image provided, failed to load " << inFileName <<
" as DW Image. Aborting...";
188 if( fit_name ==
"Kurtosis" )
190 MITK_INFO(
"DiffusionIVIMFit.Main") <<
"-----[ Kurtosis Fit ]-----";
195 else if (fit_name ==
"IVIM" )
197 MITK_INFO(
"DiffusionIVIMFit.Main") <<
"IVIM Fit not fully implemented yet. Aborting...";
202 MITK_ERROR(
"DiffusionIVIMFit.Main") <<
"Unrecognized option: " << fit_name <<
". Valid values [\"IVIM\", \"Kurtosis\"] \n Aborting... \n";
bool IsDiffusionWeightedImage() const
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
itk::SmartPointer< Self > Pointer
DPH::ImageType::Pointer GetBlurredVectorImage(DPH::ImageType::Pointer vectorImage, double sigma)
void setContributor(std::string contributor)
Helper class for mitk::Images containing diffusion weighted data.
ValueType * any_cast(Any *operand)
void KurtosisMapComputation(mitk::Image::Pointer input, std::string output_prefix)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
mitk::DiffusionPropertyHelper DPH
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
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.
GradientDirectionsContainerType::Pointer GetGradientContainer() const
This filter provides the fit of the kurtosis (non-IVIM) signal to the data.
void setTitle(std::string title)
void setDescription(std::string description)
int main(int argc, char *argv[])
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
itk::VectorImage< DiffusionPixelType, 3 > ImageType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.