├── LICENSE ├── README.md ├── TORTOISEV4 ├── CMakeLists.txt ├── README.md └── tools │ └── README.md ├── external_libraries └── bet │ └── Linux │ ├── betokan.h │ ├── libbetokan.a │ ├── libbetokan2.a │ └── libbetokan_orig.a ├── settings ├── defaults.dmc ├── mecc_settings │ ├── cubic.mec │ ├── cubic_isoc.mec │ ├── justeddy.mec │ ├── justeddy_isoc.mec │ ├── quadratic.mec │ ├── quadratic_isoc.mec │ └── rigid.mec └── system_settings │ └── default_system_settings.json └── src ├── README.md ├── cuda_src ├── compute_entropy.cu ├── compute_entropy.cxx ├── compute_entropy.h ├── compute_metric.cu ├── compute_metric.cxx ├── compute_metric.h ├── compute_mi_cuda.cu ├── compute_mi_cuda.cxx ├── compute_mi_cuda.h ├── cuda_image.cxx ├── cuda_image.h ├── cuda_image_utilities.cu ├── cuda_image_utilities.cxx ├── cuda_image_utilities.h ├── cuda_utils.h ├── gaussian_smooth_image.cu ├── gaussian_smooth_image.cxx ├── gaussian_smooth_image.h ├── quadratic_transform_image.cu ├── quadratic_transform_image.cxx ├── quadratic_transform_image.h ├── register_dwi_to_b0_cuda.cxx ├── register_dwi_to_b0_cuda.h ├── register_dwi_to_slice_cuda.h ├── resample_image.cu ├── resample_image.cxx ├── resample_image.h ├── rigid_transform_image.cu ├── rigid_transform_image.cxx ├── rigid_transform_image.h ├── warp_image.cu ├── warp_image.cxx └── warp_image.h ├── external_src ├── cmpfit-1.3a │ ├── DISCLAIMER │ ├── Makefile │ ├── README │ ├── libmpfit.a │ ├── mpfit.c │ ├── mpfit.h │ ├── mpfit.o │ ├── testmpfit │ ├── testmpfit.c │ └── testmpfit.log └── json_nlohmann │ └── json.hpp ├── main ├── DIFFPREP.cxx ├── DIFFPREP.h ├── DRBUDDI.cxx ├── DRBUDDI.h ├── DRBUDDIBase.cxx ├── DRBUDDIBase.h ├── DRBUDDI_Diffeo.cxx ├── DRBUDDI_Diffeo.h ├── DiffusionModel.h ├── EPIREG.cxx ├── EPIREG.h ├── FINALDATA.cxx ├── FINALDATA.h ├── OmpThreadBase.h ├── TORTOISE.cxx ├── TORTOISE.h ├── TORTOISE_global.cxx ├── TORTOISE_parser.cxx ├── TORTOISE_parser.h ├── antsCommandLineOption.cxx ├── antsCommandLineOption.h ├── antsCommandLineParser.cxx ├── antsCommandLineParser.h ├── compute_metrics (copy).h ├── compute_metrics.h ├── compute_metrics_cc.h ├── compute_metrics_ccjacs.h ├── compute_metrics_ccsk.h ├── compute_metrics_msjac (copy).h ├── compute_metrics_msjac.h ├── create_mask.cxx ├── create_mask.h ├── defines.cxx ├── defines.h ├── drbuddi_image_utilities.cxx ├── drbuddi_image_utilities.h ├── drbuddi_structs.h ├── itkBSplineInterpolateImageFunctionOkan.h ├── itkBSplineInterpolateImageFunctionOkan.hxx ├── itkDIFFPREPGradientDescentOptimizer.cxx ├── itkDIFFPREPGradientDescentOptimizer.h ├── itkDIFFPREPGradientDescentOptimizerv4.cxx ├── itkDIFFPREPGradientDescentOptimizerv4.h ├── itkInvertDisplacementFieldImageFilterOkan.h ├── itkInvertDisplacementFieldImageFilterOkan.hxx ├── itkLinearInterpolateImageFunctionOkan.h ├── itkLinearInterpolateImageFunctionOkan.hxx ├── itkMattesMutualInformationImageToImageMetricv4Okan.h ├── itkMattesMutualInformationImageToImageMetricv4Okan.hxx ├── itkOkanImageRegistrationMethodv4.h ├── itkOkanImageRegistrationMethodv4.hxx ├── itkOkanQuadraticTransform.h ├── itkOkanQuadraticTransform.hxx ├── main.cxx ├── mecc_settings.h ├── register_dwi_to_b0.cxx ├── register_dwi_to_b0.h ├── register_dwi_to_slice.h ├── registration_settings.h ├── rigid_register_images.cxx ├── rigid_register_images.h ├── run_drbuddi_stage.cxx ├── run_drbuddi_stage.h ├── run_drbuddi_stage_TVVF.cxx └── run_drbuddi_stage_TVVF.h ├── tools ├── ApplyTransformationToScalar2 │ └── ApplyTransformationToScalar2.cxx ├── Combine3DImagesTo4D │ └── Combine3DImagesTo4D.cxx ├── CombineDWIs │ ├── combine_4dimages.cxx │ ├── combine_dwis_main.cxx │ ├── combine_dwis_with_bmatrix.h │ └── combine_dwis_with_bmatrix_main.cxx ├── ComputeADMap │ └── compute_ad_map.cxx ├── ComputeDECMap │ ├── compute_dec_map.cxx │ ├── compute_dec_map_parser.cxx │ ├── compute_dec_map_parser.h │ ├── compute_wldec_map.cxx │ └── compute_wpdec_map.cxx ├── ComputeEigVecImage │ └── compute_eigvec_image.cxx ├── ComputeFAMap │ ├── compute_fa_map.cxx │ └── compute_fa_map.h ├── ComputeGlyphMaps │ ├── compute_glyph_maps (copy).cxx │ ├── compute_glyph_maps.cxx │ ├── vtkTensorGlyphOkan.cxx │ └── vtkTensorGlyphOkan.h ├── ComputeLIMap │ ├── compute_li_map.cxx │ └── compute_li_map.h ├── ComputeLineField │ └── ComputeLineField.cxx ├── ComputeMAPMRI_NG │ └── estimate_mapmri_ng.cxx ├── ComputeMAPMRI_PA │ └── estimate_mapmri_pa.cxx ├── ComputeMAPMRI_RTOP │ └── estimate_mapmri_rtop.cxx ├── ComputeMODEMap │ └── compute_mode_map.cxx ├── ComputeNSDECMap │ ├── compute_ns_dec_map.cxx │ ├── compute_ns_dec_map_original.cxx │ ├── compute_ns_dec_map_parser.cxx │ └── compute_ns_dec_map_parser.h ├── ComputeRDMap │ └── compute_rd_map.cxx ├── ComputeRTOPDTIMaps │ └── compute_rtop_dti_maps.cxx ├── ComputeSKMap │ └── compute_sk_map.cxx ├── ComputeTRMap │ └── compute_tr_map.cxx ├── ComputeWLMap │ ├── compute_wl_map.cxx │ └── compute_wl_map.h ├── ComputeWPMap │ ├── compute_wp_map.cxx │ └── compute_wp_map.h ├── ComputeWSMap │ └── compute_ws_map.cxx ├── Convert4DImageToDisplacementField │ └── Convert4DImageToDisplacementField.cxx ├── ConvertGEGradientsToBMatrix │ └── ConvertGEGradientsToBMatrix.cxx ├── ConvertLGradNonLinToDefField │ └── ConvertLGradNonLinToDefField.cxx ├── ConvertQuadraticTransformToDisplacementField │ └── convert_eddy_trans_to_field.hxx ├── CreateDummyJson │ ├── CreateDummyJson.cxx │ ├── CreateDummyJson_parser.cxx │ └── CreateDummyJson_parser.h ├── CreateGradientNonlinearityBMatrix │ ├── CreateGradientNonlinearityBMatrix.cxx │ ├── CreateGradientNonlinearityBMatrix_parser.cxx │ └── CreateGradientNonlinearityBMatrix_parser.h ├── CreateMask │ └── create_mask_main.cxx ├── CreateNonlinearityDisplacementMap │ └── mk_displacementMaps.cxx ├── DIFFPREPAnonymizer │ ├── diffprep_anonymizer.cxx │ ├── diffprep_anonymizer.h │ ├── itkGDCMImageIOOkan.cxx │ ├── itkGDCMImageIOOkan.h │ └── tag_list.txt ├── DRBUDDI │ ├── DRBUDDI_main.cxx │ ├── DRBUDDI_parserBase.cxx │ └── DRBUDDI_parserBase.h ├── DRTAMAS │ ├── ApplyTransformationToTensorDRT.cxx │ ├── DRTAMAS.cxx │ ├── DRTAMAS.h │ ├── DRTAMASRigid.cxx │ ├── DRTAMASRigid.h │ ├── DRTAMASRigid_Bulk.cxx │ ├── DRTAMASRigid_Bulk.h │ ├── DRTAMASRigid_main.cxx │ ├── DRTAMAS_Diffeo (copy).cxx │ ├── DRTAMAS_Diffeo.cxx │ ├── DRTAMAS_Diffeo.h │ ├── DRTAMAS_batch_register_to_target_main.bash │ ├── DRTAMAS_create_template_main.bash │ ├── DRTAMAS_main.cxx │ ├── DRTAMAS_parser.cxx │ ├── DRTAMAS_parser.h │ ├── DRTAMAS_utilities.cu │ ├── DRTAMAS_utilities.cxx │ ├── DRTAMAS_utilities.h │ ├── DRTAMAS_utilities_cp.cxx │ ├── DRTAMAS_utilities_cp.h │ ├── compute_metric_dev (another copy).cu │ ├── compute_metric_dev (copy).cu │ ├── compute_metric_dev.cu │ ├── compute_metric_dev.cxx │ ├── compute_metric_dev.h │ ├── drtamas_structs.h │ ├── run_drtamas_stage (copy).cxx │ ├── run_drtamas_stage.cxx │ ├── run_drtamas_stage.h │ ├── run_drtamas_stage_rigid.cxx │ ├── run_drtamas_stage_rigid.h │ └── select_most_representative_sample.cxx ├── DWIDenoise │ ├── dwi_denoise.cxx │ └── dwi_denoise.h ├── EstimateExperimentalDeviationScalar │ ├── estimate_experimental_deviation_scalar.cxx │ ├── estimate_experimental_deviation_scalar_parser.cxx │ ├── estimate_experimental_deviation_scalar_parser.h │ └── vnl_matrix_inverse.h ├── EstimateMAPMRI │ ├── MAPMRIModel.cxx │ ├── MAPMRIModel.h │ ├── bmat2q.h │ ├── compute_eigen_images.h │ ├── constrained_least_squares.h │ ├── estimate_mapmri.h │ ├── estimate_mapmri_main.cxx │ ├── estimate_mapmri_parser.cxx │ ├── estimate_mapmri_parser.h │ ├── fit_mapmri.h │ └── synthesize_dwi_from_mapmri.h ├── EstimateTensor │ ├── DTIModel.cxx │ ├── DTIModel.h │ ├── estimate_tensor_wlls.cxx │ ├── estimate_tensor_wlls.h │ ├── estimate_tensor_wlls_main.cxx │ ├── estimate_tensor_wlls_parser.cxx │ ├── estimate_tensor_wlls_parser.h │ └── synthesize_dwi_from_tensor.h ├── ExtractAllPNGsFromNIFTI │ └── extract_all_pngs_from_nifti.cxx ├── ExtractDWISubset │ ├── extract_dwi_subset.cxx │ ├── extract_dwi_subset_parser.cxx │ └── extract_dwi_subset_parser.h ├── ExtractImage │ ├── extract_component_from_itk_vector_image.cxx │ ├── extract_image.cxx │ ├── extract_image_parser.cxx │ └── extract_image_parser.h ├── ExtractPNGFromNIFTI │ └── extract_png_from_nifti.cxx ├── FitNIFTIIso │ ├── Fit_nifti_iso.cxx │ ├── Fit_nifti_iso.h │ ├── erodeMask.cxx │ ├── erodeMask.h │ ├── fit_nifti_iso_parser.cxx │ ├── fit_nifti_iso_parser.h │ ├── gradcal.cxx │ ├── gradcal.h │ ├── init_iso_gw.cxx │ ├── init_iso_gw.h │ ├── iso_gw.cxx │ ├── iso_gw.h │ ├── main.cxx │ ├── read_grad_cal.cxx │ └── read_grad_cal.h ├── FlipImage3D │ └── flip_image_3d.cxx ├── FlipImage4D │ └── flip_image_4d.cxx ├── FlipSwapBMatrix │ ├── FlipSwapBMatrix.cxx │ ├── FlipSwapBMatrix_parser.cxx │ ├── FlipSwapBMatrix_parser.h │ ├── antsCommandLineParser2.cxx │ └── antsCommandLineParser2.h ├── InvertTransformation │ └── invert_transformation.cxx ├── IsDirectionPositiveDet │ └── IsDirectionPositiveDet.cxx ├── MaskTensorWith3D │ └── MaskTensorWith3D.cxx ├── Pad4DImage │ ├── Pad3DImage.cxx │ └── Pad4DImage.cxx ├── PadImage │ └── pad_image.hxx ├── PrintHeaderT │ └── PrintHeader.cxx ├── ReorientImage │ ├── reorient_image.cxx │ ├── reorient_image.h │ ├── reorient_image_parser.cxx │ └── reorient_image_parser.h ├── ReorientImage3D │ ├── reorient_image3d.cxx │ ├── reorient_image_parser.cxx │ └── reorient_image_parser.h ├── ResampleDWIs │ ├── resample_dwis.cxx │ └── resample_dwis.h ├── RotateBMatrix │ ├── rotate_bmatrix.cxx │ ├── rotate_bmatrix.h │ └── rotate_bmatrix_main.cxx ├── SelectBestB0 │ ├── SelectBestB0_main.cxx │ └── select_best_b0.h ├── Set4DImageDirection │ └── set_4dimage_direction.cxx ├── Set4DImageOrigin │ └── set_4dimage_origin.cxx ├── Set4DImageResolution │ └── Set4DImageResolution.cxx ├── StdevImages3D │ └── stdev_images_3d.cxx ├── SynthesizeDWIFromMAPMRI │ ├── synthesize_dwi_from_map_test.cxx │ └── synthesize_dwis_from_mapmri.cxx ├── SynthesizeDWIsFromTensor │ └── synthesize_dwis_from_tensor.cxx ├── TORTOISEBMatrixToBT │ └── tortoise_bmatrix_to_bt.cxx ├── TORTOISEBmatrixToFSLBVecs │ ├── fsl_bvecs_tortoise_bmatrix.cxx │ ├── tortoise_bmatrix_to_fsl_bvecs.cxx │ └── tortoise_bmatrix_to_fsl_bvecs.h ├── UnObliqueImage │ └── UnObliqueImage.cxx ├── UnRing │ ├── gibbs_main.cxx │ └── unring.h ├── Vol2SlRegistration │ └── vol2sl_registration_main.cxx ├── ZeroSlices3D │ └── ZeroSlices3D.cxx ├── gradnonlin │ ├── gradcal.cxx │ ├── gradcal.h │ ├── init_iso_gw.cxx │ ├── init_iso_gw.h │ ├── mk_displacementMaps.cxx │ └── mk_displacementMaps.h └── import_bruker │ ├── ImportBruker.cxx │ ├── bruker_anatomical_parser (copy).cxx │ ├── bruker_anatomical_parser (copy).h │ ├── bruker_anatomical_parser.cxx │ ├── bruker_anatomical_parser.h │ ├── bruker_parser.cxx │ ├── bruker_parser.h │ ├── convert_bruker.cxx │ ├── convert_bruker.h │ ├── convert_bruker_anatomical.cxx │ ├── convert_bruker_anatomical.h │ ├── import_bruker.cxx │ └── import_bruker_anatomical.cxx └── utilities ├── TORTOISE_Utilities.cxx ├── TORTOISE_Utilities.h ├── extract_3Dvolume_from_4D.cxx ├── extract_3Dvolume_from_4D.h ├── itkNiftiImageIOHeader.cxx ├── itkNiftiImageIOHeader.h ├── itkNiftiImageIOHeaderFactory.cxx ├── itkNiftiImageIOHeaderFactory.h ├── math_utilities.cxx ├── math_utilities.h ├── read_3Dvolume_from_4D.cxx ├── read_3Dvolume_from_4D.h ├── read_bmatrix_file.cxx ├── read_bmatrix_file.h ├── write_3D_image_to_4D_file.h ├── write_bmatrix_file.cxx └── write_bmatrix_file.h /TORTOISEV4/tools/README.md: -------------------------------------------------------------------------------- 1 | TORTOISEV4 has many tools for specific purposes. Each module in the TORTOISEProcess pipeline has also a corresponding executable in case users prefer to use them independently. Here is the list and their descriptions (in alphabetical order). 2 | 3 | 4 | ## ApplyTransformationToScalar2 5 | Usage: ApplyTransformationToScalar2 full_path_to_scalar_to_be_transformed full_path_to_transformation full_path_to_name_of_output full_path_to_image_with_desired_dimensions InterpolantType (NN, Lin, BSP) 6 | 7 | This executable can transform a 3D image using an ITK format (compatible with ANTS) deformation field or an ITK affine transform (text file format. For binary ANTS transforms, convert them to text first with c3d_affine_tool). 8 | 9 | ## Combine3DImagesTo4D 10 | Usage: Combine3DImagesTo4D output_nifti_filename nifti1_filename nifti2_filename .......... niftiN_filename 11 | 12 | Combines multiple 3D images into a single 4D image. The order of volumes will be identical to the order provided in the command line. 13 | -------------------------------------------------------------------------------- /external_libraries/bet/Linux/betokan.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | #include "defines.h" 7 | 8 | 9 | int mainokan(int argc, char *argv[]); 10 | 11 | ImageType3D::Pointer betokan(ImageType3D::Pointer filtered_img) 12 | { 13 | float *filtered_mask= new float[ filtered_img->GetLargestPossibleRegion().GetSize()[0]*filtered_img->GetLargestPossibleRegion().GetSize()[1]*filtered_img->GetLargestPossibleRegion().GetSize()[2]]; 14 | 15 | 16 | int sizes[3]; 17 | sizes[0]=filtered_img->GetLargestPossibleRegion().GetSize()[0]; 18 | sizes[1]=filtered_img->GetLargestPossibleRegion().GetSize()[1]; 19 | sizes[2]=filtered_img->GetLargestPossibleRegion().GetSize()[2]; 20 | 21 | float res[3]; 22 | res[0]= filtered_img->GetSpacing()[0]; 23 | res[1]= filtered_img->GetSpacing()[1]; 24 | res[2]= filtered_img->GetSpacing()[2]; 25 | 26 | 27 | int argc=7; 28 | char *argv[7]={0}; 29 | argv[0]= (char *) sizes; 30 | argv[1]= (char *) res; 31 | argv[2]= (char *) (filtered_img->GetBufferPointer()); 32 | argv[3]= (char *) filtered_mask; 33 | 34 | char p1[3]="-f"; 35 | float p2=0.3; 36 | 37 | 38 | argv[4]= p1; 39 | argv[5]= (char*) &p2; 40 | 41 | char p3[3]="-v"; 42 | 43 | argv[6]=p3; 44 | mainokan(argc,argv); 45 | 46 | 47 | ImageType3D::Pointer out_img= ImageType3D::New(); 48 | out_img->SetRegions(filtered_img->GetLargestPossibleRegion()); 49 | out_img->SetSpacing(filtered_img->GetSpacing()); 50 | out_img->SetDirection(filtered_img->GetDirection()); 51 | out_img->SetOrigin(filtered_img->GetOrigin()); 52 | out_img->GetPixelContainer()->SetImportPointer(filtered_mask,filtered_img->GetLargestPossibleRegion().GetSize()[0]*filtered_img->GetLargestPossibleRegion().GetSize()[1]*filtered_img->GetLargestPossibleRegion().GetSize()[2],false); 53 | 54 | 55 | return out_img; 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /external_libraries/bet/Linux/libbetokan.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/external_libraries/bet/Linux/libbetokan.a -------------------------------------------------------------------------------- /external_libraries/bet/Linux/libbetokan2.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/external_libraries/bet/Linux/libbetokan2.a -------------------------------------------------------------------------------- /external_libraries/bet/Linux/libbetokan_orig.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/external_libraries/bet/Linux/libbetokan_orig.a -------------------------------------------------------------------------------- /settings/mecc_settings/cubic.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 100 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/cubic_isoc.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 100 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/justeddy.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 80 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/justeddy_isoc.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 80 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/quadratic.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 100 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/quadratic_isoc.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 80 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/mecc_settings/rigid.mec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DIFFPREPOptimizer 10 | 11 | 12 | 80 13 | 14 | 15 | 16 | 17 | 18 | 0.0001 19 | 20 | 21 | 0.0005 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 32 | 33 | 34 | 35 | 5 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings/system_settings/default_system_settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment": "Percentage of CPU cores to be used by TORTOISE as a float. Ex, 1: use all cores 0.1: use 10% of max cores", 3 | "PercentOfCpuCoresToUse": 0.5 4 | } 5 | -------------------------------------------------------------------------------- /src/cuda_src/compute_entropy.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEENTROPY_CXX 2 | #define _COMPUTEENTROPY_CXX 3 | 4 | #include "compute_entropy.h" 5 | 6 | 7 | 8 | 9 | float ComputeEntropy(CUDAIMAGE::Pointer img, int Nbins, float low_lim, float high_lim) 10 | { 11 | float value; 12 | ComputeEntropy_cuda(img->getFloatdata(), 13 | img->sz, 14 | Nbins, 15 | low_lim,high_lim , 16 | value ); 17 | return value; 18 | } 19 | 20 | 21 | 22 | void ComputeJointEntropy(CUDAIMAGE::Pointer img1, float low_lim1, float high_lim1, CUDAIMAGE::Pointer img2, float low_lim2, float high_lim2, int Nbins,float &entropy_j,float &entropy_img1,float &entropy_img2) 23 | { 24 | float valuec, value1, value2; 25 | ComputeJointEntropy_cuda( img1->getFloatdata(), low_lim1, high_lim1, 26 | img2->getFloatdata(), low_lim2, high_lim2, 27 | img1->sz, 28 | Nbins, 29 | valuec, value1, value2); 30 | entropy_j=valuec; 31 | entropy_img1=value1; 32 | entropy_img2=value2; 33 | 34 | } 35 | 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/cuda_src/compute_entropy.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEENTROPY_H 2 | #define _COMPUTEENTROPY_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | float ComputeEntropy(CUDAIMAGE::Pointer img, int Nbins, float low_lim, float high_lim); 8 | 9 | void ComputeEntropy_cuda(cudaPitchedPtr img, const int3 sz, const int Nbins, const float low_lim, const float high_lim, float &value); 10 | 11 | 12 | 13 | void ComputeJointEntropy_cuda(cudaPitchedPtr img1, float low_lim1, float high_lim1, cudaPitchedPtr img2, float low_lim2, float high_lim2, const int3 sz, const int Nbins, float &valuec , float &value1 , float &value2); 14 | void ComputeJointEntropy(CUDAIMAGE::Pointer img1, float low_lim1, float high_lim1, CUDAIMAGE::Pointer img2, float low_lim2, float high_lim2, int Nbins,float &entropy_j, float &entropy_img1, float &entropy_img2); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/cuda_src/compute_mi_cuda.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEMICUDA_CXX 2 | #define _COMPUTEMICUDA_CXX 3 | 4 | #include "compute_mi_cuda.h" 5 | #include "mutual_information_common.h" 6 | 7 | 8 | 9 | bool cudaImageMutualInformation64( float *h_JointEntropy, float *h_Entropy1, float *h_Entropy2, 10 | cudaPitchedPtr img1, cudaPitchedPtr img2, 11 | int3 sz, 12 | int NBins, 13 | float limarr0,float limarr1,float limarr2,float limarr3) 14 | { 15 | cudaEvent_t start_device, stop_device, start_histogram, stop_histogram, start_entropy, stop_entropy; 16 | 17 | cudaEventCreate(&start_device); 18 | cudaEventCreate(&stop_device); 19 | cudaEventCreate(&start_histogram); 20 | cudaEventCreate(&stop_histogram); 21 | cudaEventCreate(&start_entropy); 22 | cudaEventCreate(&stop_entropy); 23 | 24 | cudaEventRecord(start_device,0); 25 | 26 | uint *d_JointHistogram, *d_Histogram1, *d_Histogram2; 27 | 28 | checkCudaErrors(cudaMalloc((void **)&d_Histogram1, NBins * sizeof(uint))); 29 | checkCudaErrors(cudaMalloc((void **)&d_Histogram2, NBins * sizeof(uint))); 30 | checkCudaErrors(cudaMalloc((void **)&d_JointHistogram, NBins*NBins* sizeof(uint))); 31 | 32 | 33 | 34 | 35 | } 36 | 37 | 38 | 39 | float ComputeMICuda(CUDAIMAGE::Pointer fimg, CUDAIMAGE::Pointer mimg, int NBins,std::vector lim_arr) 40 | { 41 | 42 | float h_Entropy1 = 0.0; 43 | float h_Entropy2 = 0.0; 44 | float h_JointEntropy = 0.0; 45 | 46 | 47 | h_Histogram1 = (uint *)malloc(HISTOGRAM64_BIN_COUNT * sizeof(uint)); 48 | h_Histogram2 = (uint *)malloc(HISTOGRAM64_BIN_COUNT * sizeof(uint)); 49 | h_JointHistogram = (uint *)malloc(JOINT_HISTOGRAM64_BIN_COUNT * sizeof(uint)); 50 | 51 | 52 | if (cudaImageMutualInformation64( &h_JointEntropy, &h_Entropy1, &h_Entropy2, 53 | cudaPitchedPtr img1, cudaPitchedPtr img2, 54 | fimg->sz, 55 | NBins, 56 | lim_arr[0],lim_arr[1],lim_arr[2],lim_arr[3]) 57 | { 58 | std::cerr << "cudaImageMutualInformation64 Error\n"; 59 | return EXIT_FAILURE; 60 | } 61 | 62 | 63 | float MI = ( h_Entropy1 + h_Entropy2 ) / h_JointEntropy; 64 | return -MI; 65 | } 66 | 67 | //void ComputeMICuda_cuda(cudaPitchedPtr fimg, cudaPitchedPtr mimg, 68 | // int3 sz); 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/cuda_src/compute_mi_cuda.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEMICUDA_H 2 | #define _COMPUTEMICUDA_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | float ComputeMICuda(CUDAIMAGE::Pointer fimg, CUDAIMAGE::Pointer mimg,int bs,std::vector lim_arr); 8 | 9 | void ComputeMICuda_cuda(cudaPitchedPtr fimg, cudaPitchedPtr mimg, 10 | int3 sz); 11 | 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/cuda_src/cuda_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _CUDAIMAGE_H 2 | #define _CUDAIMAGE_H 3 | 4 | #include 5 | #include 6 | #include "itkImage.h" 7 | #include "itkDisplacementFieldTransform.h" 8 | #include 9 | 10 | #include "cuda_utils.h" 11 | 12 | 13 | 14 | class CUDAIMAGE 15 | { 16 | 17 | public: 18 | using DataType=float; 19 | using ImageType3D=itk::Image; 20 | using ImageType4D=itk::Image; 21 | typedef itk::DisplacementFieldTransform DisplacementTransformType; 22 | typedef itk::DisplacementFieldTransform DisplacementTransformTypeFloat; 23 | typedef DisplacementTransformType::DisplacementFieldType DisplacementFieldType; 24 | typedef DisplacementTransformTypeFloat::DisplacementFieldType DisplacementFieldTypeFloat; 25 | 26 | using InternalMatrixType=vnl_matrix_fixed< double, 3, 3 >; 27 | using DTMatrixImageType = itk::Image; 28 | 29 | using TensorVectorType = itk::Vector; 30 | using TensorVectorImageType = itk::Image; 31 | 32 | 33 | 34 | 35 | using Self = CUDAIMAGE; 36 | using Pointer = std::shared_ptr; 37 | 38 | static Pointer New(); 39 | 40 | public: 41 | CUDAIMAGE(){PitchedFloatData.ptr=nullptr; CudaArraydata=nullptr;}; 42 | ~CUDAIMAGE(); 43 | 44 | 45 | 46 | 47 | void DuplicateFromCUDAImage(CUDAIMAGE::Pointer cp_img); 48 | void SetImageFromITK(ImageType3D::Pointer itk_image, bool create_texture=false); 49 | void SetImageFromITK(DisplacementFieldType::Pointer itk_field); 50 | void SetTImageFromITK(DTMatrixImageType::Pointer tensor_img); 51 | void FillBuffer(float val) 52 | { 53 | cudaExtent extent = make_cudaExtent(this->components_per_voxel*sizeof(float)*this->sz.x,this->sz.y,this->sz.z); 54 | cudaMemset3D(PitchedFloatData,val,extent); 55 | } 56 | 57 | ImageType3D::Pointer CudaImageToITKImage(); 58 | TensorVectorImageType::Pointer CudaImageToITKImage4D(); 59 | DisplacementFieldType::Pointer CudaImageToITKField(); 60 | 61 | 62 | cudaPitchedPtr getFloatdata(){return PitchedFloatData;}; 63 | 64 | void SetFloatDataPointer( cudaPitchedPtr data){PitchedFloatData=data;}; 65 | ImageType3D::DirectionType GetDirection(){return dir;}; 66 | 67 | void Allocate(); 68 | 69 | 70 | 71 | cudaTextureObject_t GetTexture(){return texobj;}; 72 | void CreateTexture(); 73 | 74 | ImageType3D::DirectionType dir; 75 | float3 orig; 76 | float3 spc; 77 | int3 sz; 78 | 79 | int components_per_voxel{1}; 80 | 81 | 82 | private: 83 | cudaPitchedPtr PitchedFloatData{nullptr}; 84 | 85 | cudaArray *CudaArraydata{nullptr}; 86 | cudaTextureObject_t texobj; 87 | 88 | 89 | }; 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/cuda_src/cuda_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _CUDA_UTILS_H 2 | #define _CUDA_UTILS_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | 13 | /********************/ 14 | /* CUDA ERROR CHECK */ 15 | /********************/ 16 | #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } 17 | inline void gpuAssert(cudaError_t code, std::string file, int line, bool abort=true) 18 | { 19 | if (code != cudaSuccess) 20 | { 21 | fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file.c_str(), line); 22 | if (abort) 23 | { 24 | getchar(); 25 | exit(code); 26 | } 27 | } 28 | } 29 | 30 | 31 | 32 | 33 | 34 | inline void copy3DPitchedPtrToHost(cudaPitchedPtr _src, float *_dst, int width, int height, int depth) 35 | 36 | { 37 | 38 | cudaExtent copy_extent = make_cudaExtent(width*sizeof(float),height,depth); 39 | 40 | cudaMemcpy3DParms copyParams = {0}; 41 | 42 | float *h_dest = _dst; 43 | 44 | copyParams.srcPtr = _src; 45 | 46 | copyParams.dstPtr = make_cudaPitchedPtr((void*)h_dest, width*sizeof(float), width, height); 47 | 48 | copyParams.kind = cudaMemcpyDeviceToHost; 49 | 50 | copyParams.extent = copy_extent; 51 | 52 | gpuErrchk(cudaMemcpy3D(©Params)); 53 | 54 | 55 | 56 | } 57 | 58 | inline void copy3DHostToPitchedPtr(float *_src, cudaPitchedPtr _dst, int width, int height, int depth) 59 | 60 | { 61 | 62 | cudaExtent copy_extent = make_cudaExtent(width*sizeof(float),height,depth); 63 | 64 | cudaMemcpy3DParms copyParams = {0}; 65 | 66 | float *h_source = _src; 67 | 68 | copyParams.srcPtr = make_cudaPitchedPtr((void*)h_source, copy_extent.width, copy_extent.width/sizeof(float), copy_extent.height); 69 | 70 | copyParams.dstPtr = _dst; 71 | 72 | copyParams.kind = cudaMemcpyHostToDevice; 73 | 74 | copyParams.extent = copy_extent; 75 | 76 | gpuErrchk(cudaMemcpy3D(©Params)); 77 | 78 | 79 | } 80 | 81 | 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/cuda_src/gaussian_smooth_image.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _GAUSSIANSMOOTHIMAGE_CXX 2 | #define _GAUSSIANSMOOTHIMAGE_CXX 3 | 4 | #include "itkGaussianOperator.h" 5 | #include "gaussian_smooth_image.h" 6 | 7 | 8 | 9 | CUDAIMAGE::Pointer GaussianSmoothImage(CUDAIMAGE::Pointer main_image, float std) 10 | { 11 | if(std==0) 12 | { 13 | return main_image; 14 | } 15 | 16 | if(main_image==nullptr) 17 | return nullptr; 18 | 19 | 20 | cudaPitchedPtr d_output={0}; 21 | cudaExtent extent = make_cudaExtent(main_image->components_per_voxel*sizeof(float)*main_image->sz.x,main_image->sz.y,main_image->sz.z); 22 | cudaMalloc3D(&d_output, extent); 23 | cudaMemset3D(d_output,0,extent); 24 | 25 | 26 | itk::GaussianOperator oper; 27 | 28 | float max_error=0.01; 29 | if(main_image->components_per_voxel==3) 30 | max_error=0.001; 31 | 32 | int radius; 33 | 34 | oper.SetDirection(0); 35 | oper.SetVariance(std); 36 | oper.SetMaximumKernelWidth(31); 37 | oper.SetMaximumError(max_error); 38 | oper.CreateDirectional(); 39 | 40 | 41 | radius=oper.GetRadius(0); 42 | 43 | auto aa= oper.GetBufferReference(); 44 | int kernel_sz= aa.size(); 45 | 46 | float *h_kernel = new float[kernel_sz]; 47 | for(int m=0;mgetFloatdata(), 53 | main_image->sz, 54 | main_image->components_per_voxel, 55 | kernel_sz, 56 | h_kernel, 57 | d_output 58 | ); 59 | 60 | delete[] h_kernel; 61 | 62 | 63 | if(main_image->components_per_voxel==3) 64 | { 65 | float weight1=1; 66 | if( std < 0.5 ) 67 | { 68 | weight1 = 1.0 - 1.0 * ( std / 0.5 ); 69 | } 70 | float weight2 = 1.0 - weight1; 71 | 72 | AdjustFieldBoundary(main_image->getFloatdata(),d_output,main_image->sz, weight1,weight2); 73 | } 74 | 75 | 76 | CUDAIMAGE::Pointer output = CUDAIMAGE::New(); 77 | output->sz=main_image->sz; 78 | output->dir=main_image->dir; 79 | output->orig=main_image->orig; 80 | output->spc=main_image->spc; 81 | output->components_per_voxel= main_image->components_per_voxel; 82 | output->SetFloatDataPointer( d_output); 83 | return output; 84 | 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/cuda_src/gaussian_smooth_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _GAUSSIANSMOOTHIMAGE_H 2 | #define _GAUSSIANSMOOTHIMAGE_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | 8 | 9 | 10 | CUDAIMAGE::Pointer GaussianSmoothImage(CUDAIMAGE::Pointer main_image, float std); 11 | 12 | void GaussianSmoothImage_cuda(cudaPitchedPtr data, 13 | int3 data_sz, 14 | int Ncomponents, 15 | int kernel_sz, 16 | float *h_kernel, 17 | cudaPitchedPtr output ); 18 | 19 | void AdjustFieldBoundary(cudaPitchedPtr orig_img,cudaPitchedPtr smooth_img,int3 data_sz, float weight1, float weight2); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/cuda_src/quadratic_transform_image.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _QUADRATICTRANSFORMIMAGE_CXX 2 | #define _QUADRATICTRANSFORMIMAGE_CXX 3 | 4 | #include "quadratic_transform_image.h" 5 | 6 | 7 | CUDAIMAGE::Pointer QuadraticTransformImageC(CUDAIMAGE::Pointer main_image, TransformType::Pointer tp,CUDAIMAGE::Pointer target_img) 8 | { 9 | cudaPitchedPtr d_output={0}; 10 | cudaExtent extent = make_cudaExtent(sizeof(float)*target_img->sz.x,target_img->sz.y,target_img->sz.z); 11 | cudaMalloc3D(&d_output, extent); 12 | cudaMemset3D(d_output,0,extent); 13 | 14 | 15 | TransformType::MatrixType mat= tp->GetMatrix(); 16 | 17 | float mat_arr[9]={mat(0,0),mat(0,1),mat(0,2),mat(1,0),mat(1,1),mat(1,2),mat(2,0),mat(2,1),mat(2,2)}; 18 | TransformType::ParametersType params = tp->GetParameters(); 19 | 20 | float params_arr[TransformType::NQUADPARAMS]; 21 | for(int p=0;pdir(0,0),main_image->dir(0,1),main_image->dir(0,2),main_image->dir(1,0),main_image->dir(1,1),main_image->dir(1,2),main_image->dir(2,0),main_image->dir(2,1),main_image->dir(2,2)}; 26 | float target_img_dir[9]={target_img->dir(0,0),target_img->dir(0,1),target_img->dir(0,2),target_img->dir(1,0),target_img->dir(1,1),target_img->dir(1,2),target_img->dir(2,0),target_img->dir(2,1),target_img->dir(2,2)}; 27 | 28 | QuadraticTransformImage_cuda(main_image->GetTexture(), 29 | main_image->sz, main_image->spc, main_image->orig,main_img_dir, 30 | target_img->sz, target_img->spc, target_img->orig,target_img_dir, 31 | mat_arr, 32 | params_arr, 33 | d_output ); 34 | 35 | CUDAIMAGE::Pointer output = CUDAIMAGE::New(); 36 | output->sz=target_img->sz; 37 | output->dir=target_img->dir; 38 | output->orig=target_img->orig; 39 | output->spc=target_img->spc; 40 | output->components_per_voxel= target_img->components_per_voxel; 41 | output->SetFloatDataPointer( d_output); 42 | return output; 43 | 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/cuda_src/quadratic_transform_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUADRATICTRANSFORMIMAGE_H 2 | #define _QUADRATICTRANSFORMIMAGE_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | #include "itkOkanQuadraticTransform.h" 8 | using TransformType=itk::OkanQuadraticTransform; 9 | 10 | CUDAIMAGE::Pointer QuadraticTransformImageC(CUDAIMAGE::Pointer img, TransformType::Pointer tr, CUDAIMAGE::Pointer target_img); 11 | 12 | void QuadraticTransformImage_cuda(cudaTextureObject_t tex, 13 | int3 img_sz,float3 img_res, float3 img_orig, float *img_dir, 14 | int3 target_sz,float3 target_res, float3 target_orig, float *target_dir, 15 | float mat_arr[], 16 | float params_arr[], 17 | cudaPitchedPtr output ); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/cuda_src/register_dwi_to_b0_cuda.h: -------------------------------------------------------------------------------- 1 | #ifndef _RegisterDWIToB0CUDA_H 2 | #define _RegisterDWIToB0CUDA_H 3 | 4 | #include "defines.h" 5 | #include "itkOkanQuadraticTransform.h" 6 | #include "mecc_settings.h" 7 | 8 | 9 | using TransformType=itk::OkanQuadraticTransform; 10 | 11 | 12 | TransformType::Pointer RegisterDWIToB0_cuda(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string phase, MeccSettings *mecc_settings, bool initialize,std::vector lim_arr, TransformType::Pointer minit_trans=nullptr ); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/cuda_src/resample_image.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _RESAMPLEIMAGE_CXX 2 | #define _RESAMPLEIMAGE_CXX 3 | 4 | #include "resample_image.h" 5 | 6 | 7 | 8 | CUDAIMAGE::Pointer ResampleImage(CUDAIMAGE::Pointer main_field, CUDAIMAGE::Pointer virtual_img) 9 | { 10 | 11 | if(main_field==nullptr) 12 | return nullptr; 13 | 14 | cudaPitchedPtr d_output={0}; 15 | cudaExtent extent = make_cudaExtent(main_field->components_per_voxel*sizeof(float)*virtual_img->sz.x,virtual_img->sz.y,virtual_img->sz.z); 16 | cudaMalloc3D(&d_output, extent); 17 | cudaMemset3D(d_output,0,extent); 18 | 19 | 20 | ResampleImage_cuda(main_field->getFloatdata(), 21 | main_field->sz, 22 | main_field->spc, 23 | main_field->dir(0,0),main_field->dir(0,1),main_field->dir(0,2),main_field->dir(1,0),main_field->dir(1,1),main_field->dir(1,2),main_field->dir(2,0),main_field->dir(2,1),main_field->dir(2,2), 24 | main_field->orig, 25 | virtual_img->sz, 26 | virtual_img->spc, 27 | virtual_img->dir(0,0),main_field->dir(0,1),main_field->dir(0,2),main_field->dir(1,0),main_field->dir(1,1),main_field->dir(1,2),main_field->dir(2,0),main_field->dir(2,1),main_field->dir(2,2), 28 | virtual_img->orig, 29 | main_field->components_per_voxel, 30 | d_output 31 | ); 32 | 33 | CUDAIMAGE::Pointer output = CUDAIMAGE::New(); 34 | output->sz=virtual_img->sz; 35 | output->dir=virtual_img->dir; 36 | output->orig=virtual_img->orig; 37 | output->spc=virtual_img->spc; 38 | output->components_per_voxel= main_field->components_per_voxel; 39 | output->SetFloatDataPointer( d_output); 40 | return output; 41 | 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/cuda_src/resample_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESAMPLEIMAGE_H 2 | #define _RESAMPLEIMAGE_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | 8 | 9 | 10 | CUDAIMAGE::Pointer ResampleImage(CUDAIMAGE::Pointer main_image, CUDAIMAGE::Pointer field_image); 11 | void ResampleImage_cuda(cudaPitchedPtr data, 12 | int3 data_sz,float3 data_res, 13 | float data_d00, float data_d01,float data_d02,float data_d10,float data_d11,float data_d12,float data_d20,float data_d21,float data_d22, 14 | float3 data_orig, 15 | int3 virtual_sz,float3 virtual_res, 16 | float virtual_d00, float virtual_d01,float virtual_d02,float virtual_d10,float virtual_d11,float virtual_d12,float virtual_d20,float virtual_d21,float virtual_d22, 17 | float3 virtual_orig, 18 | int Ncomponents, 19 | cudaPitchedPtr output ); 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/cuda_src/rigid_transform_image.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _RIGIDTRANSFORMIMAGE_CXX 2 | #define _RIGIDTRANSFORMIMAGE_CXX 3 | 4 | #include "rigid_transform_image.h" 5 | 6 | 7 | CUDAIMAGE::Pointer RigidTransformImageC(CUDAIMAGE::Pointer main_image, TransformType::Pointer tp,CUDAIMAGE::Pointer target_img) 8 | { 9 | cudaPitchedPtr d_output={0}; 10 | cudaExtent extent = make_cudaExtent(sizeof(float)*target_img->sz.x,target_img->sz.y,target_img->sz.z); 11 | cudaMalloc3D(&d_output, extent); 12 | cudaMemset3D(d_output,0,extent); 13 | 14 | 15 | TransformType::MatrixType mat= tp->GetMatrix(); 16 | 17 | float mat_arr[9]={mat(0,0),mat(0,1),mat(0,2),mat(1,0),mat(1,1),mat(1,2),mat(2,0),mat(2,1),mat(2,2)}; 18 | TransformType::ParametersType params = tp->GetParameters(); 19 | 20 | float params_arr[6]; 21 | for(int p=0;p<6;p++) 22 | params_arr[p]=params[p]; 23 | 24 | 25 | float main_img_dir[9]={main_image->dir(0,0),main_image->dir(0,1),main_image->dir(0,2),main_image->dir(1,0),main_image->dir(1,1),main_image->dir(1,2),main_image->dir(2,0),main_image->dir(2,1),main_image->dir(2,2)}; 26 | float target_img_dir[9]={target_img->dir(0,0),target_img->dir(0,1),target_img->dir(0,2),target_img->dir(1,0),target_img->dir(1,1),target_img->dir(1,2),target_img->dir(2,0),target_img->dir(2,1),target_img->dir(2,2)}; 27 | 28 | RigidTransformImage_cuda(main_image->GetTexture(), 29 | main_image->sz, main_image->spc, main_image->orig,main_img_dir, 30 | target_img->sz, target_img->spc, target_img->orig,target_img_dir, 31 | mat_arr, 32 | params_arr, 33 | d_output ); 34 | 35 | CUDAIMAGE::Pointer output = CUDAIMAGE::New(); 36 | output->sz=target_img->sz; 37 | output->dir=target_img->dir; 38 | output->orig=target_img->orig; 39 | output->spc=target_img->spc; 40 | output->components_per_voxel= target_img->components_per_voxel; 41 | output->SetFloatDataPointer( d_output); 42 | return output; 43 | 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/cuda_src/rigid_transform_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _RIGIDTRANSFORMIMAGE_H 2 | #define _RIGIDTRANSFORMIMAGE_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | #include "itkEuler3DTransform.h" 8 | using TransformType=itk::Euler3DTransform; 9 | 10 | CUDAIMAGE::Pointer RigidTransformImageC(CUDAIMAGE::Pointer img, TransformType::Pointer tr, CUDAIMAGE::Pointer target_img); 11 | 12 | void RigidTransformImage_cuda(cudaTextureObject_t tex, 13 | int3 img_sz,float3 img_res, float3 img_orig, float *img_dir, 14 | int3 target_sz,float3 target_res, float3 target_orig, float *target_dir, 15 | float mat_arr[], 16 | float params_arr[], 17 | cudaPitchedPtr output ); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/cuda_src/warp_image.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _WARPIMAGE_CXX 2 | #define _WARPIMAGE_CXX 3 | 4 | #include "warp_image.h" 5 | 6 | 7 | 8 | CUDAIMAGE::Pointer WarpImage(CUDAIMAGE::Pointer main_image, CUDAIMAGE::Pointer field_image) 9 | { 10 | 11 | cudaPitchedPtr d_output={0}; 12 | cudaExtent extent = make_cudaExtent(sizeof(float)*main_image->sz.x,main_image->sz.y,main_image->sz.z); 13 | cudaMalloc3D(&d_output, extent); 14 | cudaMemset3D(d_output,0,extent); 15 | 16 | 17 | WarpImage_cuda(main_image->GetTexture(), 18 | main_image->sz, 19 | main_image->spc, 20 | main_image->dir(0,0),main_image->dir(0,1),main_image->dir(0,2),main_image->dir(1,0),main_image->dir(1,1),main_image->dir(1,2),main_image->dir(2,0),main_image->dir(2,1),main_image->dir(2,2), 21 | field_image->getFloatdata(), 22 | d_output 23 | ); 24 | 25 | 26 | CUDAIMAGE::Pointer output = CUDAIMAGE::New(); 27 | output->sz=main_image->sz; 28 | output->dir=main_image->dir; 29 | output->orig=main_image->orig; 30 | output->spc=main_image->spc; 31 | output->components_per_voxel= main_image->components_per_voxel; 32 | output->SetFloatDataPointer( d_output); 33 | return output; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/cuda_src/warp_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _WARPIMAGE_H 2 | #define _WARPIMAGE_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | 8 | 9 | 10 | CUDAIMAGE::Pointer WarpImage(CUDAIMAGE::Pointer main_image, CUDAIMAGE::Pointer field_image); 11 | 12 | void WarpImage_cuda(cudaTextureObject_t tex,int3 sz,float3 res, 13 | float d00, float d01,float d02,float d10,float d11,float d12,float d20,float d21,float d22, 14 | cudaPitchedPtr field_ptr, 15 | cudaPitchedPtr output ); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/DISCLAIMER: -------------------------------------------------------------------------------- 1 | 2 | MPFIT: A MINPACK-1 Least Squares Fitting Library in C 3 | 4 | Original public domain version by B. Garbow, K. Hillstrom, J. More' 5 | (Argonne National Laboratory, MINPACK project, March 1980) 6 | Copyright (1999) University of Chicago 7 | (see below) 8 | 9 | Tranlation to C Language by S. Moshier (moshier.net) 10 | (no restrictions placed on distribution) 11 | 12 | Enhancements and packaging by C. Markwardt 13 | (comparable to IDL fitting routine MPFIT 14 | see http://cow.physics.wisc.edu/~craigm/idl/idl.html) 15 | Copyright (C) 2003, 2004, 2006, 2007 Craig B. Markwardt 16 | 17 | This software is provided as is without any warranty whatsoever. 18 | Permission to use, copy, modify, and distribute modified or 19 | unmodified copies is granted, provided this copyright and disclaimer 20 | are included unchanged. 21 | 22 | 23 | Source code derived from MINPACK must have the following disclaimer 24 | text provided. 25 | 26 | =========================================================================== 27 | Minpack Copyright Notice (1999) University of Chicago. All rights reserved 28 | 29 | Redistribution and use in source and binary forms, with or 30 | without modification, are permitted provided that the 31 | following conditions are met: 32 | 33 | 1. Redistributions of source code must retain the above 34 | copyright notice, this list of conditions and the following 35 | disclaimer. 36 | 37 | 2. Redistributions in binary form must reproduce the above 38 | copyright notice, this list of conditions and the following 39 | disclaimer in the documentation and/or other materials 40 | provided with the distribution. 41 | 42 | 3. The end-user documentation included with the 43 | redistribution, if any, must include the following 44 | acknowledgment: 45 | 46 | "This product includes software developed by the 47 | University of Chicago, as Operator of Argonne National 48 | Laboratory. 49 | 50 | Alternately, this acknowledgment may appear in the software 51 | itself, if and wherever such third-party acknowledgments 52 | normally appear. 53 | 54 | 4. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" 55 | WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE 56 | UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND 57 | THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR 58 | IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES 59 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE 60 | OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY 61 | OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR 62 | USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF 63 | THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) 64 | DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION 65 | UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL 66 | BE CORRECTED. 67 | 68 | 5. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT 69 | HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF 70 | ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, 71 | INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF 72 | ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF 73 | PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER 74 | SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT 75 | (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, 76 | EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE 77 | POSSIBILITY OF SUCH LOSS OR DAMAGES. 78 | -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/Makefile: -------------------------------------------------------------------------------- 1 | 2 | OFILES=mpfit.o 3 | LIBFILE=libmpfit.a 4 | 5 | CFLAGS=-O3 6 | 7 | all: $(LIBFILE) testmpfit 8 | 9 | clean: 10 | rm -f $(OFILES) testmpfit $(LIBFILE) 11 | 12 | mpfit.o: mpfit.c mpfit.h 13 | $(CC) -c -o $@ $< $(CFLAGS) 14 | 15 | $(LIBFILE): $(OFILES) 16 | $(AR) r $@ $(OFILES) 17 | 18 | testmpfit: testmpfit.c libmpfit.a 19 | $(CC) -o $@ $(CFLAGS) testmpfit.c -L. -lmpfit -lm 20 | -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/libmpfit.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/src/external_src/cmpfit-1.3a/libmpfit.a -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/mpfit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/src/external_src/cmpfit-1.3a/mpfit.o -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/testmpfit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QMICodeBase/TORTOISEV4/3ec055cd6f8095beda5c83954584c426ea7c32f8/src/external_src/cmpfit-1.3a/testmpfit -------------------------------------------------------------------------------- /src/external_src/cmpfit-1.3a/testmpfit.log: -------------------------------------------------------------------------------- 1 | *** testlinfit status = 1 2 | CHI-SQUARE = 2.756285 (8 DOF) 3 | NPAR = 2 4 | NFREE = 2 5 | NPEGGED = 0 6 | NITER = 3 7 | NFEV = 8 8 | 9 | P[0] = 3.209966 +/- 0.022210 (ACTUAL 3.200000) 10 | P[1] = -1.770954 +/- 0.018938 (ACTUAL 1.780000) 11 | *** testquadfit status = 1 12 | CHI-SQUARE = 5.679323 (7 DOF) 13 | NPAR = 3 14 | NFREE = 3 15 | NPEGGED = 0 16 | NITER = 3 17 | NFEV = 10 18 | 19 | P[0] = 4.703829 +/- 0.097512 (ACTUAL 4.700000) 20 | P[1] = 0.062586 +/- 0.054802 (ACTUAL 0.000000) 21 | P[2] = 6.163087 +/- 0.054433 (ACTUAL 6.200000) 22 | *** testquadfix status = 1 23 | CHI-SQUARE = 6.983588 (8 DOF) 24 | NPAR = 3 25 | NFREE = 2 26 | NPEGGED = 0 27 | NITER = 3 28 | NFEV = 8 29 | 30 | P[0] = 4.696254 +/- 0.097286 (ACTUAL 4.700000) 31 | P[1] = 0.000000 +/- 0.000000 (ACTUAL 0.000000) 32 | P[2] = 6.172954 +/- 0.053743 (ACTUAL 6.200000) 33 | *** testgaussfit status = 1 34 | CHI-SQUARE = 10.350032 (6 DOF) 35 | NPAR = 4 36 | NFREE = 4 37 | NPEGGED = 0 38 | NITER = 28 39 | NFEV = 139 40 | 41 | P[0] = 0.480443 +/- 0.232235 (ACTUAL 0.000000) 42 | P[1] = 4.550752 +/- 0.395434 (ACTUAL 4.700000) 43 | P[2] = -0.062562 +/- 0.074715 (ACTUAL 0.000000) 44 | P[3] = 0.397472 +/- 0.089996 (ACTUAL 0.500000) 45 | *** testgaussfix status = 1 46 | CHI-SQUARE = 15.516134 (8 DOF) 47 | NPAR = 4 48 | NFREE = 2 49 | NPEGGED = 0 50 | NITER = 12 51 | NFEV = 35 52 | 53 | P[0] = 0.000000 +/- 0.000000 (ACTUAL 0.000000) 54 | P[1] = 5.059244 +/- 0.329307 (ACTUAL 4.700000) 55 | P[2] = 0.000000 +/- 0.000000 (ACTUAL 0.000000) 56 | P[3] = 0.479746 +/- 0.053804 (ACTUAL 0.500000) 57 | -------------------------------------------------------------------------------- /src/main/DIFFPREP.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIFFPREP_H 2 | #define _DIFFPREP_H 3 | 4 | 5 | #include "TORTOISE.h" 6 | #include "mecc_settings.h" 7 | 8 | 9 | class DIFFPREP 10 | { 11 | public: 12 | using CompositeTransformType= TORTOISE::CompositeTransformType; 13 | using OkanQuadraticTransformType= TORTOISE::OkanQuadraticTransformType; 14 | using DisplacementFieldTransformType= TORTOISE::DisplacementFieldTransformType; 15 | 16 | 17 | public: 18 | DIFFPREP(){}; 19 | DIFFPREP(std::string data_name, json mjs); 20 | ~DIFFPREP(){}; 21 | 22 | 23 | protected: 24 | vnl_matrix ParseJSONForSliceTiming(json cjson); 25 | void GetSmallBigDelta(float &small_delta,float &big_delta); 26 | 27 | 28 | template 29 | typename ImageType::Pointer QuadratictransformImage(typename ImageType::Pointer img,CompositeTransformType::Pointer trans,std::string interp_method,float default_val); 30 | 31 | template 32 | typename ImageType::Pointer ChangeImageHeaderToDP(typename ImageType::Pointer img); 33 | 34 | 35 | ImageType3D::Pointer dmc_make_target(ImageType3D::Pointer img,ImageType3D::Pointer mask); 36 | std::vector choose_range(ImageType3D::Pointer b0_img,ImageType3D::Pointer curr_vol, ImageType3D::Pointer b0_mask_img); 37 | void ClassicMotionEddyCorrectAllDWIs(ImageType3D::Pointer target, std::vector dwis); 38 | void SynthMotionEddyCorrectAllDWIs(std::vector target_imgs, std::vector source_imgs); 39 | 40 | 41 | std::vector ReplaceOutliers( std::vector native_native_synth_dwis, std::vector raw_dwis,std::vector shells,vnl_vector bvals,ImageType3D::Pointer TR_map); 42 | void EM(std::vector< std::vector > logRMS_shell, std::vector< std::vector > &per_shell_inliers, std::vector< std::vector > &per_shell_outliers ,std::vector &Pin_per_shell,std::vector &medians,std::vector &MADs); 43 | 44 | private: //Subfunctions the main processing functions use 45 | 46 | std::vector TransformRepolData(std::string nii_filename, vnl_matrix &rot_Bmatrix, std::vector &final_inclusion_imgs); 47 | 48 | bool CheckVolumeInclusion(ImageType3DBool::Pointer inc_vol); 49 | ImageType3D::Pointer ComputeMedianB0Img(std::vector dwis,vnl_vector bvals); 50 | 51 | 52 | private: //Main processing functions 53 | void ProcessData(); 54 | void PadAndWriteImage(); 55 | void SetBoId(); 56 | void DPCreateMask(); 57 | void WriteOutputFiles(); 58 | void MotionAndEddy(); 59 | 60 | 61 | protected: 62 | 63 | int Nvols; 64 | ImageType3D::Pointer b0_mask_img{nullptr}; 65 | std::vector eddy_s2v_replaced_synth_dwis; 66 | std::vector native_native_synth_dwis; 67 | 68 | 69 | MeccSettings *mecc_settings; 70 | 71 | json my_json; 72 | std::string nii_name; 73 | vnl_matrix Bmatrix; 74 | 75 | TORTOISE::TeeStream *stream; 76 | 77 | private: 78 | 79 | std::vector dwi_transforms; 80 | std::vector > s2v_transformations; 81 | std::vector native_weight_img; 82 | 83 | int b0_vol_id; 84 | std::string PE_string; 85 | 86 | 87 | }; 88 | 89 | 90 | 91 | #endif 92 | 93 | -------------------------------------------------------------------------------- /src/main/DRBUDDI.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRBUDDI_H 2 | #define _DRBUDDI_H 3 | 4 | 5 | #include "DRBUDDIBase.h" 6 | 7 | class DRBUDDI : public DRBUDDIBase 8 | { 9 | using SuperClass=DRBUDDIBase; 10 | 11 | using OkanQuadraticTransformType= SuperClass::OkanQuadraticTransformType; 12 | using DisplacementFieldTransformType= SuperClass::DisplacementFieldTransformType; 13 | using DisplacementFieldType=SuperClass::DisplacementFieldType; 14 | using RigidTransformType = SuperClass::RigidTransformType; 15 | using CompositeTransformType= SuperClass::CompositeTransformType; 16 | 17 | using RGBPixelType=SuperClass::RGBPixelType; 18 | using RGBImageType=SuperClass::RGBImageType; 19 | 20 | public: 21 | 22 | DRBUDDI(std::string uname,std::string dname,std::vector str_names,json mjson); 23 | ~DRBUDDI(){}; 24 | 25 | private: //Subfunctions the main processing functions use 26 | 27 | RigidTransformType::Pointer RigidDiffeoRigidRegisterB0DownToB0Up(ImageType3D::Pointer up_image, ImageType3D::Pointer b0_down_image, std::string mtype, ImageType3D::Pointer & initial_corrected_b0); 28 | std::vector DRBUDDI_Initial_Register_Up_Down(ImageType3D::Pointer b0_up_img,ImageType3D::Pointer blip_down_img, std::string phase,bool small); 29 | 30 | 31 | 32 | public: //Main processing functions 33 | void Process(); 34 | 35 | private: //Main processing functions 36 | void Step0_CreateImages(); 37 | void Step1_RigidRegistration(); 38 | void Step2_DiffeoRegistration(); 39 | void Step3_WriteOutput(); 40 | 41 | DisplacementFieldType::Pointer CompositeToDispField(CompositeTransformType::Pointer comp_trans, ImageType3D::Pointer ref_img); 42 | ImageType3D::Pointer PreprocessImage( ImageType3D::ConstPointer inputImage, 43 | ImageType3D::PixelType lowerScaleValue, 44 | ImageType3D::PixelType upperScaleValue, 45 | float winsorizeLowerQuantile, float winsorizeUpperQuantile, 46 | ImageType3D::ConstPointer histogramMatchSourceImage=nullptr ); 47 | 48 | 49 | 50 | private: 51 | std::string down_nii_name; 52 | 53 | 54 | ImageType3D::Pointer FA_up_quad{nullptr}, FA_down_quad{nullptr}; 55 | ImageType3D::Pointer b0_down_quad{nullptr}; 56 | 57 | ImageType3D::Pointer FA_up{nullptr}, FA_down{nullptr}; 58 | ImageType3D::Pointer b0_down{nullptr}; 59 | 60 | 61 | DisplacementFieldType::Pointer def_MINV{nullptr}; 62 | }; 63 | 64 | 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/main/DRBUDDIBase.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRBUDDIBase_H 2 | #define _DRBUDDIBase_H 3 | 4 | #include "TORTOISE.h" 5 | #include "TORTOISE_parser.h" 6 | 7 | #include 8 | 9 | #include "defines.h" 10 | 11 | 12 | class DRBUDDIBase 13 | { 14 | 15 | public: 16 | using OkanQuadraticTransformType= TORTOISE::OkanQuadraticTransformType; 17 | using DisplacementFieldTransformType= TORTOISE::DisplacementFieldTransformType; 18 | using DisplacementFieldType=DisplacementFieldTransformType::DisplacementFieldType; 19 | using RigidTransformType = TORTOISE::RigidTransformType; 20 | using CompositeTransformType= TORTOISE::CompositeTransformType; 21 | 22 | using RGBPixelType=itk::RGBPixel< unsigned char >; 23 | using RGBImageType=itk::Image< RGBPixelType, 3 >; 24 | 25 | 26 | 27 | DRBUDDIBase() {}; 28 | virtual ~DRBUDDIBase(){}; 29 | 30 | //void SetParser(TORTOISE_PARSER* p){this->parser=p;} 31 | void SetParser(DRBUDDI_PARSERBASE* p) 32 | { 33 | this->parser=p; 34 | if(parser->getDRBUDDIOutput()!="") 35 | { 36 | this->proc_folder = parser->getDRBUDDIOutput(); 37 | if(!fs::exists(this->proc_folder)) 38 | fs::create_directories(this->proc_folder); 39 | } 40 | } 41 | 42 | void SetMaskImg(ImageType3D::Pointer mi){this->main_mask_img=mi;} 43 | 44 | 45 | protected: //Subfunctions the main processing functions use 46 | void CreateCorrectionImage(std::string nii_filename,ImageType3D::Pointer &b0_img, ImageType3D::Pointer &FA_img); 47 | 48 | 49 | 50 | void CreateBlipUpQuadImage(); 51 | 52 | ImageType3D::Pointer JacobianTransformImage(ImageType3D::Pointer img,DisplacementFieldType::Pointer field,ImageType3D::Pointer ref_img); 53 | InternalMatrixType ComputeJacobianAtIndex(DisplacementFieldType::Pointer disp_field, DisplacementFieldType::IndexType index); 54 | 55 | 56 | public: //Main processing functions 57 | void Process(); 58 | 59 | private: //Main processing functions 60 | virtual void Step0_CreateImages() {} 61 | virtual void Step1_RigidRegistration(){} 62 | virtual void Step2_DiffeoRegistration() {} 63 | virtual void Step3_WriteOutput() {} 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | protected: 72 | 73 | std::string PE_string; 74 | json my_json; 75 | std::string up_nii_name; 76 | std::vector structural_names; 77 | std::string proc_folder; 78 | 79 | 80 | #ifdef DRBUDDIALONE 81 | std::ostream *stream; 82 | #else 83 | TORTOISE::TeeStream *stream; 84 | #endif 85 | 86 | DRBUDDI_PARSERBASE *parser{nullptr}; 87 | 88 | ImageType3D::Pointer b0_up_quad{nullptr}; 89 | ImageType3D::Pointer b0_up{nullptr}; 90 | ImageType3D::Pointer main_mask_img{nullptr}; 91 | 92 | std::vector structural_imgs; 93 | 94 | DisplacementFieldType::Pointer def_FINV{nullptr}; 95 | }; 96 | 97 | 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /src/main/EPIREG.h: -------------------------------------------------------------------------------- 1 | #ifndef _EPIREG_H 2 | #define _EPIREG_H 3 | 4 | 5 | #include "DRBUDDIBase.h" 6 | 7 | class EPIREG : public DRBUDDIBase 8 | { 9 | using SuperClass=DRBUDDIBase; 10 | 11 | using OkanQuadraticTransformType= SuperClass::OkanQuadraticTransformType; 12 | using DisplacementFieldTransformType= SuperClass::DisplacementFieldTransformType; 13 | using DisplacementFieldType=SuperClass::DisplacementFieldType; 14 | using RigidTransformType = SuperClass::RigidTransformType; 15 | 16 | using RGBPixelType=SuperClass::RGBPixelType; 17 | using RGBImageType=SuperClass::RGBImageType; 18 | 19 | public: 20 | 21 | EPIREG(std::string uname,std::vector str_names,json mjson); 22 | ~EPIREG(){}; 23 | 24 | private: //Subfunctions the main processing functions use 25 | 26 | 27 | public: //Main processing functions 28 | void Process(); 29 | 30 | private: //Main processing functions 31 | void Step0_CreateImages(); 32 | void Step1_RigidRegistration(); 33 | void Step2_DiffeoRegistration(); 34 | void Step3_WriteOutput(); 35 | 36 | 37 | }; 38 | 39 | 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/main/TORTOISE_global.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _TORTOISEGLOBAL_CXX 2 | #define _TORTOISEGLOBAL_CXX 3 | 4 | 5 | 6 | #include "TORTOISE.h" 7 | 8 | TORTOISE::TeeStream* TORTOISE::stream=nullptr; 9 | std::string TORTOISE::executable_folder=""; 10 | std::vector OMPTHREADBASE::Nthreads_per_OMP_thread; 11 | std::atomic_uint OMPTHREADBASE::NAvailableCores={0}; 12 | 13 | #ifdef USECUDA 14 | //std::atomic_bool OMPTHREADBASE::gpu_available={true}; 15 | std::array< std::atomic_bool,8 > OMPTHREADBASE::gpu_available; //={1,1,1,1,1,1,1,1}; 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/main/antsCommandLineOption.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Advanced Normalization Tools 4 | Module: $RCSfile: antsCommandLineOption.cxx,v $ 5 | Language: C++ 6 | Date: $Date: 2009/01/22 22:48:30 $ 7 | Version: $Revision: 1.1 $ 8 | 9 | Copyright (c) ConsortiumOfANTS. All rights reserved. 10 | See accompanying COPYING.txt or 11 | http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. 12 | 13 | This software is distributed WITHOUT ANY WARRANTY; without even 14 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 | PURPOSE. See the above copyright notices for more information. 16 | 17 | =========================================================================*/ 18 | #include "antsCommandLineOption.h" 19 | 20 | namespace itk 21 | { 22 | namespace ants 23 | { 24 | CommandLineOption 25 | ::CommandLineOption() : m_ShortName( '\0' ), 26 | m_LongName( "" ), 27 | m_Description( "" ) 28 | { 29 | this->m_OptionFunctions.clear(); 30 | this->m_UsageOptions.clear(); 31 | } 32 | 33 | void 34 | CommandLineOption 35 | ::AddFunction( std::string functionString, char leftDelimiter, char rightDelimiter, unsigned int order ) 36 | { 37 | OptionFunctionType::Pointer optionFunction = OptionFunctionType::New(); 38 | 39 | optionFunction->SetArgOrder( order ); 40 | 41 | std::string::size_type leftDelimiterPos = functionString.find( leftDelimiter ); 42 | std::string::size_type rightDelimiterPos = functionString.find( rightDelimiter ); 43 | 44 | if( leftDelimiterPos == std::string::npos || 45 | rightDelimiterPos == std::string::npos ) 46 | { 47 | optionFunction->SetName( functionString ); 48 | this->m_OptionFunctions.push_front( optionFunction ); 49 | } 50 | else 51 | { 52 | OptionFunctionType::ParameterStackType parameters; 53 | 54 | optionFunction->SetName( functionString.substr( 0, leftDelimiterPos ) ); 55 | 56 | std::string::size_type leftPos = leftDelimiterPos; 57 | std::string::size_type rightPos = functionString.find( ',', leftPos + 1 ); 58 | while( rightPos != std::string::npos ) 59 | { 60 | parameters.push_back( functionString.substr( leftPos + 1, rightPos - leftPos - 1 ) ); 61 | leftPos = rightPos; 62 | rightPos = functionString.find( ',', leftPos + 1 ); 63 | } 64 | 65 | rightPos = rightDelimiterPos; 66 | parameters.push_back( functionString.substr( leftPos + 1, rightPos - leftPos - 1 ) ); 67 | 68 | optionFunction->SetParameters( parameters ); 69 | 70 | this->m_OptionFunctions.push_front( optionFunction ); 71 | } 72 | 73 | this->Modified(); 74 | } 75 | 76 | void 77 | CommandLineOption 78 | ::SetUsageOption( unsigned int i, std::string usage ) 79 | { 80 | if( i >= this->m_UsageOptions.size() ) 81 | { 82 | this->m_UsageOptions.resize( i + 1 ); 83 | } 84 | this->m_UsageOptions[i] = usage; 85 | this->Modified(); 86 | } 87 | } // end namespace ants 88 | } // end namespace itk 89 | -------------------------------------------------------------------------------- /src/main/compute_metrics (copy).h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEMETRICSMSJAC_H 2 | #define _COMPUTEMETRICSMSJAC_H 3 | 4 | #include "defines.h" 5 | 6 | 7 | 8 | 9 | 10 | float ComputeMetric_MSJac(const ImageType3D::Pointer up_img, const ImageType3D::Pointer down_img, 11 | const DisplacementFieldType::Pointer def_FINV, const DisplacementFieldType::Pointer def_MINV , 12 | DisplacementFieldType::Pointer &updateFieldF, DisplacementFieldType::Pointer &updateFieldM, 13 | vnl_vector phase_vector,float update_std) 14 | { 15 | updateFieldF->SetRegions(def_FINV->GetLargestPossibleRegion()); 16 | updateFieldF->SetDirection(this->def_FINV->GetDirection()); 17 | updateFieldF->SetOrigin(this->def_FINV->GetOrigin()); 18 | updateFieldF->SetSpacing(this->def_FINV->GetSpacing()); 19 | updateFieldF->Allocate(); 20 | CurrentFieldType::PixelType zero; zero.Fill(0); 21 | updateFieldF->FillBuffer(zero); 22 | 23 | updateFieldM->SetRegions(def_FINV->GetLargestPossibleRegion()); 24 | updateFieldM->SetDirection(this->def_FINV->GetDirection()); 25 | updateFieldM->SetOrigin(this->def_FINV->GetOrigin()); 26 | updateFieldM->SetSpacing(this->def_FINV->GetSpacing()); 27 | updateFieldM->Allocate(); 28 | updateFieldM->FillBuffer(zero); 29 | 30 | int phase=0; 31 | if( (fabs(phase_vector[1]) > fabs(phase_vector[0])) && (fabs(phase_vector[1]) > fabs(phase_vector[2]))) 32 | phase=1; 33 | if( (fabs(phase_vector[2]) > fabs(phase_vector[0])) && (fabs(phase_vector[2]) > fabs(phase_vector[1]))) 34 | phase=2; 35 | 36 | itk::GaussianOperator oper; 37 | oper.SetDirection(phase); 38 | oper.SetVariance(update_std); 39 | oper.SetMaximumError(0.001); 40 | oper.SetMaximumKernelWidth(31); 41 | oper.CreateDirectional(); 42 | 43 | auto aa= oper.GetBufferReference(); 44 | 45 | 46 | 47 | float metric_value; 48 | 49 | ComputeMetric_MSJac_cuda(up_img->getFloatdata(), down_img->getFloatdata(), 50 | up_img->sz, up_img->spc, 51 | up_img->dir(0,0),up_img->dir(0,1),up_img->dir(0,2),up_img->dir(1,0),up_img->dir(1,1),up_img->dir(1,2),up_img->dir(2,0),up_img->dir(2,1),up_img->dir(2,2), 52 | def_FINV->getFloatdata(), def_MINV->getFloatdata(), 53 | updateFieldF->getFloatdata(), updateFieldM->getFloatdata(), 54 | phase_vector, kernel_sz,h_kernel, metric_value 55 | ); 56 | 57 | delete[] h_kernel; 58 | 59 | return metric_value; 60 | } 61 | 62 | 63 | 64 | } 65 | 66 | 67 | float ComputeMetric_CCSK(const ImageType3D::Pointer up_img, const ImageType3D::Pointer down_img, 68 | const DisplacementFieldType::Pointer def_FINV, const DisplacementFieldType::Pointer def_MINV) 69 | { 70 | 71 | 72 | } 73 | 74 | 75 | 76 | float ComputeMetric_CC(const CUDAIMAGE::Pointer up_img, const CUDAIMAGE::Pointer down_img, 77 | const DisplacementFieldType::Pointer def_FINV, const DisplacementFieldType::Pointer def_MINV ) 78 | { 79 | 80 | 81 | } 82 | 83 | 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/main/create_mask.h: -------------------------------------------------------------------------------- 1 | #ifndef _CREATEMASK_H 2 | #define _CREATEMASK_H 3 | 4 | 5 | #include "defines.h" 6 | 7 | 8 | 9 | #ifdef __APPLE__ 10 | ImageType3D::Pointer betApple(ImageType3D::Pointer img); 11 | #endif 12 | 13 | ImageType3D::Pointer create_mask(ImageType3D::Pointer img,ImageType3D::Pointer noise_img=nullptr); 14 | 15 | 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /src/main/defines.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _DEFINES_HXX 2 | #define _DEFINES_HXX 3 | 4 | #include "itkImage.h" 5 | #include 6 | 7 | #include "defines.h" 8 | 9 | 10 | 11 | template 12 | typename ImageType::Pointer readImageD(std::string filename) 13 | { 14 | typedef itk::ImageFileReader ReaderType; 15 | typename ReaderType::Pointer reader= ReaderType::New(); 16 | reader->SetFileName(filename); 17 | reader->Update(); 18 | typename ImageType::Pointer img= reader->GetOutput(); 19 | return img; 20 | } 21 | 22 | 23 | 24 | template 25 | void writeImageD(typename ImageType::Pointer img, std::string filename) 26 | { 27 | typedef itk::ImageFileWriter WriterType; 28 | typename WriterType::Pointer writer= WriterType::New(); 29 | writer->SetFileName(filename); 30 | writer->SetInput(img); 31 | writer->Update(); 32 | 33 | 34 | } 35 | 36 | 37 | template ImageType3D::Pointer readImageD(std::string) ; 38 | template void writeImageD(ImageType3D::Pointer , std::string); 39 | 40 | template ImageType3DBool::Pointer readImageD(std::string) ; 41 | template void writeImageD(ImageType3DBool::Pointer , std::string); 42 | 43 | 44 | template ImageType4D::Pointer readImageD(std::string) ; 45 | template void writeImageD(ImageType4D::Pointer , std::string); 46 | 47 | template ImageType4DBool::Pointer readImageD(std::string) ; 48 | template void writeImageD(ImageType4DBool::Pointer , std::string); 49 | 50 | 51 | template DisplacementFieldType::Pointer readImageD(std::string) ; 52 | template void writeImageD(DisplacementFieldType::Pointer , std::string); 53 | 54 | 55 | template void writeImageD< itk::Image,3> >(itk::Image,3>::Pointer , std::string); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/main/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEFINES_H 2 | #define _DEFINES_H 3 | 4 | 5 | #include "itkImageFileReader.h" 6 | #include "itkImageFileWriter.h" 7 | #include "itkImageRegionIteratorWithIndex.h" 8 | 9 | #include 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "itkDisplacementFieldTransform.h" 18 | namespace fs = boost::filesystem; 19 | 20 | #include "../external_src/json_nlohmann/json.hpp" 21 | using json = nlohmann::json; 22 | 23 | 24 | 25 | #define DPI 3.1415926535897931 26 | 27 | using CoordType= double; 28 | using PixelDataType = float; 29 | 30 | using EigenVecType = Eigen::Matrix; 31 | 32 | using ImageType2D=itk::Image; 33 | using ImageType3D=itk::Image; 34 | using ImageType4D=itk::Image; 35 | using ImageType3DBool=itk::Image; 36 | using ImageType4DBool=itk::Image; 37 | 38 | 39 | using DTType=itk::Vector ; 40 | using DTImageType=itk::Image; 41 | 42 | using MAPType = itk::VariableLengthVector; 43 | using MAPImageType=itk::VectorImage; 44 | 45 | 46 | using DisplacementFieldType = itk::DisplacementFieldTransform::DisplacementFieldType; 47 | 48 | using InternalMatrixType=vnl_matrix_fixed< double, 3, 3 >; 49 | using DTMatrixImageType = itk::Image; 50 | 51 | 52 | 53 | template 54 | typename ImageType::Pointer readImageD(std::string filename); 55 | 56 | template 57 | void writeImageD(typename ImageType::Pointer img, std::string filename); 58 | 59 | 60 | 61 | namespace Color { 62 | enum Code { 63 | FG_RED = 31, 64 | FG_GREEN = 32, 65 | FG_BLUE = 34, 66 | FG_DEFAULT = 39, 67 | BG_RED = 41, 68 | BG_GREEN = 42, 69 | BG_BLUE = 44, 70 | BG_DEFAULT = 49 71 | }; 72 | class Modifier { 73 | Code code; 74 | public: 75 | Modifier(Code pCode) : code(pCode) {} 76 | friend std::ostream& 77 | operator<<(std::ostream& os, const Modifier& mod) { 78 | return os << "\033[" << mod.code << "m"; 79 | } 80 | }; 81 | } 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/main/drbuddi_image_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRBUDDIIMAGEUTILITIES_H 2 | #define _DRBUDDIIMAGEUTILITIES_H 3 | 4 | #include "defines.h" 5 | #include "TORTOISE.h" 6 | 7 | 8 | using DisplacementFieldTransformType= TORTOISE::DisplacementFieldTransformType; 9 | 10 | ImageType3D::Pointer PreprocessImage( ImageType3D::Pointer inputImage,ImageType3D::PixelType lowerScaleValue,ImageType3D::PixelType upperScaleValue); 11 | 12 | ImageType3D::Pointer WarpImage(ImageType3D::Pointer img, DisplacementFieldType::Pointer field); 13 | 14 | DisplacementFieldType::PixelType ComputeImageGradient(ImageType3D::Pointer img,ImageType3D::IndexType &index); 15 | std::vector ComputeImageGradientImg(ImageType3D::Pointer img); 16 | 17 | void AddToUpdateField(DisplacementFieldType::Pointer updateField,DisplacementFieldType::Pointer updateField_temp,double weight); 18 | 19 | void ScaleUpdateField(DisplacementFieldType::Pointer field,float scale_factor); 20 | 21 | void RestrictPhase(DisplacementFieldType::Pointer field,vnl_vector phase_vector); 22 | 23 | DisplacementFieldType::Pointer InvertField( const DisplacementFieldType * field, const DisplacementFieldType * inverseFieldEstimate=nullptr ); 24 | DisplacementFieldType::Pointer NegateField( const DisplacementFieldType::Pointer field); 25 | 26 | void ContrainDefFields(DisplacementFieldType::Pointer field1, DisplacementFieldType::Pointer field2); 27 | 28 | DisplacementFieldType::Pointer ComposeFields(DisplacementFieldType::Pointer field,DisplacementFieldType::Pointer updateField); 29 | 30 | DisplacementFieldType::Pointer GaussianSmoothImage(DisplacementFieldType::Pointer field,double variance); 31 | ImageType3D::Pointer GaussianSmoothImage(ImageType3D::Pointer img,double variance); 32 | 33 | DisplacementFieldType::Pointer ResampleImage(DisplacementFieldType::Pointer field, ImageType3D::Pointer ref_img); 34 | ImageType3D::Pointer ResampleImage(ImageType3D::Pointer img, ImageType3D::Pointer ref_img); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/main/drbuddi_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRBUDDISTRUCTS_H 2 | #define _DRBUDDISTRUCTS_H 3 | 4 | 5 | #include "defines.h" 6 | 7 | #ifdef USECUDA 8 | #include "cuda_image.h" 9 | #endif 10 | 11 | enum DRBUDDIMetricEnumeration 12 | { 13 | CCSK = 0, 14 | CCJac =1, 15 | CCJacS=2, 16 | MSJac = 3, 17 | CC=4, 18 | IllegalMetric = 5 19 | }; 20 | 21 | class DRBUDDIMetric 22 | { 23 | public: 24 | 25 | void SetMetricType(DRBUDDIMetricEnumeration type) 26 | { 27 | MetricType=type; 28 | if(type==DRBUDDIMetricEnumeration::CCSK) 29 | metric_name="CCSK"; 30 | if(type==DRBUDDIMetricEnumeration::CCJac) 31 | metric_name="CCJac"; 32 | if(type==DRBUDDIMetricEnumeration::CCJacS) 33 | metric_name="CCJacS"; 34 | if(type==DRBUDDIMetricEnumeration::MSJac) 35 | metric_name="MSJac"; 36 | if(type==DRBUDDIMetricEnumeration::CC) 37 | metric_name="CC"; 38 | } 39 | 40 | #ifdef USECUDA 41 | CUDAIMAGE::Pointer up_img{nullptr}; 42 | CUDAIMAGE::Pointer down_img{nullptr}; 43 | CUDAIMAGE::Pointer str_img{nullptr}; 44 | #else 45 | ImageType3D::Pointer up_img{nullptr}; 46 | ImageType3D::Pointer down_img{nullptr}; 47 | ImageType3D::Pointer str_img{nullptr}; 48 | #endif 49 | 50 | float weight{1}; 51 | float param{5}; 52 | 53 | std::string metric_name; 54 | DRBUDDIMetricEnumeration MetricType; 55 | }; 56 | 57 | 58 | 59 | struct DRBUDDIStageSettings 60 | { 61 | int niter{100}; 62 | float img_smoothing_std{0}; 63 | int downsample_factor{1}; 64 | 65 | #ifdef USECUDA 66 | CUDAIMAGE::Pointer init_finv{nullptr}; 67 | CUDAIMAGE::Pointer init_minv{nullptr}; 68 | CUDAIMAGE::Pointer init_finv_const{nullptr}; 69 | CUDAIMAGE::Pointer init_minv_const{nullptr}; 70 | 71 | CUDAIMAGE::Pointer output_finv{nullptr}; 72 | CUDAIMAGE::Pointer output_minv{nullptr}; 73 | 74 | std::vector init_vfield; 75 | 76 | #else 77 | DisplacementFieldType::Pointer init_finv{nullptr}; 78 | DisplacementFieldType::Pointer init_minv{nullptr}; 79 | DisplacementFieldType::Pointer output_finv{nullptr}; 80 | DisplacementFieldType::Pointer output_minv{nullptr}; 81 | 82 | DisplacementFieldType::Pointer init_finv_const{nullptr}; 83 | DisplacementFieldType::Pointer init_minv_const{nullptr}; 84 | 85 | #endif 86 | 87 | std::vector metrics; 88 | 89 | float learning_rate{0.25}; 90 | float update_gaussian_sigma{3}; 91 | float total_gaussian_sigma{0}; 92 | 93 | bool restrct{0}; 94 | bool constrain{0}; 95 | }; 96 | 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/main/main.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TORTOISE.h" 3 | #include 4 | 5 | 6 | int main(int argc, char * argv[]) 7 | { 8 | 9 | itk::MultiThreaderBase::SetGlobalDefaultThreader(itk::MultiThreaderBase::ThreaderTypeFromString("Pool")); 10 | 11 | std::chrono::steady_clock::time_point Tbegin = std::chrono::steady_clock::now(); 12 | TORTOISE(argc,argv); 13 | 14 | std::chrono::steady_clock::time_point Tend = std::chrono::steady_clock::now(); 15 | 16 | std::cout << "TOTAL runtime: " << std::chrono::duration_cast (Tend - Tbegin).count() << "mins" << std::endl; 17 | 18 | return EXIT_SUCCESS; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/main/register_dwi_to_b0.h: -------------------------------------------------------------------------------- 1 | #ifndef _RegisterDWIToB0_H 2 | #define _RegisterDWIToB0_H 3 | 4 | #include "defines.h" 5 | 6 | 7 | #include "itkOkanQuadraticTransform.h" 8 | #include "mecc_settings.h" 9 | 10 | using QuadraticTransformType=itk::OkanQuadraticTransform; 11 | 12 | 13 | QuadraticTransformType::Pointer RegisterDWIToB0(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string phase, MeccSettings *mecc_settings, bool initialize,std::vector lim_arr, int vol, QuadraticTransformType::Pointer minit_trans=nullptr ) ; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/main/rigid_register_images.h: -------------------------------------------------------------------------------- 1 | #ifndef RIGIDREGISTERIMAGES_H 2 | #define RIGIDREGISTERIMAGES_H 3 | 4 | 5 | #include "TORTOISE.h" 6 | 7 | 8 | 9 | using QuadraticTransformType=TORTOISE::OkanQuadraticTransformType; 10 | using CompositeTransformType=TORTOISE::CompositeTransformType; 11 | using RigidTransformType= TORTOISE::RigidTransformType; 12 | 13 | 14 | QuadraticTransformType::Pointer CompositeLinearToQuadratic(const CompositeTransformType * compositeTransform, std::string phase); 15 | QuadraticTransformType::Pointer RigidRegisterImages(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string metric_type="CC"); 16 | RigidTransformType::Pointer RigidRegisterImagesEuler(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string metric_type="CC",float lr=0.4,bool gd=0, RigidTransformType::Pointer in_trans=nullptr); 17 | RigidTransformType::Pointer RigidRegisterImagesEulerSmall(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string metric_type="CC"); 18 | 19 | 20 | RigidTransformType::Pointer MultiStartRigidSearch(ImageType3D::Pointer fixed_img, ImageType3D::Pointer moving_img,std::string metric_type); 21 | 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/main/run_drbuddi_stage_TVVF.h: -------------------------------------------------------------------------------- 1 | #ifndef _RUNDRBUDDIStage_TVVF_H 2 | #define _RUNDRBUDDIStage_TVVF_H 3 | 4 | #include "drbuddi_structs.h" 5 | 6 | #include "DRBUDDI_Diffeo.h" 7 | #include "TORTOISE.h" 8 | 9 | #ifdef USECUDA 10 | #include "cuda_image.h" 11 | #endif 12 | 13 | #include "defines.h" 14 | #include "itkTimeProbe.h" 15 | #include "run_drbuddi_stage.h" 16 | 17 | class DRBUDDIStage_TVVF: public DRBUDDIStage 18 | { 19 | public: 20 | 21 | using CurrentFieldType = DRBUDDI_Diffeo::CurrentFieldType; 22 | using CurrentImageType = DRBUDDI_Diffeo::CurrentImageType; 23 | using PhaseEncodingVectorType=DRBUDDI_Diffeo::PhaseEncodingVectorType; 24 | 25 | DRBUDDIStage_TVVF(){}; 26 | DRBUDDIStage_TVVF(DRBUDDIStageSettings *my_settings) 27 | { 28 | settings=my_settings; 29 | velocity_field=my_settings->init_vfield; 30 | float tot_weight=0; 31 | for(int m=0;mmetrics.size();m++) 32 | tot_weight+=settings->metrics[m].weight; 33 | for(int m=0;mmetrics.size();m++) 34 | settings->metrics[m].weight/=tot_weight; 35 | 36 | #ifdef DRBUDDIALONE 37 | this->stream= &(std::cout); 38 | #else 39 | this->stream= TORTOISE::stream; 40 | #endif 41 | } 42 | ~DRBUDDIStage_TVVF(){}; 43 | 44 | 45 | void RunDRBUDDIStage(); 46 | void PreprocessImagesAndFields(); 47 | std::vector GetVelocityfield(){return velocity_field;} 48 | void SetVelocityField(std::vector vf){velocity_field=vf;} 49 | 50 | CurrentFieldType::Pointer IntegrateVelocityField(float lowt, float hight); 51 | 52 | 53 | void ComputeFields(CurrentFieldType::Pointer &def_finv, CurrentFieldType::Pointer &def_minv) 54 | { 55 | def_finv =IntegrateVelocityField(0.5,0); 56 | def_minv =IntegrateVelocityField(0.5,1); 57 | } 58 | 59 | private: 60 | std::vector velocity_field; 61 | public: 62 | static const int NTimePoints{7}; 63 | }; 64 | 65 | 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/tools/Combine3DImagesTo4D/Combine3DImagesTo4D.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "defines.h" 4 | #include "../utilities/write_3D_image_to_4D_file.h" 5 | 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | if(argc < 4) 10 | { 11 | std::cout<< "Usage: Combine3DImagesTo4D output_nifti_filename nifti1_filename nifti2_filename .......... niftiN_filename "<(argv[i]); 20 | 21 | write_3D_image_to_4D_file(img,argv[1],i-2,Nimgs); 22 | 23 | } 24 | 25 | 26 | return EXIT_SUCCESS; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/tools/CombineDWIs/combine_4dimages.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "defines.h" 4 | #include "../utilities/write_3D_image_to_4D_file.h" 5 | #include "../utilities/extract_3Dvolume_from_4D.h" 6 | 7 | #include "boost/filesystem.hpp" 8 | 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | if(argc < 4) 13 | { 14 | std::cout<< "Usage: Combine4DImages output_nifti_filename nifti1_filename nifti2_filename .......... niftiN_filename"<SetFileName(nii_name); 40 | myio->ReadImageInformation(); 41 | int Nvols= myio->GetDimensions(3); 42 | tot_Nvols+=Nvols; 43 | } 44 | 45 | std::cout<<"Total volumes: "<< tot_Nvols<(nii_name) ; 53 | int Nvols = img->GetLargestPossibleRegion().GetSize()[3]; 54 | 55 | for(int v=0;v(vol,output_name,vols_so_far+v,tot_Nvols); 59 | } 60 | vols_so_far+=Nvols; 61 | } 62 | 63 | 64 | return EXIT_SUCCESS; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/tools/CombineDWIs/combine_dwis_with_bmatrix_main.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | 7 | #include "combine_dwis_with_bmatrix.h" 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | if(argc < 4) 12 | { 13 | std::cout<< "Usage: CombineDWIsWithBMatrix output_nifti_filename nifti1_filename nifti2_filename .......... niftiN_filename"< nii_names; 34 | for(int ni=0;ni 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class ComputeDecMap_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | ComputeDecMap_PARSER( int argc , char * argv[] ); 15 | ~ComputeDecMap_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | double getColorParameter0(); 19 | double getColorParameter1(); 20 | double getColorParameter2(); 21 | double getColorParameter3(); 22 | double getGammaFactor(); 23 | double getPercentBeta(); 24 | double getLatticeIndexMax(); 25 | double getLatticeIndexMin(); 26 | double getScaleXp(); 27 | bool getUseFA(); 28 | 29 | private: 30 | void CreateParserandFillText(int argc , char * argv[] ); 31 | void InitializeCommandLineOptions(); 32 | bool checkIfAllRequiredParamsAreEntered(); 33 | }; 34 | 35 | 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/tools/ComputeLIMap/compute_li_map.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #include "compute_li_map.h" 9 | 10 | 11 | typedef itk::DiffusionTensor3D TensorPixelType; 12 | typedef itk::Vector VectorPixelType; 13 | 14 | typedef itk::Image,3> TensorImageType; 15 | typedef itk::Image VectorImageType; 16 | 17 | 18 | 19 | 20 | 21 | 22 | int main( int argc , char * argv[] ) 23 | { 24 | if(argc<2) 25 | { 26 | std::cout<<"Usage: ComputeLIMap full_path_to_tensor_image full_path_to_AM_image (optional)"< ImageType4DReaderType; 45 | ImageType4DReaderType::Pointer imager= ImageType4DReaderType::New(); 46 | imager->SetFileName(nm); 47 | imager->Update(); 48 | ImageType4D::Pointer image4D= imager->GetOutput(); 49 | 50 | 51 | ImageType3D::Pointer A0_image=nullptr; 52 | if(argc>2) 53 | { 54 | typedef itk::ImageFileReader ImageType3DReaderType; 55 | ImageType3DReaderType::Pointer imager2= ImageType3DReaderType::New(); 56 | imager2->SetFileName(argv[2]); 57 | imager2->Update(); 58 | A0_image= imager2->GetOutput(); 59 | 60 | } 61 | else 62 | { 63 | std::string filename(argv[1]); 64 | std::string::size_type idx=filename.rfind("DT."); 65 | std::string basename= filename.substr(mypos+1,idx-mypos-1); 66 | std::string A0name=currdir + basename + std::string("AM.nii"); 67 | 68 | typedef itk::ImageFileReader ImageType3DReaderType; 69 | ImageType3DReaderType::Pointer imager2= ImageType3DReaderType::New(); 70 | imager2->SetFileName(A0name); 71 | imager2->Update(); 72 | A0_image= imager2->GetOutput(); 73 | } 74 | 75 | 76 | ImageType3D::Pointer li_map= compute_li_map(image4D,A0_image); 77 | 78 | 79 | 80 | 81 | 82 | 83 | std::string filename(argv[1]); 84 | std::string::size_type idx=filename.rfind('.'); 85 | std::string basename= filename.substr(mypos+1,idx-mypos-1); 86 | std::string output_name=currdir + basename + std::string("_LI.nii"); 87 | 88 | 89 | 90 | typedef itk::ImageFileWriter WriterType; 91 | WriterType::Pointer writer= WriterType::New(); 92 | writer->SetFileName(output_name); 93 | writer->SetInput(li_map); 94 | writer->Update(); 95 | 96 | 97 | 98 | 99 | 100 | 101 | return EXIT_SUCCESS; 102 | } 103 | -------------------------------------------------------------------------------- /src/tools/ComputeNSDECMap/compute_ns_dec_map_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTE_NS_DEC_MAP_PARSER_h 2 | #define _COMPUTE_NS_DEC_MAP_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class ComputeNSDecMap_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | ComputeNSDecMap_PARSER( int argc , char * argv[] ); 15 | ~ComputeNSDecMap_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | double getColorParameter0(); 19 | double getColorParameter1(); 20 | double getColorParameter2(); 21 | double getColorParameter3(); 22 | double getGammaFactor(); 23 | double getPercentBeta(); 24 | double getLatticeIndexMax(); 25 | double getLatticeIndexMin(); 26 | double getScaleXp(); 27 | 28 | private: 29 | void CreateParserandFillText(int argc , char * argv[] ); 30 | void InitializeCommandLineOptions(); 31 | bool checkIfAllRequiredParamsAreEntered(); 32 | }; 33 | 34 | 35 | 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /src/tools/ComputeWLMap/compute_wl_map.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "compute_wl_map.h" 5 | 6 | 7 | 8 | int main( int argc , char * argv[] ) 9 | { 10 | if(argc<2) 11 | { 12 | std::cout<< "Computes the Westin-Linear map from the diffusion tensor"< ImageType4DReaderType; 31 | ImageType4DReaderType::Pointer imager= ImageType4DReaderType::New(); 32 | imager->SetFileName(nm); 33 | imager->Update(); 34 | ImageType4D::Pointer image4D= imager->GetOutput(); 35 | 36 | 37 | ImageType3D::Pointer scalar_image = compute_wl(image4D); 38 | 39 | 40 | std::string filename(argv[1]); 41 | std::string::size_type idx=filename.rfind('.'); 42 | std::string basename= filename.substr(mypos+1,idx-mypos-1); 43 | std::string output_name=currdir + basename + std::string("_WL.nii"); 44 | 45 | 46 | 47 | typedef itk::ImageFileWriter WriterType; 48 | WriterType::Pointer writer= WriterType::New(); 49 | writer->SetFileName(output_name); 50 | writer->SetInput(scalar_image); 51 | writer->Update(); 52 | 53 | 54 | 55 | 56 | 57 | 58 | return EXIT_SUCCESS; 59 | } 60 | -------------------------------------------------------------------------------- /src/tools/ComputeWPMap/compute_wp_map.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include "compute_wp_map.h" 3 | 4 | 5 | 6 | 7 | int main( int argc , char * argv[] ) 8 | { 9 | if(argc<2) 10 | { 11 | std::cout<< "Computes the Westin-Planar map from the diffusion tensor"< ImageType4DReaderType; 30 | ImageType4DReaderType::Pointer imager= ImageType4DReaderType::New(); 31 | imager->SetFileName(nm); 32 | imager->Update(); 33 | ImageType4D::Pointer image4D= imager->GetOutput(); 34 | 35 | ImageType3D::Pointer scalar_image = compute_wp(image4D); 36 | 37 | 38 | 39 | std::string filename(argv[1]); 40 | std::string::size_type idx=filename.rfind('.'); 41 | std::string basename= filename.substr(mypos+1,idx-mypos-1); 42 | std::string output_name=currdir + basename + std::string("_WP.nii"); 43 | 44 | 45 | 46 | typedef itk::ImageFileWriter WriterType; 47 | WriterType::Pointer writer= WriterType::New(); 48 | writer->SetFileName(output_name); 49 | writer->SetInput(scalar_image); 50 | writer->Update(); 51 | 52 | 53 | 54 | 55 | 56 | 57 | return EXIT_SUCCESS; 58 | } 59 | -------------------------------------------------------------------------------- /src/tools/ConvertQuadraticTransformToDisplacementField/convert_eddy_trans_to_field.hxx: -------------------------------------------------------------------------------- 1 | #ifndef _CONVERTEDDYTANSTOFIELD_H 2 | #define _CONVERTEDDYTANSTOFIELD_H 3 | 4 | #include "defines.h" 5 | #include "TORTOISE.h" 6 | 7 | using CompositeTransformType= TORTOISE::CompositeTransformType; 8 | using OkanQuadraticTransformType= TORTOISE::OkanQuadraticTransformType; 9 | using DisplacementFieldTransformType= TORTOISE::DisplacementFieldTransformType; 10 | 11 | 12 | 13 | 14 | DisplacementFieldType::Pointer ConvertEddyTransformToField(CompositeTransformType::Pointer eddy_trans,ImageType3D::Pointer ref_img,ImageType3D::Pointer ref_img_DP) 15 | { 16 | DisplacementFieldType::Pointer field=DisplacementFieldType::New(); 17 | field->SetRegions(ref_img->GetLargestPossibleRegion()); 18 | field->Allocate(); 19 | DisplacementFieldType::PixelType zero; zero.Fill(0); 20 | field->FillBuffer(zero); 21 | field->SetDirection(ref_img->GetDirection()); 22 | field->SetOrigin(ref_img->GetOrigin()); 23 | field->SetSpacing(ref_img->GetSpacing()); 24 | 25 | 26 | itk::ImageRegionIteratorWithIndex it(ref_img_DP,ref_img_DP->GetLargestPossibleRegion()); 27 | it.GoToBegin(); 28 | while(!it.IsAtEnd()) 29 | { 30 | ImageType3D::IndexType ind3= it.GetIndex(); 31 | ImageType3D::PointType pt,pt_trans; 32 | ref_img_DP->TransformIndexToPhysicalPoint(ind3,pt); 33 | pt_trans= eddy_trans->TransformPoint(pt); 34 | 35 | itk::ContinuousIndex cind; 36 | ref_img_DP->TransformPhysicalPointToContinuousIndex(pt_trans,cind); 37 | 38 | ref_img->TransformIndexToPhysicalPoint(ind3,pt); 39 | ref_img->TransformContinuousIndexToPhysicalPoint(cind,pt_trans); 40 | 41 | DisplacementFieldType::PixelType vec; 42 | vec[0]= pt_trans[0]- pt[0]; 43 | vec[1]= pt_trans[1]- pt[1]; 44 | vec[2]= pt_trans[2]- pt[2]; 45 | field->SetPixel(ind3,vec); 46 | 47 | 48 | ++it; 49 | } 50 | return field; 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/tools/CreateDummyJson/CreateDummyJson.cxx: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | #include "CreateDummyJson_parser.h" 3 | 4 | 5 | #include "../utilities/read_3Dvolume_from_4D.h" 6 | 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | 11 | CreateDummyJson_PARSER *parser= new CreateDummyJson_PARSER(argc,argv); 12 | 13 | 14 | json my_json; 15 | 16 | int MBf= parser->getMBFactor(); 17 | std::string phase= parser->getPhaseEncoding(); 18 | float PF= parser->getPF(); 19 | 20 | 21 | my_json["PartialFourier"] = PF; 22 | my_json["PhaseEncodingDirection"]= phase; 23 | my_json["MultibandAccelerationFactor"]=MBf; 24 | if(parser->getBigDelta()!=-1) 25 | my_json["BigDelta"]=parser->getBigDelta(); 26 | if(parser->getSmallDelta()!=-1) 27 | my_json["SmallDelta"]=parser->getSmallDelta(); 28 | 29 | 30 | 31 | ImageType3D::Pointer first_vol = readImageD(parser->getInputImageName()); 32 | 33 | //ImageType3D::Pointer first_vol = read_3D_volume_from_4D(parser->getInputImageName(),0); 34 | ImageType3D::SizeType sz= first_vol->GetLargestPossibleRegion().GetSize(); 35 | 36 | std::vector times; 37 | times.resize(sz[2]); 38 | 39 | if(parser->getInterLeave()==0) 40 | { 41 | int Nexc= sz[2]/MBf; 42 | for(int k=0;kgetInputImageName(); 83 | std::string json_name= name.substr(0,name.find(".nii")) + ".json"; 84 | std::ofstream out_json(json_name); 85 | out_json << std::setw(4) << my_json << std::endl; 86 | out_json.close(); 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/tools/CreateDummyJson/CreateDummyJson_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _CreateDummyJson_PARSER_h 2 | #define _CreateDummyJson_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class CreateDummyJson_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | CreateDummyJson_PARSER( int argc , char * argv[] ); 15 | ~CreateDummyJson_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getPhaseEncoding(); 19 | int getMBFactor(); 20 | float getPF(); 21 | float getBigDelta(); 22 | float getSmallDelta(); 23 | bool getInterLeave(); 24 | 25 | 26 | 27 | private: 28 | void CreateParserandFillText(int argc , char * argv[] ); 29 | void InitializeCommandLineOptions(); 30 | bool checkIfAllRequiredParamsAreEntered(); 31 | }; 32 | 33 | 34 | 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/tools/CreateGradientNonlinearityBMatrix/CreateGradientNonlinearityBMatrix_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _CreateGradientNonlinearityBMatrix_PARSER_h 2 | #define _CreateGradientNonlinearityBMatrix_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class CreateGradientNonlinearityBMatrix_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | CreateGradientNonlinearityBMatrix_PARSER( int argc , char * argv[] ); 15 | ~CreateGradientNonlinearityBMatrix_PARSER(); 16 | 17 | std::string getFinalImageName(); 18 | std::string getInitialImageName(); 19 | 20 | std::string getNonlinearity(); 21 | bool getIsGE(); 22 | 23 | private: 24 | void CreateParserandFillText(int argc , char * argv[] ); 25 | void InitializeCommandLineOptions(); 26 | bool checkIfAllRequiredParamsAreEntered(); 27 | }; 28 | 29 | 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/tools/CreateMask/create_mask_main.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _CREATEMASKMAIN_CXX 2 | #define _CREATEMASKMAIN_CXX 3 | 4 | #include "../main/create_mask.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | if(argc==1) 9 | { 10 | std::cout<<"Usage: CreateMask input_img output_name"<(argv[1]); 14 | 15 | ImageType3D::Pointer mask_img = create_mask(img); 16 | writeImageD(mask_img, argv[2]); 17 | 18 | 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/tools/CreateNonlinearityDisplacementMap/mk_displacementMaps.cxx: -------------------------------------------------------------------------------- 1 | #include "mk_displacementMaps.h" 2 | #include "read_3Dvolume_from_4D.h" 3 | 4 | 5 | 6 | 7 | int main(int argc,char *argv[]) 8 | { 9 | if(argc<2) 10 | { 11 | std::cout<<"CreateNonlinearityDisplacementMap path_to_coefficient_or_gradcal_file path_to_base_nifti outputname is_GE (0/1. optional.default:0)"<4) 18 | is_GE=(bool)(argv[4]); 19 | 20 | DisplacementFieldType::Pointer output_field= mk_displacement(argv[2], argv[1],is_GE); 21 | 22 | 23 | typedef itk::ImageFileWriter WrType; 24 | WrType::Pointer wr= WrType::New(); 25 | wr->SetInput(output_field); 26 | wr->SetFileName(argv[3]); 27 | wr->Update(); 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/tools/DIFFPREPAnonymizer/diffprep_anonymizer.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIFFPREP_ANONYMIZER_h 2 | #define _DIFFPREP_ANONYMIZER_h 3 | 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | #include 10 | #include "itkGDCMImageIOOkan.h" 11 | 12 | 13 | #include "defines.h" 14 | 15 | 16 | 17 | typedef itk::GDCMImageIOOkan ImageIOType; 18 | typedef itk::Image SliceType; 19 | 20 | 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/tools/DIFFPREPAnonymizer/tag_list.txt: -------------------------------------------------------------------------------- 1 | 0008,0050 2 | 0008,0080 3 | 0008,0081 4 | 0008,0090 5 | 0008,1010 6 | 0008,1030 7 | 0008,103E 8 | 0008,1040 9 | 0008,1048 10 | 0008,1050 11 | 0008,1070 12 | 0010,0010 13 | 0010,0020 14 | 0010,0021 15 | 0010,0030 16 | 0010,0040 17 | 0010,1010 18 | 0010,1020 19 | 0010,1030 20 | 0010,1040 21 | 0010,2110 22 | 0010,2150 23 | 0018,1000 24 | 0020,000D 25 | 0020,000E 26 | 0020,0010 27 | 0032,1032 28 | 0032,1033 29 | 0032,1060 30 | 0040,0280 31 | 0008,0100 32 | 0008,010F 33 | -------------------------------------------------------------------------------- /src/tools/DRBUDDI/DRBUDDI_parserBase.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRBUDDI_PARSERBASE_h 2 | #define _DRBUDDI_PARSERBASE_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | 12 | class DRBUDDI_PARSERBASE : public itk::ants::CommandLineParser 13 | { 14 | public: 15 | DRBUDDI_PARSERBASE( int argc , char * argv[],bool print ); 16 | ~DRBUDDI_PARSERBASE(); 17 | 18 | std::string getUpInputName(); 19 | std::string getUpJSonName(); 20 | std::string getDownInputName(); 21 | std::vector getStructuralNames(); 22 | std::string getDRBUDDIOutput(); 23 | int getDRBUDDIStep(); 24 | 25 | std::string getGradNonlinInput(); 26 | void setGradNonlinInput(std::string fname); 27 | bool getGradNonlinIsGE(); 28 | std::string getGradNonlinGradWarpDim(); 29 | bool getNOGradWarp(); 30 | 31 | bool getDisableInitRigid(); 32 | bool getStartWithDiffeo(); 33 | std::string getRigidMetricType(); 34 | float getRigidLR(); 35 | int getDWIBvalue(); 36 | 37 | std::string GetInitialMINV(); 38 | std::string GetInitialFINV(); 39 | int getNumberOfStages(); 40 | std::vector getStageString(int st); 41 | int GetNIter(int st); 42 | int GetF(int st); 43 | float GetS(int st); 44 | float GetLR(int st); 45 | float GetUStd(int st); 46 | float GetTStd(int st); 47 | bool GetRestrict(int st); 48 | bool GetConstrain(int st); 49 | int GetNMetrics(int st); 50 | std::string GetMetricString(int st,int m); 51 | bool getEstimateLRPerIteration(); 52 | 53 | float getStructuralWeight(); 54 | bool getDisableLastStage(); 55 | 56 | bool getEnforceFullAntiSymmetry(); 57 | 58 | int getNumberOfStructurals(); 59 | std::string getStructuralNames(int str_id); 60 | 61 | bool getDisableITKThreads(); 62 | std::string getRegistrationMethodType(); 63 | 64 | int getNumberOfCores(); 65 | 66 | protected: 67 | void InitializeCommandLineOptions(); 68 | 69 | 70 | private: 71 | virtual void CreateParserandFillText(int argc , char * argv[] ); 72 | 73 | }; 74 | 75 | 76 | 77 | 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/ApplyTransformationToTensorDRT.cxx: -------------------------------------------------------------------------------- 1 | #include "DRTAMAS.h" 2 | #include "../utilities/read_3Dvolume_from_4D.h" 3 | #include "../utilities/write_3D_image_to_4D_file.h" 4 | 5 | 6 | 7 | #include "itkResampleImageFilter.h" 8 | #include "itkTransformFileReader.h" 9 | #include "itkExtractImageFilter.h" 10 | 11 | 12 | #include "DRTAMAS_utilities_cp.h" 13 | 14 | 15 | 16 | 17 | int main( int argc , char * argv[] ) 18 | { 19 | if(argc<4) 20 | { 21 | std::cout<<"Usage: ApplyTransformationToTensor full_path_to_tensor_to_be_transformed full_path_to_transformation full_path_to_name_of_output full_path_to_TENSOR_with_desired_dimensions "< FieldReaderType; 44 | typename FieldReaderType::Pointer mreader=FieldReaderType::New(); 45 | mreader->SetFileName(filename); 46 | mreader->Update(); 47 | disp_field =mreader->GetOutput(); 48 | 49 | TransformAndWriteDiffeoImage(tensor,disp_field,ref_tensor, output_nii_name); 50 | } 51 | else 52 | { 53 | using TransformReaderType =itk::TransformFileReaderTemplate< double > ; 54 | TransformReaderType::Pointer reader = TransformReaderType::New(); 55 | reader->SetFileName(filename ); 56 | reader->Update(); 57 | const TransformReaderType::TransformListType * transforms = reader->GetTransformList(); 58 | itk::TransformFileReader::TransformListType::const_iterator it = transforms->begin(); 59 | affine_trans = static_cast((*it).GetPointer()); 60 | 61 | TransformAndWriteAffineImage(tensor,affine_trans,ref_tensor, output_nii_name); 62 | 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMAS_h 2 | #define _DRTAMAS_h 3 | 4 | 5 | #include "DRTAMAS_parser.h" 6 | #include "defines.h" 7 | 8 | #include "TORTOISE.h" 9 | 10 | 11 | 12 | 13 | 14 | class DRTAMAS 15 | { 16 | public: 17 | DRTAMAS( ){}; 18 | ~DRTAMAS(){}; 19 | 20 | using RigidTransformType = TORTOISE::RigidTransformType; 21 | using AffineTransformType= TORTOISE::AffineTransformType; 22 | using DisplacementFieldType = TORTOISE::DisplacementFieldType; 23 | using DisplacementFieldTransformType = TORTOISE::DisplacementFieldTransformType; 24 | 25 | 26 | 27 | 28 | 29 | public: 30 | void SetParser(DRTAMAS_PARSER* p){parser=p;} 31 | void Process(); 32 | 33 | 34 | private: 35 | void Step0_ReadImages(); 36 | void Step0_AffineRegistration(); 37 | void Step0_TransformAndWriteAffineImage(); 38 | void Step1_DiffeoRegistration(); 39 | void Step2_WriteImages(); 40 | 41 | // vnl_matrix_fixed ComputeJacobian(DisplacementFieldType::Pointer field,DisplacementFieldType::IndexType ind3 ); 42 | 43 | 44 | 45 | private: 46 | // DTMatrixImageType::Pointer ReadAndOrientTensor(std::string fname); 47 | 48 | 49 | private: 50 | DRTAMAS_PARSER* parser{nullptr}; 51 | 52 | DTMatrixImageType::Pointer fixed_tensor{nullptr}; 53 | DTMatrixImageType::Pointer moving_tensor{nullptr}; 54 | DTMatrixImageType::Pointer moving_tensor_aff{nullptr}; 55 | std::vector fixed_structurals; 56 | std::vector moving_structurals; 57 | 58 | AffineTransformType::Pointer my_affine_trans{nullptr}; 59 | DisplacementFieldType::Pointer def{nullptr}; 60 | 61 | 62 | }; 63 | 64 | 65 | 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMASRigid.cxx: -------------------------------------------------------------------------------- 1 | #include "DRTAMASRigid.h" 2 | #include "../utilities/read_3Dvolume_from_4D.h" 3 | #include "../utilities/write_3D_image_to_4D_file.h" 4 | 5 | 6 | #include "itkImageRegionIteratorWithIndex.h" 7 | #include "itkResampleImageFilter.h" 8 | #include "itkTransformFileReader.h" 9 | #include "itkTransformFileWriter.h" 10 | 11 | #include "DRTAMAS_utilities_cp.h" 12 | #include "DRTAMASRigid_Bulk.h" 13 | 14 | 15 | 16 | 17 | void DRTAMASRigid::Process2() 18 | { 19 | Step0_ReadImages(); 20 | Step1_RigidRegistration(); 21 | Step2_TransformAndWriteAffineImage(); 22 | 23 | std::cout<<"DRTAMASRigid completed sucessfully..."<SetFixedTensor(this->fixed_tensor); 34 | myDRTAMASRigid_processor->SetMovingTensor(this->moving_tensor); 35 | myDRTAMASRigid_processor->SetParser(parser); 36 | myDRTAMASRigid_processor->Process(); 37 | 38 | 39 | this->my_rigid_trans = myDRTAMASRigid_processor->GetRigidTrans(); 40 | 41 | delete myDRTAMASRigid_processor; 42 | 43 | } 44 | 45 | 46 | 47 | void DRTAMASRigid::Step2_TransformAndWriteAffineImage() 48 | { 49 | 50 | std::string moving_dt_name = parser->getMovingTensor(); 51 | std::string output_nii_name = moving_dt_name.substr(0,moving_dt_name.rfind(".nii")) + "_aff.nii"; 52 | 53 | using AffineTransformType= TORTOISE::AffineTransformType; 54 | AffineTransformType::Pointer naff= AffineTransformType::New(); 55 | 56 | naff->SetIdentity(); 57 | naff->SetMatrix(this->my_rigid_trans->GetMatrix()); 58 | naff->SetFixedParameters(this->my_rigid_trans->GetFixedParameters()); 59 | naff->SetCenter(this->my_rigid_trans->GetCenter()); 60 | naff->SetOffset(this->my_rigid_trans->GetOffset()); 61 | naff->SetTranslation(this->my_rigid_trans->GetTranslation()); 62 | 63 | 64 | TransformAndWriteAffineImage(this->moving_tensor,naff, this->fixed_tensor, output_nii_name); 65 | } 66 | 67 | 68 | 69 | void DRTAMASRigid::Step0_ReadImages() 70 | { 71 | 72 | std::string fixed_tensor_fname = parser->getFixedTensor(); 73 | this->fixed_tensor = ReadAndOrientTensor(fixed_tensor_fname); 74 | 75 | std::string moving_tensor_fname = parser->getMovingTensor(); 76 | this->moving_tensor = ReadAndOrientTensor(moving_tensor_fname); 77 | } 78 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMASRigid.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMASRigid_h 2 | #define _DRTAMASRigid_h 3 | 4 | 5 | #include "DRTAMAS_parser.h" 6 | #include "defines.h" 7 | 8 | #include "TORTOISE.h" 9 | 10 | 11 | 12 | 13 | 14 | class DRTAMASRigid 15 | { 16 | public: 17 | DRTAMASRigid(){}; 18 | ~DRTAMASRigid(){}; 19 | 20 | using RigidTransformType = TORTOISE::RigidTransformType; 21 | 22 | 23 | public: 24 | void SetParser(DRTAMAS_PARSER* p){parser=p;}; 25 | void Process2(); 26 | 27 | 28 | private: 29 | void Step0_ReadImages(); 30 | void Step1_RigidRegistration(); 31 | void Step2_TransformAndWriteAffineImage(); 32 | 33 | 34 | 35 | 36 | private: 37 | 38 | 39 | private: 40 | DRTAMAS_PARSER* parser{nullptr}; 41 | 42 | DTMatrixImageType::Pointer fixed_tensor{nullptr}; 43 | DTMatrixImageType::Pointer moving_tensor{nullptr}; 44 | 45 | RigidTransformType::Pointer my_rigid_trans{nullptr}; 46 | 47 | 48 | 49 | }; 50 | 51 | 52 | 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMASRigid_Bulk.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMASDIFFEO_H 2 | #define _DRTAMASDIFFEO_H 3 | 4 | 5 | #include "drtamas_structs.h" 6 | #include "defines.h" 7 | #include "TORTOISE.h" 8 | 9 | #include "DRTAMAS_parser.h" 10 | 11 | 12 | #include "cuda_image.h" 13 | #include "../cuda_src/cuda_image_utilities.h" 14 | 15 | 16 | class DRTAMASRigid_Bulk 17 | { 18 | public: 19 | 20 | 21 | using CurrentFieldType = CUDAIMAGE; 22 | using CurrentImageType = CUDAIMAGE; 23 | 24 | using RigidTransformType = TORTOISE::RigidTransformType; 25 | 26 | 27 | DRTAMASRigid_Bulk() 28 | { 29 | this->stream= &(std::cout); 30 | } 31 | 32 | ~DRTAMASRigid_Bulk(){}; 33 | 34 | void SetFixedTensor(DTMatrixImageType::Pointer tens) 35 | { 36 | this->fixed_tensor = CUDAIMAGE::New(); 37 | this->fixed_tensor->SetTImageFromITK(tens); 38 | } 39 | 40 | void SetMovingTensor(DTMatrixImageType::Pointer tens) 41 | { 42 | this->moving_tensor = CUDAIMAGE::New(); 43 | this->moving_tensor->SetTImageFromITK(tens); 44 | } 45 | 46 | void SetStagesFromExternal(std::vector st){stages=st;} 47 | void SetParser(DRTAMAS_PARSER *prs){parser=prs;}; 48 | 49 | RigidTransformType::Pointer GetRigidTrans(){return my_rigid_trans;} 50 | 51 | 52 | private: //Subfunctions the main processing functions use 53 | void SetImagesForMetrics(); 54 | void SetUpStages(); 55 | void SetDefaultStages(); 56 | 57 | 58 | public: //Main processing functions 59 | void Process(); 60 | 61 | // std::string GetRegistrationMethodType(){return parser->getRegistrationMethodType();} 62 | 63 | 64 | 65 | private: //Main processing functions 66 | 67 | 68 | 69 | 70 | 71 | private: //class member variables 72 | 73 | CUDAIMAGE::Pointer fixed_tensor{nullptr}; 74 | CUDAIMAGE::Pointer moving_tensor{nullptr}; 75 | 76 | std::vector stages; 77 | 78 | 79 | 80 | 81 | std::ostream *stream; 82 | DRTAMAS_PARSER *parser{nullptr}; 83 | 84 | RigidTransformType::Pointer my_rigid_trans{nullptr}; 85 | 86 | }; 87 | 88 | 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMASRigid_main.cxx: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | 4 | #include "DRTAMAS_parser.h" 5 | #include "DRTAMASRigid.h" 6 | 7 | int main(int argc,char *argv[]) 8 | { 9 | DRTAMAS_PARSER *parser= new DRTAMAS_PARSER(argc,argv); 10 | 11 | 12 | for(int i=0;iSetParser(parser); 22 | my_program->Process2(); 23 | } 24 | catch( itk::ExceptionObject & err ) 25 | { 26 | std::cerr << "Exception Object caught: " << std::endl; 27 | std::cerr << err << std::endl; 28 | return EXIT_FAILURE; 29 | } 30 | 31 | 32 | 33 | return EXIT_SUCCESS; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS_Diffeo.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMASDIFFEO_H 2 | #define _DRTAMASDIFFEO_H 3 | 4 | 5 | #include "drtamas_structs.h" 6 | #include "defines.h" 7 | #include "TORTOISE.h" 8 | 9 | #include "DRTAMAS_parser.h" 10 | 11 | 12 | #include "cuda_image.h" 13 | #include "../cuda_src/cuda_image_utilities.h" 14 | 15 | 16 | class DRTAMAS_Diffeo 17 | { 18 | public: 19 | 20 | 21 | using CurrentFieldType = CUDAIMAGE; 22 | using CurrentImageType = CUDAIMAGE; 23 | 24 | 25 | DRTAMAS_Diffeo() 26 | { 27 | this->stream= &(std::cout); 28 | } 29 | 30 | ~DRTAMAS_Diffeo(){}; 31 | 32 | DisplacementFieldType::Pointer getDef() 33 | { 34 | CurrentFieldType::Pointer def_F= InvertField(def_FINV); 35 | CurrentFieldType::Pointer def = ComposeFields(def_F,this->def_MINV); 36 | 37 | 38 | DisplacementFieldType::Pointer disp=def->CudaImageToITKField(); 39 | return disp; 40 | } 41 | 42 | void SetFixedStructurals(std::vector si) 43 | { 44 | for(int i=0;iSetImageFromITK(si[i]); 48 | this->fixed_structurals.push_back(str_img); 49 | } 50 | } 51 | void SetMovingStructurals(std::vector si) 52 | { 53 | for(int i=0;iSetImageFromITK(si[i]); 57 | this->moving_structurals.push_back(str_img); 58 | } 59 | } 60 | 61 | void SetFixedTensor(DTMatrixImageType::Pointer tens) 62 | { 63 | this->fixed_tensor = CUDAIMAGE::New(); 64 | this->fixed_tensor->SetTImageFromITK(tens); 65 | } 66 | 67 | void SetMovingTensor(DTMatrixImageType::Pointer tens) 68 | { 69 | this->moving_tensor = CUDAIMAGE::New(); 70 | this->moving_tensor->SetTImageFromITK(tens); 71 | } 72 | 73 | 74 | 75 | 76 | void SetStagesFromExternal(std::vector st){stages=st;} 77 | void SetParser(DRTAMAS_PARSER *prs){parser=prs;}; 78 | 79 | 80 | private: //Subfunctions the main processing functions use 81 | void SetImagesForMetrics(); 82 | void SetUpStages(); 83 | void SetDefaultStages(); 84 | 85 | 86 | public: //Main processing functions 87 | void Process(); 88 | 89 | // std::string GetRegistrationMethodType(){return parser->getRegistrationMethodType();} 90 | 91 | 92 | 93 | private: //Main processing functions 94 | 95 | 96 | 97 | 98 | 99 | private: //class member variables 100 | 101 | CUDAIMAGE::Pointer fixed_tensor{nullptr}; 102 | CUDAIMAGE::Pointer moving_tensor{nullptr}; 103 | std::vector fixed_structurals; 104 | std::vector moving_structurals; 105 | 106 | CUDAIMAGE::Pointer def_FINV{nullptr}; 107 | CUDAIMAGE::Pointer def_MINV{nullptr}; 108 | 109 | 110 | std::vector stages; 111 | 112 | 113 | std::ostream *stream; 114 | DRTAMAS_PARSER *parser{nullptr}; 115 | 116 | }; 117 | 118 | 119 | 120 | #endif 121 | 122 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS_main.cxx: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | 4 | #include "DRTAMAS_parser.h" 5 | #include "DRTAMAS.h" 6 | 7 | int main(int argc,char *argv[]) 8 | { 9 | DRTAMAS_PARSER *parser= new DRTAMAS_PARSER(argc,argv); 10 | 11 | 12 | for(int i=0;iSetParser(parser); 22 | my_program->Process(); 23 | } 24 | catch( itk::ExceptionObject & err ) 25 | { 26 | std::cerr << "Exception Object caught: " << std::endl; 27 | std::cerr << err << std::endl; 28 | return EXIT_FAILURE; 29 | } 30 | 31 | 32 | 33 | return EXIT_SUCCESS; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMAS_PARSER_h 2 | #define _DRTAMAS_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | 12 | class DRTAMAS_PARSER : public itk::ants::CommandLineParser 13 | { 14 | public: 15 | DRTAMAS_PARSER( int argc , char * argv[]); 16 | ~DRTAMAS_PARSER(); 17 | 18 | 19 | std::string getFixedTensor(); 20 | std::string getMovingTensor(); 21 | 22 | std::vector getFixedStructuralNames(); 23 | std::vector getMovingStructuralNames(); 24 | 25 | std::string getOutput(); 26 | int getStep(); 27 | 28 | std::string GetInitialMINV(); 29 | std::string GetInitialFINV(); 30 | 31 | std::string getInitialRigidTransform(); 32 | 33 | 34 | int getNumberOfStages(); 35 | std::vector getStageString(int st); 36 | int GetNIter(int st); 37 | int GetF(int st); 38 | float GetS(int st); 39 | float GetLR(int st); 40 | float GetUStd(int st); 41 | float GetTStd(int st); 42 | 43 | int GetNMetrics(int st); 44 | std::string GetMetricString(int st,int m); 45 | 46 | 47 | int getNumberOfStructurals(); 48 | std::string getFixedStructuralName(int str_id); 49 | std::string getMovingStructuralName(int str_id); 50 | 51 | std::string getRegistrationMethodType(); 52 | 53 | bool getOnlyAffine(); 54 | bool getNoSmoothingLastStage(); 55 | 56 | 57 | 58 | protected: 59 | void InitializeCommandLineOptions(); 60 | 61 | 62 | private: 63 | virtual void CreateParserandFillText(int argc , char * argv[] ); 64 | 65 | }; 66 | 67 | 68 | 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMAS_UTILITIES_h 2 | #define _DRTAMAS_UTILITIES_h 3 | 4 | 5 | #include "cuda_image.h" 6 | 7 | #include "itkEuler3DTransform.h" 8 | using TransformType=itk::Euler3DTransform; 9 | 10 | void ComputeTRMapC_cuda(cudaPitchedPtr tensor_img, cudaPitchedPtr output, const int3 data_sz); 11 | CUDAIMAGE::Pointer ComputeTRMapC(CUDAIMAGE::Pointer tensor_img); 12 | 13 | 14 | void LogTensor_cuda(cudaPitchedPtr tens, cudaPitchedPtr output, const int3 data_sz); 15 | CUDAIMAGE::Pointer LogTensor(CUDAIMAGE::Pointer tens); 16 | 17 | void ExpTensor_cuda(cudaPitchedPtr tens, cudaPitchedPtr output, const int3 data_sz); 18 | CUDAIMAGE::Pointer ExpTensor(CUDAIMAGE::Pointer tens); 19 | 20 | void RotateTensors_cuda(cudaPitchedPtr tens, cudaPitchedPtr output, const int3 data_sz, float mat_arr[]); 21 | CUDAIMAGE::Pointer RotateTensors(CUDAIMAGE::Pointer tens,TransformType::Pointer rigid_trans); 22 | 23 | 24 | void SplitImageComponents_cuda(cudaPitchedPtr tensor_img, 25 | cudaPitchedPtr *output, 26 | int3 data_sz, 27 | int Ncomp); 28 | std::vector SplitImageComponents(CUDAIMAGE::Pointer img); 29 | 30 | 31 | 32 | void CombineImageComponents_cuda(cudaPitchedPtr *img, 33 | cudaPitchedPtr output, 34 | int3 data_sz, 35 | int Ncomp); 36 | CUDAIMAGE::Pointer CombineImageComponents(std::vector img); 37 | 38 | 39 | 40 | 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/DRTAMAS_utilities_cp.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMAS_UTILITIES_CP_h 2 | #define _DRTAMAS_UTILITIES_CP_h 3 | 4 | 5 | 6 | #include "defines.h" 7 | 8 | #include "DRTAMAS.h" 9 | 10 | 11 | DTMatrixImageType::Pointer LogTensorImage(DTMatrixImageType::Pointer dt_img); 12 | 13 | 14 | DTMatrixImageType::Pointer ExpTensorImage(DTMatrixImageType::Pointer dt_img); 15 | 16 | 17 | InternalMatrixType InterpolateAt(DTMatrixImageType::Pointer img, DTMatrixImageType::PointType pt); 18 | 19 | 20 | vnl_matrix_fixed ComputeRotationFromAffine(vnl_matrix_fixed matrix); 21 | 22 | 23 | DTMatrixImageType::Pointer ReadAndOrientTensor(std::string fname); 24 | void OrientAndWriteTensor(DTMatrixImageType::Pointer tens,std::string nm); 25 | 26 | 27 | DTMatrixImageType::Pointer TransformAndWriteAffineImage(DTMatrixImageType::Pointer moving_tensor,DRTAMAS::AffineTransformType::Pointer my_affine_trans,DTMatrixImageType::Pointer fixed_tensor, std::string output_nii_name); 28 | void TransformAndWriteDiffeoImage(DTMatrixImageType::Pointer moving_tensor,DisplacementFieldType::Pointer disp_field,DTMatrixImageType::Pointer fixed_tensor, std::string output_nii_name); 29 | 30 | vnl_matrix_fixed ComputeJacobian(DisplacementFieldType::Pointer field,DisplacementFieldType::IndexType ind3 ); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/compute_metric_dev.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPUTEMETRICDEV_H 2 | #define _COMPUTEMETRICDEV_H 3 | 4 | #include "cuda_image.h" 5 | 6 | 7 | 8 | 9 | 10 | float ComputeMetric_DEV(const CUDAIMAGE::Pointer fixed_img, const CUDAIMAGE::Pointer moving_img, 11 | const CUDAIMAGE::Pointer def_FINV, const CUDAIMAGE::Pointer def_MINV , 12 | CUDAIMAGE::Pointer &updateFieldF, CUDAIMAGE::Pointer &updateFieldM, 13 | bool to); 14 | 15 | 16 | 17 | 18 | void ComputeMetric_DEV_cuda(cudaPitchedPtr fixed_img, cudaPitchedPtr moving_img, 19 | int3 data_sz, float3 data_spc, 20 | float d00,float d01,float d02,float d10,float d11,float d12,float d20,float d21,float d22, 21 | cudaPitchedPtr def_FINV, cudaPitchedPtr def_MINV, 22 | cudaPitchedPtr updateFieldF, cudaPitchedPtr updateFieldM, 23 | float &metric_value,bool to 24 | ); 25 | 26 | 27 | void ComputeDeviatoricTensor_cuda(cudaPitchedPtr img, int3 data_sz); 28 | 29 | CUDAIMAGE::Pointer ComputeDeviatoricTensorImg(CUDAIMAGE::Pointer img); 30 | 31 | 32 | 33 | float ComputeMetric_DEV_ONLY(const CUDAIMAGE::Pointer fixed_img, const CUDAIMAGE::Pointer moving_img); 34 | 35 | void ComputeMetric_DEV_ONLY_cuda(cudaPitchedPtr fixed_img, cudaPitchedPtr moving_img, 36 | int3 data_sz, 37 | float &metric_value); 38 | 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/drtamas_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef _DRTAMASSTRUCTS_H 2 | #define _DRTAMASSTRUCTS_H 3 | 4 | 5 | #include "defines.h" 6 | #include "cuda_image.h" 7 | 8 | #include "TORTOISE.h" 9 | 10 | 11 | enum DRTAMASMetricEnumeration 12 | { 13 | DTDEV = 0, 14 | DTTR =1, 15 | DTCC=2, 16 | DTIllegalMetric = 3 17 | }; 18 | 19 | class DRTAMASMetric 20 | { 21 | public: 22 | 23 | void SetMetricType(DRTAMASMetricEnumeration type) 24 | { 25 | MetricType=type; 26 | if(type==DRTAMASMetricEnumeration::DTCC) 27 | metric_name="CC"; 28 | if(type==DRTAMASMetricEnumeration::DTDEV) 29 | metric_name="DEV"; 30 | if(type==DRTAMASMetricEnumeration::DTTR) 31 | metric_name="TR"; 32 | } 33 | 34 | 35 | CUDAIMAGE::Pointer fixed_img{nullptr}; 36 | CUDAIMAGE::Pointer moving_img{nullptr}; 37 | 38 | float weight{1}; 39 | float param{5}; 40 | bool to{1}; 41 | 42 | std::string metric_name; 43 | DRTAMASMetricEnumeration MetricType; 44 | }; 45 | 46 | 47 | 48 | struct DRTAMASStageSettings 49 | { 50 | int niter{100}; 51 | float img_smoothing_std{0}; 52 | int downsample_factor{1}; 53 | 54 | 55 | CUDAIMAGE::Pointer init_finv{nullptr}; 56 | CUDAIMAGE::Pointer init_minv{nullptr}; 57 | CUDAIMAGE::Pointer output_finv{nullptr}; 58 | CUDAIMAGE::Pointer output_minv{nullptr}; 59 | using RigidTransformType=TORTOISE::RigidTransformType; 60 | 61 | RigidTransformType::Pointer rigid_trans{nullptr}; 62 | 63 | std::vector metrics; 64 | 65 | float learning_rate{0.25}; 66 | float update_gaussian_sigma{3}; 67 | float total_gaussian_sigma{0}; 68 | 69 | }; 70 | 71 | 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/run_drtamas_stage.h: -------------------------------------------------------------------------------- 1 | #ifndef _RUNDRTAMASSTAGE_H 2 | #define _RUNDRTAMASSTAGE_H 3 | 4 | #include "drtamas_structs.h" 5 | 6 | #include "DRTAMAS_Diffeo.h" 7 | #include "TORTOISE.h" 8 | 9 | #ifdef USECUDA 10 | #include "cuda_image.h" 11 | #endif 12 | 13 | #include "defines.h" 14 | #include "itkTimeProbe.h" 15 | 16 | class DRTAMASStage 17 | { 18 | public: 19 | 20 | using CurrentFieldType = DRTAMAS_Diffeo::CurrentFieldType; 21 | using CurrentImageType = DRTAMAS_Diffeo::CurrentImageType; 22 | 23 | DRTAMASStage(){}; 24 | ~DRTAMASStage(){}; 25 | 26 | DRTAMASStage(DRTAMASStageSettings *my_settings) 27 | { 28 | settings=my_settings; 29 | this->def_FINV= settings->init_finv; 30 | this->def_MINV= settings->init_minv; 31 | 32 | float tot_weight=0; 33 | for(int m=0;mmetrics.size();m++) 34 | tot_weight+=settings->metrics[m].weight; 35 | for(int m=0;mmetrics.size();m++) 36 | settings->metrics[m].weight/=tot_weight; 37 | 38 | this->stream= &(std::cout); 39 | 40 | } 41 | 42 | 43 | 44 | 45 | void RunDRTAMASStage(); 46 | void PreprocessImagesAndFields(); 47 | 48 | protected: 49 | void CreateVirtualImage(); 50 | 51 | 52 | DRTAMASStageSettings *settings; 53 | CurrentImageType::Pointer virtual_img{nullptr}; 54 | 55 | itk::TimeProbe m_clock; 56 | std::ostream *stream; 57 | 58 | private: 59 | 60 | 61 | CurrentFieldType::Pointer def_F{nullptr}; 62 | CurrentFieldType::Pointer def_M{nullptr}; 63 | CurrentFieldType::Pointer def_FINV{nullptr}; 64 | CurrentFieldType::Pointer def_MINV{nullptr}; 65 | 66 | 67 | }; 68 | 69 | 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/tools/DRTAMAS/run_drtamas_stage_rigid.h: -------------------------------------------------------------------------------- 1 | #ifndef _RUNDRTAMASStageRigid_H 2 | #define _RUNDRTAMASStageRigid_H 3 | 4 | #include "drtamas_structs.h" 5 | 6 | #include "DRTAMASRigid_Bulk.h" 7 | #include "TORTOISE.h" 8 | 9 | #ifdef USECUDA 10 | #include "cuda_image.h" 11 | #endif 12 | 13 | #include "defines.h" 14 | #include "itkTimeProbe.h" 15 | 16 | class DRTAMASStageRigid 17 | { 18 | public: 19 | 20 | using CurrentImageType=CUDAIMAGE; 21 | using RigidTransformType=TORTOISE::RigidTransformType; 22 | 23 | 24 | DRTAMASStageRigid(){}; 25 | ~DRTAMASStageRigid(){}; 26 | 27 | DRTAMASStageRigid(DRTAMASStageSettings *my_settings) 28 | { 29 | settings=my_settings; 30 | 31 | float tot_weight=0; 32 | for(int m=0;mmetrics.size();m++) 33 | tot_weight+=settings->metrics[m].weight; 34 | for(int m=0;mmetrics.size();m++) 35 | settings->metrics[m].weight/=tot_weight; 36 | 37 | this->stream= &(std::cout); 38 | 39 | } 40 | 41 | 42 | 43 | 44 | void RunDRTAMASStageRigid(); 45 | void PreprocessImagesAndFields(); 46 | 47 | 48 | private: 49 | std::vector ComputeMetrics(CUDAIMAGE::Pointer fixed_img, std::vector moving_img_vec, RigidTransformType::Pointer rigid_trans); 50 | 51 | std::vector< std::pair > BracketGrad(CUDAIMAGE::Pointer fixed_img, std::vector moving_img_vec,RigidTransformType::ParametersType params, vnl_vector grad, int mode); 52 | double GoldenSearch(CUDAIMAGE::Pointer fixed_img, std::vector moving_img_vec,RigidTransformType::ParametersType params, std::vector< std::pair > &x_f_pairs, vnl_vector grad, int mode); 53 | 54 | double ComputeMetricRigid_TR(CUDAIMAGE::Pointer fixed_tensor, CUDAIMAGE::Pointer moving_tensor); 55 | double ComputeMetricRigid_DEV(CUDAIMAGE::Pointer fixed_tensor, CUDAIMAGE::Pointer moving_tensor); 56 | 57 | protected: 58 | void CreateVirtualImage(); 59 | 60 | 61 | DRTAMASStageSettings *settings; 62 | CurrentImageType::Pointer virtual_img{nullptr}; 63 | 64 | itk::TimeProbe m_clock; 65 | std::ostream *stream; 66 | 67 | double class_metric_value{0}; 68 | 69 | 70 | 71 | }; 72 | 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/tools/DWIDenoise/dwi_denoise.cxx: -------------------------------------------------------------------------------- 1 | #include "dwi_denoise.h" 2 | 3 | 4 | #include "defines.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | if(argc<3) 9 | { 10 | std::cout<< "Usage: DwiDenoise input_image name_of_output_dwi name_of_output_noise_img denoising_kernel_diameter(int. optional)" <=5) 16 | desired_extent = atoi(argv[4]); 17 | 18 | 19 | ImageType4D::Pointer img4D= readImageD(argv[1]); 20 | 21 | 22 | ImageType3D::Pointer noise_img=nullptr; 23 | double noise_mean; 24 | ImageType4D::Pointer output_img = DWIDenoise(img4D,noise_img,noise_mean,true, desired_extent); 25 | std::cout<< "Average noise std: " <(output_img,argv[2]); 29 | writeImageD(noise_img,argv[3]); 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/tools/EstimateExperimentalDeviationScalar/estimate_experimental_deviation_scalar_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _EstimateExperimentalDeviationScalar_h 2 | #define _EstimateExperimentalDeviationScalar_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class EstimateExperimentalDeviationScalar_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | EstimateExperimentalDeviationScalar_PARSER( int argc , char * argv[] ); 15 | ~EstimateExperimentalDeviationScalar_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getMaskImageName(); 19 | double getBValCutoff(); 20 | std::string getModality(); 21 | 22 | 23 | 24 | private: 25 | void CreateParserandFillText(int argc , char * argv[] ); 26 | void InitializeCommandLineOptions(); 27 | bool checkIfAllRequiredParamsAreEntered(); 28 | }; 29 | 30 | 31 | 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/tools/EstimateExperimentalDeviationScalar/vnl_matrix_inverse.h: -------------------------------------------------------------------------------- 1 | // This is core/vnl/algo/vnl_matrix_inverse.h 2 | #ifndef vnl_matrix_inverse_h_ 3 | #define vnl_matrix_inverse_h_ 4 | //: 5 | // \file 6 | // \brief Calculates inverse of a matrix (wrapper around vnl_svd) 7 | // \author Andrew W. Fitzgibbon, Oxford RRG 8 | // \date 22 Nov 96 9 | // 10 | // \verbatim 11 | // Modifications 12 | // dac (Manchester) 28/03/2001: tidied up documentation 13 | // \endverbatim 14 | 15 | #include 16 | #include 17 | 18 | //: Calculates inverse of a matrix (wrapper around vnl_svd) 19 | // vnl_matrix_inverse is a wrapper around vnl_svd that allows 20 | // you to write 21 | // \code 22 | // x = vnl_matrix_inverse(A) * b; 23 | // \endcode 24 | // This is exactly equivalent to 25 | // \code 26 | // x = vnl_svd(A).solve(b); 27 | // \endcode 28 | // but is arguably clearer, and also allows for the vnl_matrix_inverse 29 | // class to be changed to use vnl_qr, say. 30 | 31 | template 32 | struct vnl_matrix_inverse : public vnl_svd 33 | { 34 | vnl_matrix_inverse(vnl_matrix const & M): vnl_svd(M) { } 35 | ~vnl_matrix_inverse() override = default; 36 | 37 | vnl_matrix as_matrix() const { return this->inverse(); } 38 | 39 | #if ! VXL_USE_HISTORICAL_IMPLICIT_CONVERSIONS 40 | explicit operator vnl_matrix() const { return this->inverse(); } 41 | #else 42 | #if VXL_LEGACY_FUTURE_REMOVE 43 | VXL_DEPRECATED_MSG("Implicit cast conversion is dangerous.\nUSE: .as_matrix() or .as_ref() member function for clarity.") 44 | #endif 45 | operator vnl_matrix() const { return this->inverse(); } 46 | #endif 47 | }; 48 | 49 | template 50 | inline 51 | vnl_vector operator*(vnl_matrix_inverse const & i, 52 | vnl_vector const & B) 53 | { 54 | return i.solve(B); 55 | } 56 | 57 | template 58 | inline 59 | vnl_matrix operator*(vnl_matrix_inverse const & i, 60 | vnl_matrix const & B) 61 | { 62 | return i.solve(B); 63 | } 64 | 65 | #endif // vnl_matrix_inverse_h_ 66 | 67 | -------------------------------------------------------------------------------- /src/tools/EstimateMAPMRI/MAPMRIModel.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAPMRIModel_H 2 | #define _MAPMRIModel_H 3 | 4 | 5 | #include "DiffusionModel.h" 6 | 7 | 8 | using namespace Eigen; 9 | 10 | class MAPMRIModel: public DiffusionModel 11 | { 12 | 13 | public: 14 | using EVecType=vnl_matrix_fixed< double, 3, 3 >; 15 | using EValType=itk::Vector ; 16 | using EVecImageType=itk::Image; 17 | using EValImageType=itk::Image; 18 | 19 | using Superclass=DiffusionModel; 20 | using OutputImageType= Superclass::OutputImageType; 21 | 22 | 23 | public: 24 | void SetSmallDelta(float sd){small_delta=sd;} 25 | void SetBigDelta(float bd){big_delta=bd;} 26 | void SetDTImg(DTImageType::Pointer di){dt_image=di;} 27 | void SetMAPMRIDegree(int md){MAP_DEGREE=md;} 28 | void SetDTIIndices(std::vector di){DT_indices=di;} 29 | 30 | EValImageType::Pointer getEvalImage(){return eval_image;} 31 | void ComputeEigenImages(); 32 | 33 | 34 | void PerformFitting(); 35 | ImageType3D::Pointer SynthesizeDWI(vnl_vector bmat_vec); 36 | 37 | private: 38 | 39 | vnl_matrix bmat2q(vnl_matrix cBMatrix , std::vector all_indices,bool qspace=true); 40 | MAPType FitMAPMRI(std::vector &signal, float A0val, int order, EValType uvec, vnl_matrix &qxyz,double tdiff, double reg_weight,vnl_vector weights_vector); 41 | MatrixXd mk_ashore_basis(int order, vnl_vector & uvec,vnl_matrix &qxyz, bool qsp); 42 | vnl_matrix shore_3d_reconstruction_domain(int order, vnl_vector& uvec); 43 | MatrixXd shore_car_phi(int nn, double uu, vnl_matrix qarr); 44 | vnl_matrix hermiteh(int nn, vnl_matrix xx); 45 | 46 | 47 | private: 48 | float small_delta{0}, big_delta{0}; 49 | 50 | DTImageType::Pointer dt_image{nullptr}; 51 | std::vector DT_indices; 52 | 53 | EValImageType::Pointer eval_image{nullptr}; 54 | EVecImageType::Pointer evec_image{nullptr}; 55 | 56 | int MAP_DEGREE; 57 | 58 | 59 | }; 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/tools/EstimateMAPMRI/bmat2q.h: -------------------------------------------------------------------------------- 1 | #ifndef _BMAT2Q_H 2 | #define _BMAT2Q_H 3 | 4 | 5 | #include "defines.h" 6 | #include "vnl/algo/vnl_symmetric_eigensystem.h" 7 | 8 | 9 | #define MPI 3.141592653589793 10 | 11 | 12 | vnl_matrix bmat2q(vnl_matrix BMatrix,std::vector all_indices,double small_delta,double big_delta,bool qspace=true) 13 | { 14 | vnl_matrix qmat; 15 | qmat.set_size(3,all_indices.size()); 16 | 17 | double delta= big_delta-small_delta/3.; 18 | 19 | for(int v=0;v bmat_vec= BMatrix.get_row(vol); 23 | 24 | vnl_matrix bmat(3,3); 25 | bmat(0,0) = bmat_vec[0]; bmat(0,1) = bmat_vec[1]/2; bmat(0,2) = bmat_vec[2]/2; 26 | bmat(1,0) = bmat_vec[1]/2; bmat(1,1) = bmat_vec[3]; bmat(1,2) = bmat_vec[4]/2; 27 | bmat(2,0) = bmat_vec[2]/2; bmat(2,1) = bmat_vec[4]/2; bmat(2,2) = bmat_vec[5]; 28 | 29 | bmat= bmat / 1000.; 30 | 31 | vnl_symmetric_eigensystem eig(bmat); 32 | if(eig.D(2,2)<0) 33 | eig.D(2,2)=0; 34 | 35 | double bval=eig.D(2,2); 36 | vnl_vector bvec= eig.get_eigenvector(2); 37 | 38 | double qq; 39 | if(qspace) 40 | qq=sqrt(bval/delta)/(2*MPI) ; 41 | else 42 | { 43 | qq=bmat_vec[0] + bmat_vec[3] + bmat_vec[5]; 44 | } 45 | 46 | vnl_vector qvec= qq * bvec; 47 | qmat.set_column(v,qvec); 48 | } 49 | 50 | return qmat; 51 | 52 | } 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/tools/EstimateMAPMRI/compute_eigen_images.h: -------------------------------------------------------------------------------- 1 | #ifndef _ComputeEigenImages_H 2 | #define _ComputeEigenImages_H 3 | 4 | #include "defines.h" 5 | #include "itkImageRegionIteratorWithIndex.h" 6 | #include "vnl/algo/vnl_symmetric_eigensystem.h" 7 | 8 | 9 | EVecImageType::Pointer ComputeEigenImages(DTImageType::Pointer dt_image, EValImageType::Pointer & eval_image) 10 | { 11 | EVecImageType::Pointer evec_image = EVecImageType::New(); 12 | evec_image->SetRegions(dt_image->GetLargestPossibleRegion()); 13 | evec_image->Allocate(); 14 | evec_image->SetOrigin(dt_image->GetOrigin()); 15 | evec_image->SetDirection(dt_image->GetDirection()); 16 | evec_image->SetSpacing(dt_image->GetSpacing()); 17 | EVecType zerovec; 18 | zerovec.set_identity(); 19 | evec_image->FillBuffer(zerovec); 20 | 21 | 22 | 23 | eval_image = EValImageType::New(); 24 | eval_image->SetRegions(dt_image->GetLargestPossibleRegion()); 25 | eval_image->Allocate(); 26 | eval_image->SetOrigin(dt_image->GetOrigin()); 27 | eval_image->SetDirection(dt_image->GetDirection()); 28 | eval_image->SetSpacing(dt_image->GetSpacing()); 29 | 30 | EValType zeroval; zeroval.Fill(0); 31 | 32 | itk::ImageRegionIteratorWithIndex it(evec_image,evec_image->GetLargestPossibleRegion()); 33 | while(!it.IsAtEnd()) 34 | { 35 | EVecImageType::IndexType ind=it.GetIndex(); 36 | DTType vec= dt_image->GetPixel(ind); 37 | 38 | if(vec[0]+ vec[3]+ vec[5] !=0) 39 | { 40 | 41 | 42 | EVecType tensor; 43 | tensor(0,0)= vec[0]; tensor(0,1)= vec[1]; tensor(0,2)= vec[2]; 44 | tensor(1,0)= vec[1]; tensor(1,1)= vec[3]; tensor(1,2)= vec[4]; 45 | tensor(2,0)= vec[2]; tensor(2,1)= vec[4]; tensor(2,2)= vec[5]; 46 | 47 | 48 | vnl_symmetric_eigensystem eig(tensor); 49 | 50 | EVecType evec; 51 | evec.set_column(0, eig.V.get_column(2)); 52 | evec.set_column(1, eig.V.get_column(1)); 53 | evec.set_column(2, eig.V.get_column(0)); 54 | 55 | double mdet= vnl_determinant( evec); 56 | if(mdet<0) 57 | { 58 | evec.set_column(2, -1.* evec.get_column(2)); 59 | } 60 | 61 | evec=evec.transpose(); 62 | 63 | EValType eval; 64 | 65 | if(eig.D(0,0)< 0) 66 | eig.D(0,0)=0.000000000001; 67 | if(eig.D(1,1)< 0) 68 | eig.D(1,1)=0.000000000001; 69 | if(eig.D(2,2)< 0) 70 | eig.D(2,2)=0.000000000001; 71 | 72 | eval[2]= eig.D(0,0); 73 | eval[1]= eig.D(1,1); 74 | eval[0]= eig.D(2,2); 75 | 76 | it.Set(evec); 77 | eval_image->SetPixel(ind,eval); 78 | } 79 | else 80 | { 81 | eval_image->SetPixel(ind,zeroval); 82 | evec_image->SetPixel(ind,zerovec); 83 | } 84 | ++it; 85 | } 86 | 87 | return evec_image; 88 | } 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | #endif 97 | 98 | -------------------------------------------------------------------------------- /src/tools/EstimateMAPMRI/estimate_mapmri_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Estimate_MAPMRI_PARSER_h 2 | #define _Estimate_MAPMRI_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class EstimateMAPMRI_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | EstimateMAPMRI_PARSER( int argc , char * argv[] ); 15 | ~EstimateMAPMRI_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getMaskImageName(); 19 | double getBValCutoff(); 20 | bool getUseNoise(); 21 | bool getUseVoxelwiseBmat(); 22 | std::string getInclusionImg(); 23 | 24 | std::string getDTIImageName(); 25 | std::string getA0ImageName(); 26 | int getMAPMRIOrder(); 27 | float getSmallDelta(); 28 | float getBigDelta(); 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | private: 37 | void CreateParserandFillText(int argc , char * argv[] ); 38 | void InitializeCommandLineOptions(); 39 | bool checkIfAllRequiredParamsAreEntered(); 40 | }; 41 | 42 | 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/tools/EstimateTensor/estimate_tensor_wlls.h: -------------------------------------------------------------------------------- 1 | #ifndef _ESTIMATETENSORWLLSSUB_H 2 | #define _ESTIMATETENSORWLLSSUB_H 3 | 4 | 5 | #include "defines.h" 6 | 7 | DTImageType::Pointer EstimateTensorWLLS_sub_nomm(std::vector dwis, vnl_matrix Bmatrix,std::vector &DT_indices, ImageType3D::Pointer & A0_image,ImageType3D::Pointer mask_image,std::vector inclusion_img); 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/tools/EstimateTensor/estimate_tensor_wlls_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Estimate_Tensor_WLLS_PARSER_h 2 | #define _Estimate_Tensor_WLLS_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class EstimateTensorWLLS_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | EstimateTensorWLLS_PARSER( int argc , char * argv[] ); 15 | ~EstimateTensorWLLS_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getMaskImageName(); 19 | double getBValCutoff(); 20 | bool getUseNoise(); 21 | bool getUseVoxelwiseBmat(); 22 | std::string getInclusionImg(); 23 | std::string getRegressionMode(); 24 | float getFreeWaterDiffusivity(); 25 | 26 | float getNT2C1MaxDiff(); 27 | float getNT2C2MinDiff(); 28 | 29 | 30 | bool getWriteCSImg(); 31 | 32 | 33 | private: 34 | void CreateParserandFillText(int argc , char * argv[] ); 35 | void InitializeCommandLineOptions(); 36 | bool checkIfAllRequiredParamsAreEntered(); 37 | }; 38 | 39 | 40 | 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/tools/EstimateTensor/synthesize_dwi_from_tensor.h: -------------------------------------------------------------------------------- 1 | #ifndef _SynthesizeDWIFromTensor_H 2 | #define _SynthesizeDWIFromTensor_H 3 | 4 | 5 | #include "defines.h" 6 | #include "itkImageRegionIteratorWithIndex.h" 7 | 8 | #include 9 | 10 | 11 | 12 | 13 | 14 | ImageType3D::Pointer SynthesizeDWIFromTensor(DTImageType::Pointer dt_image, ImageType3D::Pointer A0_image, vnl_vector bmatrix_vec ) 15 | { 16 | ImageType3D::Pointer synth_image = ImageType3D::New(); 17 | synth_image->SetRegions(A0_image->GetLargestPossibleRegion()); 18 | synth_image->Allocate(); 19 | synth_image->SetOrigin(A0_image->GetOrigin()); 20 | synth_image->SetDirection(A0_image->GetDirection()); 21 | 22 | synth_image->SetSpacing(A0_image->GetSpacing()); 23 | synth_image->FillBuffer(0.); 24 | 25 | 26 | 27 | itk::ImageRegionIteratorWithIndex it(synth_image,synth_image->GetLargestPossibleRegion()); 28 | while(!it.IsAtEnd()) 29 | { 30 | ImageType3D::IndexType ind=it.GetIndex(); 31 | DTType tensor= dt_image->GetPixel(ind); 32 | double exp_term=0; 33 | for(int i=0;i<6;i++) 34 | exp_term += tensor[i] * bmatrix_vec[i]; 35 | 36 | 37 | if(exp_term < 0) 38 | exp_term=0; 39 | 40 | float A0val= A0_image->GetPixel(ind); 41 | 42 | float signal = A0val * exp(-exp_term); 43 | if(!isnan(signal) && isfinite(signal)) 44 | it.Set(signal); 45 | ++it; 46 | } 47 | 48 | return synth_image; 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/tools/ExtractDWISubset/extract_dwi_subset_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Extract_DWI_Subset_PARSER_h 2 | #define _Extract_DWI_Subset_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class Extract_DWI_Subset_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | Extract_DWI_Subset_PARSER( int argc , char * argv[] ); 15 | ~Extract_DWI_Subset_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getOutputImageName(); 19 | std::string getBvalsString(); 20 | std::string getVolIdsString(); 21 | 22 | private: 23 | void CreateParserandFillText(int argc , char * argv[] ); 24 | void InitializeCommandLineOptions(); 25 | bool checkIfAllRequiredParamsAreEntered(); 26 | }; 27 | 28 | 29 | 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/tools/ExtractImage/extract_component_from_itk_vector_image.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include "extract_image_parser.h" 3 | 4 | 5 | #include "itkDisplacementFieldTransform.h" 6 | 7 | #include "itkImageRegionIteratorWithIndex.h" 8 | #include "itkImageFileWriter.h" 9 | #include "itkImageFileReader.h" 10 | 11 | int main(int argc, char * argv[]) 12 | { 13 | if(argc==1) 14 | { 15 | std::cout<<"Usage: ExtractComponentFromDisplacementField -i input_vector_image -v component_id "<getOutputImageName()=="") 24 | { 25 | std::string nm=parser->getInputImageName(); 26 | char buf[2000]; 27 | sprintf(buf,"_V%.3d.nii",parser->getVolId()); 28 | if(nm.find(".nii.gz")!=std::string::npos) 29 | oname=nm.substr(0,nm.find(".nii.gz")) + std::string(buf); 30 | else 31 | oname=nm.substr(0,nm.find(".nii")) + std::string(buf); 32 | } 33 | else 34 | { 35 | oname=parser->getOutputImageName(); 36 | } 37 | 38 | 39 | typedef itk::DisplacementFieldTransform DisplacementFieldTransformType; 40 | typedef DisplacementFieldTransformType::DisplacementFieldType DisplacementFieldType; 41 | 42 | 43 | typedef itk::ImageFileReader RdType; 44 | RdType::Pointer rd= RdType::New(); 45 | rd->SetFileName(parser->getInputImageName()); 46 | rd->Update(); 47 | DisplacementFieldType::Pointer field= rd->GetOutput(); 48 | 49 | 50 | typedef itk::Image ImageType3D; 51 | ImageType3D::Pointer output_img = ImageType3D::New(); 52 | output_img->SetRegions(field->GetLargestPossibleRegion()); 53 | output_img->Allocate(); 54 | output_img->SetDirection(field->GetDirection()); 55 | output_img->SetOrigin(field->GetOrigin()); 56 | output_img->SetSpacing(field->GetSpacing()); 57 | 58 | int vol_id = parser->getVolId(); 59 | 60 | itk::ImageRegionIteratorWithIndex it(output_img,output_img->GetLargestPossibleRegion()); 61 | it.GoToBegin(); 62 | while(!it.IsAtEnd()) 63 | { 64 | ImageType3D::IndexType ind3 = it.GetIndex(); 65 | DisplacementFieldType::PixelType vec= field->GetPixel(ind3); 66 | float val = vec[vol_id]; 67 | 68 | it.Set(val); 69 | ++it; 70 | } 71 | 72 | typedef itk::ImageFileWriter WrType; 73 | WrType::Pointer wr=WrType::New(); 74 | wr->SetInput(output_img); 75 | wr->SetFileName(oname); 76 | wr->Update(); 77 | 78 | 79 | 80 | return EXIT_SUCCESS; 81 | } 82 | -------------------------------------------------------------------------------- /src/tools/ExtractImage/extract_image.cxx: -------------------------------------------------------------------------------- 1 | #include "../utilities/read_3Dvolume_from_4D.h" 2 | #include "extract_image_parser.h" 3 | #include "defines.h" 4 | 5 | int main(int argc, char * argv[]) 6 | { 7 | Extract_Image_PARSER *parser = new Extract_Image_PARSER(argc,argv); 8 | 9 | std::string oname; 10 | if(parser->getOutputImageName()=="") 11 | { 12 | std::string nm=parser->getInputImageName(); 13 | char buf[2000]; 14 | sprintf(buf,"_V%.3d.nii",parser->getVolId()); 15 | oname=nm.substr(0,nm.find(".nii")) + std::string(buf); 16 | } 17 | else 18 | { 19 | oname=parser->getOutputImageName(); 20 | } 21 | 22 | ImageType3D::Pointer img = read_3D_volume_from_4D(parser->getInputImageName(),parser->getVolId()); 23 | 24 | writeImageD(img,oname); 25 | 26 | return EXIT_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /src/tools/ExtractImage/extract_image_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Extract_Image_PARSER_h 2 | #define _Extract_Image_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class Extract_Image_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | Extract_Image_PARSER( int argc , char * argv[] ); 15 | ~Extract_Image_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getOutputImageName(); 19 | int getVolId(); 20 | 21 | private: 22 | void CreateParserandFillText(int argc , char * argv[] ); 23 | void InitializeCommandLineOptions(); 24 | bool checkIfAllRequiredParamsAreEntered(); 25 | }; 26 | 27 | 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/Fit_nifti_iso.h: -------------------------------------------------------------------------------- 1 | #ifndef _FIT_NIFTI_ISO_H 2 | #define _FIT_NIFTI_ISO_H 3 | #include "defines.h" 4 | 5 | 6 | #include "gradcal.h" 7 | #include "fit_nifti_iso_parser.h" 8 | #include "init_iso_gw.h" 9 | #include "iso_gw.h" 10 | #include "erodeMask.h" 11 | 12 | 13 | typedef ImageType4D DTImageType4D; 14 | 15 | class FITNIFTIISO{ 16 | 17 | void process(); 18 | public: 19 | FITNIFTIISO(int argc, char *argv[]); 20 | ~FITNIFTIISO(); 21 | void setInputList(std::string listname ); 22 | 23 | private: 24 | ImageType3D::Pointer b0_image; 25 | MaskImageType::Pointer maskImage; 26 | ImageType4D::Pointer my_image; 27 | 28 | std::string mask_filename; 29 | std::string output_filename; 30 | std::string gradFn; 31 | std::string scannerType; 32 | std::string grad_normalization; 33 | std::string coef_filename; 34 | std::string nii_name; 35 | 36 | bool compute_normalization = false; 37 | bool GE_type = false; 38 | bool computeCalibration = 0; 39 | bool computeGains = 0; 40 | 41 | double phantomD = 0; 42 | double threshold = 0.01; 43 | double R0 = 250; 44 | 45 | int rdfit = 0; 46 | int npts = 0; 47 | int erode_factor = 0; 48 | int init_flag = 0; 49 | int nVols =0; 50 | int nx = 0; 51 | int ny = 0; 52 | int nz = 0; 53 | int na = 0; 54 | 55 | int locx = 0; 56 | int locy = 0; 57 | int locz = 0; 58 | GRADCAL *grads; 59 | GradCoef gradCoefOutput; 60 | basisFuntions basis; 61 | 62 | std::string list_inputs; 63 | 64 | vnl_matrix Bmatrix; 65 | vnl_matrix_fixed smat; 66 | vnl_matrix inv_smat; 67 | vnl_vector aa; 68 | vnl_vectorfita; 69 | std::vectornodif; 70 | int nnodif = 0; 71 | 72 | /* Init Functions */ 73 | void set4Dimage(std::string fn); 74 | void setb0Image(int volid); 75 | void setMaskImage(double threshold, int erodeFactor); 76 | void setGradientCalibrationStructure(std::string fn); 77 | void setNormalizingFlag(); 78 | void setVectorOfFitting(); 79 | void setPermitFlagsforFitting(); 80 | 81 | /* funtions to process()*/ 82 | void normalize_image_nodif(std::vector a, int b); 83 | void normalize_image_b0(); 84 | void PerformNonlinearityMisCalibrationFitting(); 85 | void normalize_gradient(); 86 | void PerformGainFitting(); 87 | void write_gradcal(std::string fn); 88 | 89 | void writeOutputs(); 90 | 91 | 92 | double regression_at_point(ImageType3D::IndexType ind3); 93 | 94 | }; 95 | 96 | int IsoGW(int m, int n, double *p, double *deviates, double **derivs, void *vars); 97 | int IsoGW1(int m, int n, double *p, double *deviates, double **derivs, void *vars); 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/erodeMask.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERODEMASK_H 2 | #define _ERODEMASK_H 3 | 4 | 5 | #include "itkImageRegionIteratorWithIndex.h" 6 | #include "itkRescaleIntensityImageFilter.h" 7 | 8 | #include "itkGrayscaleErodeImageFilter.h" 9 | #include "itkBinaryErodeImageFilter.h" 10 | 11 | #include "itkFlatStructuringElement.h" 12 | #include "itkImageDuplicator.h" 13 | #include "defines.h" 14 | 15 | 16 | typedef unsigned char MaskPixelType; 17 | typedef itk::Image MaskImageType; 18 | 19 | 20 | 21 | MaskImageType::Pointer computeMask(ImageType3D::Pointer b0_image, 22 | float threshold); 23 | 24 | MaskImageType::Pointer erodeMask(MaskImageType::Pointer mask_image); 25 | 26 | MaskImageType::Pointer compute_erode_Mask(ImageType3D::Pointer b0_image, 27 | int erodeFactor , float threshold ); 28 | 29 | 30 | /* 31 | 32 | int read_coef_file(std::string gradtxtfile){ 33 | std::ifstream inFile(gradtxtfile); 34 | if (!inFile) 35 | { 36 | std::cerr << "File " << gradtxtfile << " not found." << std::endl; 37 | return 0; 38 | } 39 | std::vector< std::vector> x_key (1,std::vector (2,0)); 40 | std::vector< std::vector> y_key (1,std::vector (2,0)); 41 | std::vector< std::vector> z_key (1,std::vector (2,0)); 42 | 43 | std::string line; 44 | char curr_comp='z'; 45 | while (std::getline(inFile, line)) 46 | { 47 | if (line.empty()) 48 | continue; 49 | 50 | if(line =="z") 51 | continue; 52 | 53 | if(line=="x") 54 | { 55 | curr_comp='x'; 56 | continue; 57 | } 58 | 59 | if(line=="y") 60 | { 61 | curr_comp='y'; 62 | continue; 63 | } 64 | 65 | 66 | std::istringstream iss(line); 67 | int l, m; 68 | double coeff; 69 | 70 | iss >> l >> m >> coeff; 71 | std::cout< 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | 12 | class Fit_NIFTI_iso_parser : public itk::ants::CommandLineParser 13 | { 14 | public: 15 | Fit_NIFTI_iso_parser( int argc , char * argv[] ); 16 | ~Fit_NIFTI_iso_parser(); 17 | 18 | std::string getInputImageName(); 19 | std::string getMaskImageName(); 20 | std::string getOuputFilename(); 21 | 22 | std::string getGradCalName(); 23 | 24 | std::string getExtraInputs(); 25 | std::string getCoefFile(); 26 | 27 | std::string getScannerType(); 28 | 29 | std::string getGradient_normalization(); 30 | 31 | float getPhantomDiffusitivity(); 32 | 33 | int getErodeFactor(); 34 | double getThreshold(); 35 | double getDistance(); 36 | int getRadiusFit(); 37 | 38 | bool IsEstimate_gradient_calibration(); 39 | bool isGradient_normalization(); 40 | 41 | private: 42 | void CreateParserandFillText(int argc , char * argv[] ); 43 | void InitializeCommandLineOptions(); 44 | bool checkIfAllRequiredParamsAreEntered(); 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/gradcal.h: -------------------------------------------------------------------------------- 1 | #ifndef _GRADCAL_H 2 | #define _GRADCAL_H 3 | 4 | #include "iostream" 5 | #include 6 | #include 7 | #include "defines.h" 8 | #include "cmath" 9 | 10 | 11 | struct GradCoef{ 12 | std::vector gradX_coef; 13 | std::vectorXkeys; 14 | std::vector gradY_coef; 15 | std::vectorYkeys; 16 | std::vector gradZ_coef; 17 | std::vectorZkeys; 18 | float R0 = 250.; 19 | std::string gradType; 20 | 21 | }; 22 | 23 | 24 | class GRADCAL{ 25 | public: 26 | // 2 constructors 27 | GRADCAL(); 28 | GRADCAL(std::string fileName); 29 | 30 | 31 | // destructor 32 | ~GRADCAL(); 33 | 34 | 35 | 36 | void read_grad_file(std::string fileName); 37 | void write_ASB_format(GradCoef gc, std::string outFileName); 38 | 39 | std::vector get_X_key(){ 40 | 41 | return this->grads_cal.Xkeys; 42 | } 43 | std::vector get_Y_key(){ 44 | return this->grads_cal.Ykeys; 45 | } 46 | std::vector get_Z_key(){ 47 | return this->grads_cal.Zkeys; 48 | } 49 | std::vector get_X_coef(){ 50 | return this->grads_cal.gradX_coef; 51 | } 52 | std::vector get_Y_coef(){ 53 | return this->grads_cal.gradY_coef; 54 | } 55 | std::vector get_Z_coef(){ 56 | return this->grads_cal.gradZ_coef; 57 | } 58 | GradCoef get_struct(){ 59 | return this->grads_cal; 60 | } 61 | 62 | private: 63 | GradCoef grads_cal; 64 | std::string gradFilename; 65 | void read_Siemens_format(std::string fileName); 66 | void read_GE_format(std::string fileName); 67 | void read_ASB_format(std::string fileName); 68 | void init(); 69 | 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/init_iso_gw.h: -------------------------------------------------------------------------------- 1 | #ifndef _INIT_ISO_GW_H 2 | #define _INIT_ISO_GW_H 3 | 4 | #include "gradcal.h" 5 | 6 | 7 | #include "itkNiftiImageIO.h" 8 | #include "itkImportImageFilter.h" 9 | #include "itkImageMomentsCalculator.h" 10 | #include "itkImageDuplicator.h" 11 | #include "itkImageRegionIteratorWithIndex.h" 12 | 13 | 14 | typedef unsigned char MaskPixelType; 15 | typedef itk::Image MaskImageType; 16 | 17 | 18 | 19 | struct basisFuntions{ 20 | std::vector< vnl_matrix > xbasis; 21 | std::vector< vnl_matrix > ybasis; 22 | std::vector< vnl_matrix > zbasis; 23 | 24 | 25 | 26 | }; 27 | 28 | 29 | double plgndr(int ll, int mm, double x); 30 | float factorial(int n); 31 | 32 | double sphericalz(int ll, int mm, double phi,double zz, double theta ); 33 | 34 | // code for derivative wrt x,y,z 35 | double dshdx(char grad, int ll, int mml, double rr, double phi,double zz, double theta); 36 | double dshdx_X(int ll, int mml, double phi, double zz, double theta ); 37 | double dshdx_Y(int ll, int mml, double phi, double zz, double theta ); 38 | double dshdx_Z(int ll, int mml, double phi, double zz, double theta ); 39 | 40 | 41 | basisFuntions init_iso_gw(vnl_matrix smat, MaskImageType::Pointer maskedIm, GradCoef E); 42 | 43 | 44 | #endif 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/iso_gw.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _ISO_GW_CXX 2 | #define _ISO_GW_CXX 3 | 4 | 5 | #include "iso_gw.h" 6 | 7 | 8 | void multiplyArray(std::vector &a, double multiplier){ 9 | for (int i =0; i < a.size(); i++){ 10 | a[i] *= multiplier; 11 | } 12 | } 13 | void multiplyArray(vnl_vector &a, double multiplier){ 14 | for (int i =0; i < a.size(); i++){ 15 | a(i) *= multiplier; 16 | } 17 | } 18 | 19 | void expArray(std::vector &a, double exponent = 1){ 20 | for (int i =0; i < a.size(); i ++){ 21 | a[i] = std::exp(a[i]*exponent); 22 | } 23 | } 24 | 25 | void expArray(vnl_vector &a, double exponent = 1){ 26 | for (int i =0; i < a.size(); i ++){ 27 | // double d = a[i]; 28 | a(i) = std::exp(a(i)*exponent); 29 | } 30 | } 31 | 32 | void debugArray(vnl_vector &a, std::string c =""){ 33 | std::cout << c << std::endl; 34 | for (int i = 0; i < a.size(); i++){ 35 | std::cout << a[i] << "\t"; 36 | } 37 | std::cout << std::endl; 38 | } 39 | 40 | void debugArray(vnl_vector &a, std::string c =""){ 41 | std::cout << c << std::endl; 42 | for (int i = 0; i < a.size(); i++){ 43 | std::cout << a[i] << "\t"; 44 | } 45 | std::cout << std::endl; 46 | } 47 | 48 | 49 | 50 | void debugArray(std::vector a, std::string c =""){ 51 | std::cout << c << std::endl; 52 | for (int i = 0; i < a.size(); i++){ 53 | std::cout << a[i] << "\t"; 54 | } 55 | std::cout << std::endl; 56 | } 57 | 58 | void debug2DArray(vnl_matrix &a, std::string c =""){ 59 | std::cout << c << std::endl; 60 | for (int r = 0; r < a.rows(); r++){ 61 | for (int c = 0; c < a.cols(); c ++){ 62 | std::cout << a[r][c] << "\t"; 63 | 64 | } 65 | std::cout << std::endl; 66 | } 67 | std::cout << std::endl; 68 | } 69 | void debug2DArray(vnl_matrix_fixed &a, std::string c =""){ 70 | std::cout << c << std::endl; 71 | for (int r = 0; r < a.rows(); r++){ 72 | for (int c = 0; c < a.cols(); c ++){ 73 | std::cout << a[r][c] << "\t"; 74 | 75 | } 76 | std::cout << std::endl; 77 | } 78 | std::cout << std::endl; 79 | } 80 | 81 | 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/iso_gw.h: -------------------------------------------------------------------------------- 1 | #ifndef _ISO_GW_H 2 | #define _ISO_GW_H 3 | 4 | #include "init_iso_gw.h" 5 | 6 | 7 | 8 | 9 | 10 | void multiplyArray(std::vector &a, double multiplier); 11 | 12 | 13 | void multiplyArray(vnl_vector &a, double multiplier); 14 | 15 | void expArray(std::vector &a, double exponent ); 16 | 17 | void expArray(vnl_vector &a, double exponent ); 18 | 19 | void debugArray(vnl_vector &a, std::string c ); 20 | void debugArray(vnl_vector &a, std::string c ); 21 | void debugArray(std::vector a, std::string c ); 22 | 23 | 24 | 25 | void debug2DArray(vnl_matrix &a, std::string c ); 26 | void debug2DArray(vnl_matrix_fixed &a, std::string c ); 27 | 28 | 29 | 30 | //void iso_gw(LISTFILE &list, basisFuntions &Basis, GradCoef E); 31 | void iso_gw(vnl_matrixBmatrix, basisFuntions &Basis, GradCoef E, vnl_vectoraa); 32 | 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/main.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include "Fit_nifti_iso.h" 3 | #include "fit_nifti_iso_parser.h" 4 | 5 | 6 | int main(int argc , char * argv[] ){ 7 | 8 | std::cout << "Debuging..."<< std::endl; 9 | std::cout << "testing: "<< argc << std::endl; 10 | FITNIFTIISO myfitter(argc,argv); 11 | 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/tools/FitNIFTIIso/read_grad_cal.cxx: -------------------------------------------------------------------------------- 1 | #include "gradcal.h" 2 | 3 | 4 | void print_keys(std::vector key){ 5 | int nx = key.size(); 6 | for (int i =0; i < nx; i++){ 7 | std::cout << "Key" << i << ": " < key){ 12 | int nx = key.size(); 13 | for (int i =0; i < nx; i++){ 14 | std::cout << "Key" << i << ": " < Xkey = outputGrad->get_X_key(); 29 | print_keys(Xkey); 30 | std::vector Ykey = outputGrad->get_Y_key(); 31 | print_keys(Ykey); 32 | std::vector Zkey = outputGrad->get_Z_key(); 33 | print_keys(Zkey); 34 | 35 | std::vector X_coef = outputGrad->get_X_coef(); 36 | print_coef(X_coef); 37 | std::vector Y_coef = outputGrad->get_Y_coef(); 38 | print_coef(Y_coef); 39 | std::vector Z_coef = outputGrad->get_Y_coef(); 40 | print_coef(Z_coef); 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | return 1; 52 | } 53 | -------------------------------------------------------------------------------- /src/tools/FlipSwapBMatrix/FlipSwapBMatrix_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _FlipSwapBMatrix_PARSER_h 2 | #define _FlipSwapBMatrix_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser2.h" 10 | 11 | class FlipSwapBMatrix_PARSER : public itk::ants::CommandLineParser2 12 | { 13 | public: 14 | FlipSwapBMatrix_PARSER( int argc , char * argv[] ); 15 | ~FlipSwapBMatrix_PARSER(); 16 | 17 | std::string getInputBMatrix(); 18 | std::string getOutputBMatrix(); 19 | std::string getNewX(); 20 | std::string getNewY(); 21 | std::string getNewZ(); 22 | 23 | 24 | 25 | private: 26 | void CreateParserandFillText(int argc , char * argv[] ); 27 | void InitializeCommandLineOptions(); 28 | bool checkIfAllRequiredParamsAreEntered(); 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/tools/IsDirectionPositiveDet/IsDirectionPositiveDet.cxx: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | if(argc==1) 7 | { 8 | std::cout<<"Usage: IsDirectionPositiveDet nifti_image"<(argv[1]); 15 | 16 | float det = vnl_determinant( img->GetDirection().GetVnlMatrix()); 17 | std::cout<< "Img det: "< 7 | typename ImageType::Pointer PadImage(typename ImageType::Pointer img, int pl, int pr, int pt,int pb, int pf, int pback, bool change_header) 8 | { 9 | 10 | 11 | int pad_left= pl; 12 | int pad_right= pr; 13 | int pad_top= pt; 14 | int pad_bottom= pb; 15 | int pad_low= pf; 16 | int pad_high= pback; 17 | 18 | typename ImageType::SizeType orig_size= img->GetLargestPossibleRegion().GetSize(); 19 | 20 | typename ImageType::SizeType new_size=orig_size; 21 | new_size[0]=orig_size[0]+pad_left+pad_right; 22 | new_size[1]=orig_size[1]+pad_top+pad_bottom; 23 | new_size[2]=orig_size[2]+pad_low+pad_high; 24 | 25 | 26 | typename ImageType::Pointer new_image=ImageType::New(); 27 | typename ImageType::IndexType start; start.Fill(0); 28 | typename ImageType::RegionType reg(start,new_size); 29 | new_image->SetRegions(reg); 30 | new_image->Allocate(); 31 | new_image->SetOrigin(img->GetOrigin()); 32 | new_image->SetSpacing(img->GetSpacing()); 33 | new_image->SetDirection(img->GetDirection()); 34 | new_image->FillBuffer(0.); 35 | 36 | 37 | itk::ImageRegionIteratorWithIndex it(img,img->GetLargestPossibleRegion()); 38 | it.GoToBegin(); 39 | while(!it.IsAtEnd()) 40 | { 41 | typename ImageType::IndexType old_ind= it.GetIndex(); 42 | typename ImageType::IndexType new_ind=old_ind; 43 | 44 | new_ind[2]= old_ind[2] + pad_low; 45 | new_ind[1]= old_ind[1] + pad_top; 46 | new_ind[0]= old_ind[0] + pad_left; 47 | new_image->SetPixel(new_ind,it.Get()); 48 | ++it; 49 | } 50 | 51 | if(change_header) 52 | { 53 | itk::ContinuousIndex cint; 54 | cint.Fill(0); 55 | cint[0]=-pad_left; 56 | cint[1]=-pad_top; 57 | cint[2]=-pad_low; 58 | 59 | typename ImageType::PointType pt; 60 | img->TransformContinuousIndexToPhysicalPoint(cint,pt); 61 | new_image->SetOrigin(pt); 62 | } 63 | 64 | return new_image; 65 | } 66 | 67 | 68 | 69 | 70 | template ImageType3D::Pointer PadImage(ImageType3D::Pointer, int, int , int ,int ,int ,int, bool) ; 71 | template ImageType4D::Pointer PadImage(ImageType4D::Pointer, int, int , int ,int ,int ,int, bool) ; 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/tools/ReorientImage/reorient_image_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Reorient_Image_PARSER_h 2 | #define _Reorient_Image_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class Reorient_Image_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | Reorient_Image_PARSER( int argc , char * argv[] ); 15 | ~Reorient_Image_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getOriginalOrientation(); 19 | std::string getDesiredOrientation(); 20 | std::string getOutputName(); 21 | std::string getPhase(); 22 | 23 | 24 | 25 | private: 26 | void CreateParserandFillText(int argc , char * argv[] ); 27 | void InitializeCommandLineOptions(); 28 | bool checkIfAllRequiredParamsAreEntered(); 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/tools/ReorientImage3D/reorient_image_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Reorient_Image_PARSER_h 2 | #define _Reorient_Image_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class Reorient_Image_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | Reorient_Image_PARSER( int argc , char * argv[] ); 15 | ~Reorient_Image_PARSER(); 16 | 17 | std::string getInputImageName(); 18 | std::string getOriginalOrientation(); 19 | std::string getDesiredOrientation(); 20 | std::string getDesiredOrientationFromReferenceImage(); 21 | std::string getOutputName(); 22 | 23 | 24 | private: 25 | void CreateParserandFillText(int argc , char * argv[] ); 26 | void InitializeCommandLineOptions(); 27 | bool checkIfAllRequiredParamsAreEntered(); 28 | }; 29 | 30 | 31 | 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/tools/ResampleDWIs/resample_dwis.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESAMPLE_DWIS_H 2 | #define _RESAMPLE_DWIS_H 3 | 4 | 5 | 6 | #include "defines.h" 7 | 8 | 9 | ImageType3D::Pointer resample_3D_image(ImageType3D::Pointer img,std::vector new_res,std::vector up_factors,std::string method); 10 | 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /src/tools/RotateBMatrix/rotate_bmatrix.h: -------------------------------------------------------------------------------- 1 | #ifndef _ROTATE_BMATRIX_H 2 | #define _ROTATE_BMATRIX_H 3 | 4 | 5 | #include "defines.h" 6 | #include 7 | #include "itkOkanQuadraticTransform.h" 8 | #include "itkAffineTransform.h" 9 | #include "itkEuler3DTransform.h" 10 | 11 | using CompositeTransformType= itk::CompositeTransform ; 12 | using OkanQuadraticTransformType=itk::OkanQuadraticTransform ; 13 | using AffineTransformType=itk::AffineTransform; 14 | using RigidTransformType= itk::Euler3DTransform; 15 | 16 | 17 | 18 | vnl_vector RotateBMatrixVec(vnl_vector Bmatrixvec, const vnl_matrix_fixed &rotmat); 19 | 20 | vnl_matrix RotateBMatrix(const vnl_matrix &Bmatrix, const vnl_matrix_fixed &rotmat, const vnl_matrix_fixed &fixed_dirmat,const vnl_matrix_fixed &moving_dirmat); 21 | 22 | 23 | vnl_matrix RotateBMatrix(vnl_matrix Bmatrix, std::vector transforms,const vnl_matrix_fixed &fixed_dirmat,const vnl_matrix_fixed &moving_dirmat); 24 | 25 | 26 | vnl_matrix RotateBMatrix(vnl_matrix Bmatrix, std::vector transforms,const vnl_matrix_fixed &fixed_dirmat,const vnl_matrix_fixed &moving_dirmat); 27 | 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /src/tools/RotateBMatrix/rotate_bmatrix_main.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _ROTATE_BMATRIXMAIN_CXX 2 | #define _ROTATE_BMATRIXMAIN_CXX 3 | 4 | 5 | #include "rotate_bmatrix.h" 6 | #include "../utilities/read_bmatrix_file.h" 7 | #include "itkTransformFileReader.h" 8 | #include "../utilities/read_3Dvolume_from_4D.h" 9 | 10 | int main(int argc, char* argv[]) 11 | { 12 | if(argc==1) 13 | { 14 | std::cout<<"Usage: RotateBmatrix bmat_file trans_file corresponding_image_that_will_be_rotated"< Bmatrix =read_bmatrix_file(argv[1]); 19 | 20 | std::ifstream intrans; 21 | intrans.open(argv[2]); 22 | std::string line; 23 | std::getline(intrans,line); 24 | intrans.close(); 25 | 26 | 27 | ImageType3D::Pointer ref_img=read_3D_volume_from_4D(argv[3],0); 28 | 29 | vnl_matrix_fixed dirmat=ref_img->GetDirection().GetVnlMatrix(); 30 | 31 | 32 | vnl_matrix_fixed rot_mat; 33 | 34 | if(line.find("#Insight Transform File")!=std::string::npos) 35 | { 36 | using TransformReaderType =itk::TransformFileReaderTemplate< double > ; 37 | TransformReaderType::Pointer reader = TransformReaderType::New(); 38 | reader->SetFileName(argv[2] ); 39 | reader->Update(); 40 | const TransformReaderType::TransformListType * transforms = reader->GetTransformList(); 41 | TransformReaderType::TransformListType::const_iterator it = transforms->begin(); 42 | 43 | RigidTransformType::Pointer rigid_trans = static_cast< RigidTransformType * >( (*it).GetPointer() ); 44 | AffineTransformType::Pointer affine_trans = static_cast< AffineTransformType * >( (*it).GetPointer() ); 45 | 46 | if(rigid_trans) 47 | rot_mat=rigid_trans->GetMatrix().GetVnlMatrix(); 48 | else 49 | rot_mat=affine_trans->GetMatrix().GetVnlMatrix(); 50 | } 51 | else 52 | { 53 | 54 | } 55 | 56 | vnl_matrix newBmat= RotateBMatrix(Bmatrix,rot_mat,dirmat,dirmat); 57 | 58 | std::string bmat_name= argv[1]; 59 | std::string new_bmat_name= bmat_name.substr(0,bmat_name.find(".bmtxt")) + "_rot.bmtxt"; 60 | std::ofstream outfile(new_bmat_name); 61 | outfile<(argv[1]); 21 | int Nvols = img->GetLargestPossibleRegion().GetSize()[3]; 22 | 23 | vnl_vector bvals(Nvols); 24 | std::ifstream infileb(argv[2]); 25 | infileb>>bvals; 26 | infileb.close(); 27 | 28 | ImageType3D::Pointer best_b0_img; 29 | 30 | int id = select_best_b0(img,bvals,best_b0_img); 31 | 32 | writeImageD(best_b0_img,argv[3]); 33 | return EXIT_SUCCESS; 34 | 35 | } 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/tools/Set4DImageDirection/set_4dimage_direction.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | #include "defines.h" 10 | 11 | 12 | int main(int argc, char*argv[]) 13 | { 14 | if(argc<3) 15 | { 16 | std::cout<<"Usage: Set4DImageDirection full_path_to_4d_image full_path_to_output_name 16_directions (first row- then secon row... If not provided, identity is put)"<(argv[1]); 21 | 22 | 23 | ImageType4D::DirectionType dir; 24 | dir.SetIdentity(); 25 | 26 | if(argc>3) 27 | { 28 | dir(0,0) = atof(argv[3]); 29 | dir(0,1) = atof(argv[4]); 30 | dir(0,2) = atof(argv[5]); 31 | dir(0,3) = atof(argv[6]); 32 | dir(1,0) = atof(argv[7]); 33 | dir(1,1) = atof(argv[8]); 34 | dir(1,2) = atof(argv[9]); 35 | dir(1,3) = atof(argv[10]); 36 | dir(2,0) = atof(argv[11]); 37 | dir(2,1) = atof(argv[12]); 38 | dir(2,2) = atof(argv[13]); 39 | dir(2,3) = atof(argv[14]); 40 | dir(3,0) = atof(argv[15]); 41 | dir(3,1) = atof(argv[16]); 42 | dir(3,2) = atof(argv[17]); 43 | dir(3,3) = atof(argv[18]); 44 | } 45 | 46 | image4D->SetDirection(dir); 47 | 48 | writeImageD(image4D,argv[2]); 49 | 50 | return EXIT_SUCCESS; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/tools/Set4DImageOrigin/set_4dimage_origin.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | #include "defines.h" 10 | 11 | 12 | int main(int argc, char*argv[]) 13 | { 14 | if(argc<3) 15 | { 16 | std::cout<<"Usage: Set4DImageOrigin full_path_to_4d_image full_path_to_output_name orig_x orig_y orig_z orig_t (if origin not provided 0s will be written)"<(argv[1]); 21 | 22 | 23 | ImageType4D::PointType orig; 24 | orig.Fill(0); 25 | 26 | if(argc>3) 27 | { 28 | orig[0] = atof(argv[3]); 29 | orig[1] = atof(argv[4]); 30 | orig[2] = atof(argv[5]); 31 | orig[3] = atof(argv[6]); 32 | } 33 | 34 | image4D->SetOrigin(orig); 35 | 36 | writeImageD(image4D,std::string(argv[2])); 37 | 38 | 39 | 40 | return EXIT_SUCCESS; 41 | } 42 | -------------------------------------------------------------------------------- /src/tools/Set4DImageResolution/Set4DImageResolution.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | #include "defines.h" 10 | 11 | 12 | int main(int argc, char*argv[]) 13 | { 14 | if(argc<3) 15 | { 16 | std::cout<<"Usage: Set4DImageResolution full_path_to_4d_image full_path_to_output_name res_x res_y res_z res_t (if origin not provided 0s will be written)"<(argv[1]); 21 | 22 | 23 | ImageType4D::SpacingType orig; 24 | orig.Fill(0); 25 | 26 | if(argc>3) 27 | { 28 | orig[0] = atof(argv[3]); 29 | orig[1] = atof(argv[4]); 30 | orig[2] = atof(argv[5]); 31 | orig[3] = atof(argv[6]); 32 | } 33 | 34 | image4D->SetSpacing(orig); 35 | 36 | 37 | 38 | writeImageD(image4D,argv[2]); 39 | 40 | return EXIT_SUCCESS; 41 | } 42 | -------------------------------------------------------------------------------- /src/tools/SynthesizeDWIFromMAPMRI/synthesize_dwi_from_map_test.cxx: -------------------------------------------------------------------------------- 1 | #include "synthesize_dwi_from_map_mri.h" 2 | #include "defines.h" 3 | #include "compute_eigen_images.h" 4 | #include "estimate_tensor_wlls_sub.h" 5 | 6 | typedef itk::Vector DTType; 7 | typedef itk::Image DTImageType; 8 | 9 | int main(int argc, char*argv[]) 10 | { 11 | 12 | std::string mapname(argv[1]); 13 | std::string listname(argv[2]); 14 | int vol_id = atoi(argv[3]); 15 | std::string maskname(argv[4]); 16 | 17 | LISTFILE list(listname); 18 | 19 | 20 | 21 | typedef itk::ImageFileReader RdType2; 22 | RdType2::Pointer rd2= RdType2::New(); 23 | rd2->SetFileName(maskname); 24 | rd2->Update(); 25 | ImageType3D::Pointer mask_image= rd2->GetOutput(); 26 | 27 | 28 | std::vector dummy; 29 | 30 | ImageType3D::Pointer A0_image=NULL; 31 | DTImageType::Pointer dt_image=NULL; 32 | 33 | std::cout<<"Estimating the diffusion tensors..."< RdType; 43 | RdType::Pointer rd= RdType::New(); 44 | rd->SetFileName(mapname); 45 | rd->Update(); 46 | MAPImageType::Pointer mapmri_image= rd->GetOutput(); 47 | 48 | 49 | ImageType3D::Pointer dwi =SynthesizeDWIFromMAPMRI(mapmri_image,A0_image,evec_image,eval_image, list.GetBmatrix().get_n_rows(vol_id,1), list.GetSmallDelta(),list.GetBigDelta() ); 50 | 51 | 52 | typedef itk::ImageFileWriter WrType; 53 | WrType::Pointer wr= WrType::New(); 54 | std::string nname = mapname.substr(0, mapname.find(".nii")) + std::string("_dwi.nii"); 55 | wr->SetFileName( nname); 56 | wr->SetInput(dwi); 57 | wr->Update(); 58 | 59 | 60 | 61 | 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/tools/SynthesizeDWIsFromTensor/synthesize_dwis_from_tensor.cxx: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | #include "../utilities/read_bmatrix_file.h" 3 | #include "../utilities/write_3D_image_to_4D_file.h" 4 | #include "../tools/EstimateTensor/DTIModel.h" 5 | 6 | 7 | int main(int argc,char *argv[]) 8 | { 9 | if(argc<5) 10 | { 11 | std::cout<<"Usage: SynthesizeDWIsFromTensor full_path_to_tensor_image full_path_to_A0_image full_path_to_synthesization_Bmatrix output_filename"< TensorReaderType; 17 | TensorReaderType::Pointer tensor_reader=TensorReaderType::New(); 18 | tensor_reader->SetFileName(argv[1]); 19 | tensor_reader->Update(); 20 | ImageType4D::Pointer tensor_image_4D_itk= tensor_reader->GetOutput(); 21 | 22 | 23 | ImageType3D::Pointer A0_image= readImageD(argv[2]); 24 | 25 | vnl_matrix Bmatrix = read_bmatrix_file(argv[3]); 26 | 27 | 28 | DTImageType::Pointer dt_image= DTImageType::New(); 29 | dt_image->SetRegions(A0_image->GetLargestPossibleRegion()); 30 | dt_image->Allocate(); 31 | dt_image->SetSpacing(A0_image->GetSpacing()); 32 | dt_image->SetOrigin(A0_image->GetOrigin()); 33 | dt_image->SetDirection(A0_image->GetDirection()); 34 | 35 | 36 | ImageType3D::SizeType imsize = A0_image->GetLargestPossibleRegion().GetSize(); 37 | 38 | 39 | ImageType4D::IndexType ind; 40 | ImageType3D::IndexType index; 41 | 42 | for(int k=0;kGetPixel(ind)/1000000.; 59 | ind[3]=1; 60 | curr_tens[3]= tensor_image_4D_itk->GetPixel(ind)/1000000.; 61 | ind[3]=2; 62 | curr_tens[5]= tensor_image_4D_itk->GetPixel(ind)/1000000.; 63 | ind[3]=3; 64 | curr_tens[1]= tensor_image_4D_itk->GetPixel(ind)/1000000.; 65 | ind[3]=4; 66 | curr_tens[2]= tensor_image_4D_itk->GetPixel(ind)/1000000.; 67 | ind[3]=5; 68 | curr_tens[4]= tensor_image_4D_itk->GetPixel(ind)/1000000.; 69 | 70 | 71 | dt_image->SetPixel(index,curr_tens); 72 | } 73 | } 74 | } 75 | 76 | 77 | 78 | DTIModel dti_estimator; 79 | dti_estimator.SetOutput(dt_image); 80 | dti_estimator.SetA0Image(A0_image); 81 | 82 | 83 | int Nvols= Bmatrix.rows(); 84 | 85 | for(int i=0;i bmat_vec= Bmatrix.get_row(i); 88 | 89 | ImageType3D::Pointer dwi= dti_estimator.SynthesizeDWI( bmat_vec ); 90 | 91 | write_3D_image_to_4D_file(dwi,argv[4],i,Nvols); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/tools/TORTOISEBMatrixToBT/tortoise_bmatrix_to_bt.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _TORTOISEBmatrixToFSLBVecs_CXX 2 | #define _TORTOISEBmatrixToFSLBVecs_CXX 3 | 4 | #include "../utilities/read_bmatrix_file.h" 5 | #include "defines.h" 6 | #include 7 | #include 8 | 9 | 10 | 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | if(argc==1) 15 | { 16 | std::cout<<"Usage: tortoise_bmatrix_to_bt full_path_to_bmatrix_file"< Bmatrix = read_bmatrix_file(bmat_name); 22 | 23 | int Nvols = Bmatrix.rows(); 24 | vnl_matrix BT = Bmatrix; 25 | BT.fill(0); 26 | 27 | 28 | for(int v=0;v bmat_vec=Bmatrix.get_row(v); 31 | 32 | BT(v,0)= bmat_vec[0]*1E6; 33 | BT(v,1)= bmat_vec[3]*1E6; 34 | BT(v,2)= bmat_vec[5]*1E6; 35 | 36 | BT(v,3)= bmat_vec[1]*1E6/sqrt(2); 37 | BT(v,4)= -bmat_vec[2]*1E6/sqrt(2); 38 | BT(v,5)= -bmat_vec[4]*1E6/sqrt(2); 39 | } 40 | 41 | std::string out_name = bmat_name.substr(0,bmat_name.rfind(".bmtxt"))+".bt"; 42 | 43 | std::ofstream outbtfile(out_name); 44 | outbtfile< 6 | #include 7 | #include "defines.h" 8 | 9 | 10 | 11 | int main(int argc, char* argv[]) 12 | { 13 | if(argc<3) 14 | { 15 | std::cout<<"Usage: FSLBVecsToTORTOISEBmatrix full_path_to_bvals_file full_path_to_bvecs_file"< bvecs,bvals; 25 | if(bvecs_stream.is_open()) 26 | { 27 | bvecs.read_ascii(bvecs_stream); 28 | bvecs_stream.close(); 29 | } 30 | else 31 | { 32 | std::cerr<<"Bvecs file does not exist..."< Bmatrix(Nvols,6) ; 55 | 56 | for(int i=0;i vec= bvecs.get_n_columns(i,1); 59 | double nrm= sqrt(vec(0,0)*vec(0,0) + vec(1,0)*vec(1,0) + vec(2,0)*vec(2,0) ); 60 | if(nrm > 1E-3) 61 | { 62 | vec(0,0)/=nrm; 63 | vec(1,0)/=nrm; 64 | vec(2,0)/=nrm; 65 | } 66 | 67 | vnl_matrix mat = bvals(0,i) * vec * vec.transpose(); 68 | Bmatrix(i,0)=mat(0,0); 69 | Bmatrix(i,1)=2*mat(0,1); 70 | Bmatrix(i,2)=2*mat(0,2); 71 | Bmatrix(i,3)=mat(1,1); 72 | Bmatrix(i,4)=2*mat(1,2); 73 | Bmatrix(i,5)=mat(2,2); 74 | } 75 | 76 | fs::path p(argv[1]); 77 | std::string dirname = p.parent_path().string() ; 78 | if(dirname=="") 79 | dirname="."; 80 | 81 | std::string bmtxt_filename= dirname + "/" + p.stem().string() + ".bmtxt"; 82 | 83 | std::ofstream outbmtxtfile(bmtxt_filename); 84 | outbmtxtfile< 7 | #include 8 | 9 | 10 | 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | if(argc==1) 15 | { 16 | std::cout<<"Usage: TORTOISEBmatrixToFSLBVecs full_path_to_bmatrix_file"< Bmatrix = read_bmatrix_file(std::string(argv[1])); 21 | int Nvols=Bmatrix.rows(); 22 | vnl_matrix bvecs(3,Nvols); 23 | 24 | vnl_matrix bvals =tortoise_bmatrix_to_fsl_bvecs(Bmatrix,bvecs); 25 | std::string bmtxt_filename(argv[1]); 26 | std::string bvecs_fname= bmtxt_filename.substr(0,bmtxt_filename.find(".bmtxt")) + std::string(".bvecs"); 27 | std::string bvals_fname= bmtxt_filename.substr(0,bmtxt_filename.find(".bmtxt")) + std::string(".bvals"); 28 | 29 | 30 | std::ofstream bvecs_file(bvecs_fname.c_str()); 31 | for(int i=0;i<3;i++) 32 | { 33 | for(int j=0;j MatrixType; 8 | 9 | vnl_matrix tortoise_bmatrix_to_fsl_bvecs(const vnl_matrix &Bmatrix, vnl_matrix &bvecs) 10 | { 11 | int Nvols=Bmatrix.rows(); 12 | vnl_matrix bvals(1,Nvols); 13 | 14 | for(int i=0;i bmat_vec= Bmatrix.get_row(i); 17 | 18 | MatrixType bmat; 19 | bmat(0,0)= bmat_vec[0]; 20 | bmat(0,1)= bmat_vec[1]/2; 21 | bmat(1,0)= bmat_vec[1]/2; 22 | bmat(0,2)= bmat_vec[2]/2; 23 | bmat(2,0)= bmat_vec[2]/2; 24 | bmat(1,1)= bmat_vec[3]; 25 | bmat(1,2)= bmat_vec[4]/2; 26 | bmat(2,1)= bmat_vec[4]/2; 27 | bmat(2,2)= bmat_vec[5]; 28 | 29 | vnl_symmetric_eigensystem eig(bmat); 30 | 31 | bvals(0,i)= eig.D(2,2); 32 | vnl_vector cbvec= eig.V.get_column(2); 33 | bvecs(0,i)= cbvec[0]; 34 | bvecs(1,i)= cbvec[1]; 35 | bvecs(2,i)= cbvec[2]; 36 | } 37 | return bvals; 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/tools/ZeroSlices3D/ZeroSlices3D.cxx: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #include "itkImage.h" 9 | #include "itkImageFileReader.h" 10 | #include "itkImageFileWriter.h" 11 | #include "itkImageDuplicator.h" 12 | 13 | #include "itkImageRegionIteratorWithIndex.h" 14 | 15 | 16 | typedef float RealType; 17 | typedef itk::Image ImageType3D; 18 | 19 | 20 | int main( int argc , char * argv[] ) 21 | { 22 | if(argc<5) 23 | { 24 | std::cout<<"Usage: ZeroSlices3D input_image output_image start_slice_index end_index(inclusive)"< ImageType3DReaderType; 32 | ImageType3DReaderType::Pointer imager= ImageType3DReaderType::New(); 33 | imager->SetFileName(argv[1]); 34 | imager->Update(); 35 | ImageType3D::Pointer image3D= imager->GetOutput(); 36 | 37 | ImageType3D::SizeType sz= image3D->GetLargestPossibleRegion().GetSize(); 38 | 39 | int start_ind=atoi(argv[3]); 40 | int end_ind=atoi(argv[4]); 41 | 42 | for(int k=start_ind;k<=end_ind;k++) 43 | { 44 | ImageType3D::IndexType ind3; 45 | ind3[2]=k; 46 | for(int j=0;jSetPixel(ind3,0); 53 | } 54 | } 55 | } 56 | 57 | 58 | 59 | 60 | std::string filename(argv[2]); 61 | 62 | 63 | 64 | typedef itk::ImageFileWriter WriterType; 65 | WriterType::Pointer writer= WriterType::New(); 66 | writer->SetFileName(filename); 67 | writer->SetInput(image3D); 68 | writer->Update(); 69 | 70 | 71 | 72 | 73 | 74 | 75 | return EXIT_SUCCESS; 76 | } 77 | -------------------------------------------------------------------------------- /src/tools/gradnonlin/gradcal.h: -------------------------------------------------------------------------------- 1 | #ifndef _GRADCAL_H 2 | #define _GRADCAL_H 3 | 4 | #include "iostream" 5 | #include 6 | #include 7 | #include "cmath" 8 | 9 | 10 | struct GradCoef{ 11 | std::vector gradX_coef; 12 | std::vectorXkeys; 13 | std::vector gradY_coef; 14 | std::vectorYkeys; 15 | std::vector gradZ_coef; 16 | std::vectorZkeys; 17 | float R0 = 250.; 18 | std::string gradType; 19 | }; 20 | 21 | 22 | class GRADCAL{ 23 | public: 24 | // 2 constructors 25 | GRADCAL(); 26 | GRADCAL(std::string fileName); 27 | 28 | 29 | // destructor 30 | ~GRADCAL(); 31 | 32 | 33 | 34 | void read_grad_file(std::string fileName); 35 | void write_ASB_format(GradCoef gc, std::string outFileName); 36 | 37 | std::vector get_X_key(){ 38 | 39 | return this->grads_cal.Xkeys; 40 | } 41 | std::vector get_Y_key(){ 42 | return this->grads_cal.Ykeys; 43 | } 44 | std::vector get_Z_key(){ 45 | return this->grads_cal.Zkeys; 46 | } 47 | std::vector get_X_coef(){ 48 | return this->grads_cal.gradX_coef; 49 | } 50 | std::vector get_Y_coef(){ 51 | return this->grads_cal.gradY_coef; 52 | } 53 | std::vector get_Z_coef(){ 54 | return this->grads_cal.gradZ_coef; 55 | } 56 | GradCoef get_struct(){ 57 | return this->grads_cal; 58 | } 59 | 60 | private: 61 | GradCoef grads_cal; 62 | std::string gradFilename; 63 | void read_Siemens_format(std::string fileName); 64 | void read_GE_format(std::string fileName); 65 | void read_ASB_format(std::string fileName); 66 | void init(); 67 | 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/tools/gradnonlin/init_iso_gw.h: -------------------------------------------------------------------------------- 1 | #ifndef _INIT_ISO_GW_H 2 | #define _INIT_ISO_GW_H 3 | 4 | #include "gradcal.h" 5 | //#include "LISTFILE.h" 6 | 7 | 8 | #include "itkNiftiImageIO.h" 9 | #include "itkImportImageFilter.h" 10 | #include "itkImageMomentsCalculator.h" 11 | #include "itkImageDuplicator.h" 12 | #include "itkImageRegionIteratorWithIndex.h" 13 | 14 | 15 | typedef unsigned char MaskPixelType; 16 | typedef itk::Image MaskImageType; 17 | 18 | 19 | 20 | struct basisFuntions{ 21 | std::vector< vnl_matrix > xbasis; 22 | std::vector< vnl_matrix > ybasis; 23 | std::vector< vnl_matrix > zbasis; 24 | }; 25 | 26 | 27 | double plgndr(int ll, int mm, double x); 28 | float factorial(int n); 29 | 30 | double sphericalz(int ll, int mm, double phi,double zz, double theta ); 31 | 32 | // code for derivative wrt x,y,z 33 | double dshdx(char grad, int ll, int mml, double rr, double phi,double zz, double theta); 34 | double dshdx_X(int ll, int mml, double phi, double zz, double theta ); 35 | double dshdx_Y(int ll, int mml, double phi, double zz, double theta ); 36 | double dshdx_Z(int ll, int mml, double phi, double zz, double theta ); 37 | 38 | basisFuntions init_iso_gw(vnl_matrix smat, MaskImageType::Pointer maskedIm, GradCoef E); 39 | 40 | 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/tools/gradnonlin/mk_displacementMaps.cxx: -------------------------------------------------------------------------------- 1 | #include "mk_displacementMaps.h" 2 | #include 3 | #include 4 | #include "defines.h" 5 | 6 | 7 | 8 | int main(int argc,char *argv[]) 9 | { 10 | if(argc<2) 11 | { 12 | std::cout<<"CreateNonlinearityDisplacementMap path_to_coefficient_or_gradcal_file path_to_base_nifti outputname is_GE (0/1. optional.default:0)"<4) 19 | is_GE=(bool)atoi(argv[4]); 20 | 21 | 22 | ImageType3D::Pointer img =readImageD(argv[2]); 23 | 24 | DisplacementFieldType::Pointer output_field= mk_displacement(argv[1],img ,is_GE); 25 | 26 | 27 | typedef itk::ImageFileWriter WrType; 28 | WrType::Pointer wr= WrType::New(); 29 | wr->SetInput(output_field); 30 | wr->SetFileName(argv[3]); 31 | wr->Update(); 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/tools/import_bruker/bruker_anatomical_parser (copy).h: -------------------------------------------------------------------------------- 1 | #ifndef _BrukerAnatomical_PARSER_h 2 | #define _BrukerAnatomical_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class BrukerAnatomical_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | BrukerAnatomical_PARSER( int argc , char * argv[] ); 15 | ~BrukerAnatomical_PARSER(); 16 | 17 | std::string getInputDataFolder(); 18 | std::string getOutputFilename(); 19 | bool getConvertToAnatomicalHeader(); 20 | 21 | private: 22 | void CreateParserandFillText(int argc , char * argv[] ); 23 | void InitializeCommandLineOptions(); 24 | bool checkIfAllRequiredParamsAreEntered(); 25 | }; 26 | 27 | 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/tools/import_bruker/bruker_anatomical_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _BrukerAnatomical_PARSER_h 2 | #define _BrukerAnatomical_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class BrukerAnatomical_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | BrukerAnatomical_PARSER( int argc , char * argv[] ); 15 | ~BrukerAnatomical_PARSER(); 16 | 17 | std::string getInputDataFolder(); 18 | std::string getOutputFilename(); 19 | bool getConvertToAnatomicalHeader(); 20 | 21 | private: 22 | void CreateParserandFillText(int argc , char * argv[] ); 23 | void InitializeCommandLineOptions(); 24 | bool checkIfAllRequiredParamsAreEntered(); 25 | }; 26 | 27 | 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/tools/import_bruker/bruker_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _Bruker_PARSER_h 2 | #define _Bruker_PARSER_h 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "antsCommandLineParser.h" 10 | 11 | class Bruker_PARSER : public itk::ants::CommandLineParser 12 | { 13 | public: 14 | Bruker_PARSER( int argc , char * argv[] ); 15 | ~Bruker_PARSER(); 16 | 17 | std::string getInputDataFolder(); 18 | std::string getOutputProcFolder(); 19 | // bool getUseGradientsInsteadOfBMatrix(); 20 | 21 | int getConvertToAnatomicalHeader(); 22 | 23 | private: 24 | void CreateParserandFillText(int argc , char * argv[] ); 25 | void InitializeCommandLineOptions(); 26 | bool checkIfAllRequiredParamsAreEntered(); 27 | }; 28 | 29 | 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/tools/import_bruker/convert_bruker.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONVERT_BRUKER_h 2 | #define _CONVERT_BRUKER_h 3 | 4 | #include 5 | #include 6 | 7 | 8 | #include "defines.h" 9 | 10 | namespace fs = boost::filesystem; 11 | 12 | 13 | 14 | 15 | 16 | struct METHOD_struct 17 | { 18 | int N_averages; 19 | int N_reps; 20 | float TR; 21 | std::string ReadOrient; 22 | std::string SliceOrient; 23 | int N_A0; 24 | int NdiffExp; 25 | int Ndir; 26 | int N_totalvol; 27 | float RG; 28 | float small_delta, BIG_DELTA; 29 | vnl_vector eff_bval; 30 | vnl_vector grad_phase, grad_read,grad_slice; 31 | 32 | vnl_matrix Bmatrix; 33 | int PVM_EPI_BlipDir; 34 | std::string phase_mode; 35 | 36 | vnl_matrix_fixed grad_orient; 37 | }; 38 | 39 | 40 | struct VISU_struct 41 | { 42 | int dim; 43 | int size[3]; 44 | float extent[3]; 45 | vnl_matrix_fixed orientation; 46 | float pos[3]; 47 | float intercept,slope; 48 | std::string word_type; 49 | int nslices; 50 | float slice_thickness; 51 | std::string subject_position; 52 | }; 53 | 54 | 55 | struct RECO_struct 56 | { 57 | public: 58 | 59 | std::string RECO_WORDTYPE; 60 | std::string RECO_BYTE_ORDER; 61 | int RECO_SIZE[3]; 62 | std::string RECO_MAP_MODE; 63 | int RECO_TRANSPOSITION; 64 | float RECO_FOV[3]; 65 | vnl_matrix RECO_MAP_SLOPE; 66 | int RECO_IR_SCALE; 67 | std::string version; 68 | }; 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/tools/import_bruker/convert_bruker_anatomical.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONVERT_BRUKER_ANATOMICAL_h 2 | #define _CONVERT_BRUKER_ANATOMICAL_h 3 | 4 | #include 5 | #include 6 | 7 | #include "bruker_anatomical_parser.h" 8 | #include 9 | #include 10 | 11 | #include "itkImageFileWriter.hxx" 12 | #include "defines.h" 13 | #include "convert_bruker.h" 14 | 15 | namespace fs = boost::filesystem; 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | class ConvertBrukerAnatomical 27 | { 28 | public: 29 | ConvertBrukerAnatomical ( int argc , char * argv[] ); 30 | ~ConvertBrukerAnatomical(); 31 | 32 | 33 | private: 34 | bool convert_bruker_anatomical(std::string input_folder, std::string output_filename); 35 | 36 | RECO_struct read_reco_header(std::string reco_file); 37 | ACQP_struct read_acqp_header(std::string acqp_file, RECO_struct reco_struct); 38 | 39 | 40 | 41 | void get_grad_orient(std::string method_file); 42 | void get_dimension_order(RECO_struct reco_struct,ACQP_struct acqp_struct,int dimension_order[]); 43 | 44 | ImageType4DITK::Pointer get_bruker_image_data(std::string twodseq_file,RECO_struct reco_struct,ACQP_struct acqp_struct); 45 | 46 | 47 | 48 | 49 | private: 50 | BrukerAnatomical_PARSER* parser; 51 | std::string slice_orientation; 52 | std::string read_orientation; 53 | vnl_matrix_fixed grad_orient; 54 | int NTE; 55 | double RG; 56 | }; 57 | 58 | 59 | 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/tools/import_bruker/import_bruker.cxx: -------------------------------------------------------------------------------- 1 | #include "convert_bruker.h" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | 6 | ConvertBruker my_converter(argc,argv); 7 | 8 | 9 | return EXIT_SUCCESS; 10 | } 11 | -------------------------------------------------------------------------------- /src/tools/import_bruker/import_bruker_anatomical.cxx: -------------------------------------------------------------------------------- 1 | #include "convert_bruker_anatomical.h" 2 | 3 | int main(int argc, char * argv[]) 4 | { 5 | 6 | ConvertBrukerAnatomical my_converter(argc,argv); 7 | 8 | 9 | return EXIT_SUCCESS; 10 | } 11 | -------------------------------------------------------------------------------- /src/utilities/TORTOISE_Utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef _TORTOISEUTILITIES_H 2 | #define _TORTOISEUTILITIES_H 3 | 4 | #ifdef _WIN32 5 | #include 6 | #elif MACOS 7 | #include 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include "boost/system/error_code.hpp" 14 | #include "boost/filesystem.hpp" 15 | 16 | int is_big_endian(void); 17 | 18 | 19 | int getNCores(); 20 | 21 | std::string GetTORTOISEVersion(); 22 | 23 | std::string executable_path_fallback(const char *argv0); 24 | 25 | std::string executable_path(const char *argv0); 26 | 27 | 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/utilities/extract_3Dvolume_from_4D.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _EXTRACT3DVOLUMEFROM4D_CXX 2 | #define _EXTRACT3DVOLUMEFROM4D_CXX 3 | 4 | 5 | #include "defines.h" 6 | 7 | 8 | ImageType3D::Pointer extract_3D_volume_from_4D(ImageType4D::Pointer img4d, int vol_id) 9 | { 10 | ImageType3D::SizeType sz; 11 | sz[0]=img4d->GetLargestPossibleRegion().GetSize()[0]; 12 | sz[1]=img4d->GetLargestPossibleRegion().GetSize()[1]; 13 | sz[2]=img4d->GetLargestPossibleRegion().GetSize()[2]; 14 | ImageType3D::IndexType start; start.Fill(0); 15 | ImageType3D::RegionType reg(start,sz); 16 | 17 | ImageType3D::SpacingType spc; 18 | spc[0]=img4d->GetSpacing()[0]; 19 | spc[1]=img4d->GetSpacing()[1]; 20 | spc[2]=img4d->GetSpacing()[2]; 21 | 22 | ImageType3D::PointType orig; 23 | orig[0]=img4d->GetOrigin()[0]; 24 | orig[1]=img4d->GetOrigin()[1]; 25 | orig[2]=img4d->GetOrigin()[2]; 26 | 27 | ImageType3D::DirectionType dir; 28 | dir(0,0)=img4d->GetDirection()(0,0);dir(0,1)=img4d->GetDirection()(0,1);dir(0,2)=img4d->GetDirection()(0,2); 29 | dir(1,0)=img4d->GetDirection()(1,0);dir(1,1)=img4d->GetDirection()(1,1);dir(1,2)=img4d->GetDirection()(1,2); 30 | dir(2,0)=img4d->GetDirection()(2,0);dir(2,1)=img4d->GetDirection()(2,1);dir(2,2)=img4d->GetDirection()(2,2); 31 | 32 | 33 | ImageType3D::Pointer img3d = ImageType3D::New(); 34 | img3d->SetRegions(reg); 35 | img3d->Allocate(); 36 | img3d->SetOrigin(orig); 37 | img3d->SetSpacing(spc); 38 | img3d->SetDirection(dir); 39 | 40 | ImageType4D::IndexType ind4; 41 | ind4[3]=vol_id; 42 | 43 | itk::ImageRegionIteratorWithIndex it(img3d,img3d->GetLargestPossibleRegion()); 44 | it.GoToBegin(); 45 | while(!it.IsAtEnd()) 46 | { 47 | ImageType3D::IndexType ind3= it.GetIndex(); 48 | ind4[2]=ind3[2]; 49 | ind4[1]=ind3[1]; 50 | ind4[0]=ind3[0]; 51 | 52 | it.Set(img4d->GetPixel(ind4)); 53 | ++it; 54 | } 55 | 56 | return img3d; 57 | } 58 | 59 | 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/utilities/extract_3Dvolume_from_4D.h: -------------------------------------------------------------------------------- 1 | #ifndef _EXTRACT3DVOLUMEFROM4D_H 2 | #define _EXTRACT3DVOLUMEFROM4D_H 3 | 4 | 5 | #include "defines.h" 6 | 7 | 8 | ImageType3D::Pointer extract_3D_volume_from_4D(ImageType4D::Pointer img4d, int vol_id); 9 | 10 | 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/utilities/itkNiftiImageIOHeaderFactory.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #include "itkNiftiImageIOHeaderFactory.h" 19 | #include "itkNiftiImageIOHeader.h" 20 | #include "itkVersion.h" 21 | 22 | namespace itk 23 | { 24 | void NiftiImageIOHeaderFactory::PrintSelf(std::ostream &, Indent) const 25 | {} 26 | 27 | NiftiImageIOHeaderFactory::NiftiImageIOHeaderFactory() 28 | { 29 | this->RegisterOverride( "itkImageIOBase", 30 | "itkNiftiImageIOHeader", 31 | "Nifti Image IO", 32 | 1, 33 | CreateObjectFunction< NiftiImageIOHeader >::New() ); 34 | } 35 | 36 | NiftiImageIOHeaderFactory::~NiftiImageIOHeaderFactory() 37 | {} 38 | 39 | const char * 40 | NiftiImageIOHeaderFactory::GetITKSourceVersion(void) const 41 | { 42 | return ITK_SOURCE_VERSION; 43 | } 44 | 45 | const char * 46 | NiftiImageIOHeaderFactory::GetDescription() const 47 | { 48 | return "Nifti ImageIO Factory, allows the loading of Nifti images into insight"; 49 | } 50 | 51 | // Undocumented API used to register during static initialization. 52 | // DO NOT CALL DIRECTLY. 53 | 54 | static bool NiftiImageIOHeaderFactoryHasBeenRegistered; 55 | 56 | void NiftiImageIOHeaderFactoryRegister__Private(void) 57 | { 58 | if( ! NiftiImageIOHeaderFactoryHasBeenRegistered ) 59 | { 60 | NiftiImageIOHeaderFactoryHasBeenRegistered = true; 61 | NiftiImageIOHeaderFactory::RegisterOneFactory(); 62 | } 63 | } 64 | 65 | } // end namespace itk 66 | -------------------------------------------------------------------------------- /src/utilities/itkNiftiImageIOHeaderFactory.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #ifndef __itkNiftiImageIOHeaderFactory_h 19 | #define __itkNiftiImageIOHeaderFactory_h 20 | 21 | 22 | #include "itkObjectFactoryBase.h" 23 | #include "itkImageIOBase.h" 24 | 25 | namespace itk 26 | { 27 | /** \class NiftiImageIOHeaderFactory 28 | * \brief Create instances of NiftiImageIOHeader objects using an object factory. 29 | * \ingroup ITKIONIFTI 30 | */ 31 | class NiftiImageIOHeaderFactory:public ObjectFactoryBase 32 | { 33 | public: 34 | /** Standard class typedefs. */ 35 | typedef NiftiImageIOHeaderFactory Self; 36 | typedef ObjectFactoryBase Superclass; 37 | typedef SmartPointer< Self > Pointer; 38 | typedef SmartPointer< const Self > ConstPointer; 39 | 40 | /** Class methods used to interface with the registered factories. */ 41 | virtual const char * GetITKSourceVersion(void) const ITK_OVERRIDE; 42 | 43 | virtual const char * GetDescription(void) const ITK_OVERRIDE; 44 | 45 | /** Method for class instantiation. */ 46 | itkFactorylessNewMacro(Self); 47 | 48 | /** Run-time type information (and related methods). */ 49 | itkTypeMacro(NiftiImageIOHeaderFactory, ObjectFactoryBase); 50 | 51 | /** Register one factory of this type */ 52 | static void RegisterOneFactory(void) 53 | { 54 | NiftiImageIOHeaderFactory::Pointer metaFactory = NiftiImageIOHeaderFactory::New(); 55 | 56 | ObjectFactoryBase::RegisterFactoryInternal(metaFactory); 57 | } 58 | 59 | protected: 60 | NiftiImageIOHeaderFactory(); 61 | ~NiftiImageIOHeaderFactory(); 62 | virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; 63 | 64 | private: 65 | NiftiImageIOHeaderFactory(const Self &); //purposely not implemented 66 | void operator=(const Self &); //purposely not implemented 67 | }; 68 | } // end namespace itk 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/utilities/math_utilities.cxx: -------------------------------------------------------------------------------- 1 | #ifndef MATHUTILITIES_CXX 2 | #define MATHUTILITIES_CXX 3 | 4 | 5 | #include "math_utilities.h" 6 | #include "vnl/vnl_cross.h" 7 | 8 | bool SameSide(vnl_vector v1, vnl_vector v2, vnl_vector v3,vnl_vector v4, vnl_vector p) 9 | { 10 | vnl_vector normal = vnl_cross_3d(v2-v1,v3-v1); 11 | double dotv4 = dot_product(normal,v4-v1); 12 | double dotP = dot_product(normal,p-v1); 13 | return (sgn(dotv4) == sgn(dotP)); 14 | } 15 | 16 | bool PointInTetrahedron(vnl_vector v1, vnl_vector v2, vnl_vector v3,vnl_vector v4, vnl_vector p) 17 | { 18 | return SameSide(v1, v2, v3, v4, p) && 19 | SameSide(v2, v3, v4, v1, p) && 20 | SameSide(v3, v4, v1, v2, p) && 21 | SameSide(v4, v1, v2, v3, p); 22 | } 23 | 24 | int round50(float n2) 25 | { 26 | int n= (int)n2; 27 | int a = (n / 50) * 50; 28 | int b = a + 50; 29 | // Return of closest of two 30 | return (n - a > b - n)? b : a; 31 | } 32 | 33 | 34 | float median(std::vector &v2) 35 | { 36 | std::vector v=v2; 37 | size_t n = v.size() / 2; 38 | nth_element(v.begin(), v.begin()+n, v.end()); 39 | return v[n]; 40 | } 41 | 42 | float average(const EigenVecType& x, const EigenVecType& w) 43 | { 44 | return x.dot(w) / w.sum(); 45 | } 46 | 47 | 48 | double ComputeResidProb(double val, float mu, float sigma,int agg_level) 49 | { 50 | double norm_x= (val -mu)/sigma; 51 | if(agg_level==0) 52 | { 53 | norm_x-=1.4; 54 | norm_x/=0.6; 55 | } 56 | if(agg_level==1) 57 | { 58 | norm_x-=1.3; 59 | norm_x/=0.45; 60 | } 61 | if(agg_level==2) 62 | { 63 | norm_x-=1.2; 64 | norm_x/=0.35; 65 | } 66 | 67 | return 1- normalCDF_val(norm_x ); 68 | } 69 | 70 | 71 | 72 | 73 | EigenVecType gaussianCDF(const EigenVecType& x) 74 | { 75 | EigenVecType resp=x; 76 | for(int i=0;i &facts) 112 | { 113 | facts[0]=1; 114 | for(int i=1;i int sgn(T val) { 119 | return (T(0) < val) - (val < T(0)); 120 | } 121 | 122 | 123 | template int sgn(double val); 124 | template int sgn(float val); 125 | template int sgn(int val); 126 | 127 | 128 | 129 | #endif 130 | 131 | -------------------------------------------------------------------------------- /src/utilities/math_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHUTILITIES_H 2 | #define MATHUTILITIES_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "defines.h" 10 | 11 | int round50(float n2); 12 | 13 | void myfactorial(vnl_vector &facts); 14 | 15 | float median(std::vector &v2); 16 | 17 | float average(const EigenVecType& x, const EigenVecType& w); 18 | 19 | EigenVecType log_gaussian_skewed(const EigenVecType& x,float alpha,float mu , float sigma ); 20 | inline double normalCDF_val(double value) 21 | { 22 | if(value<-5) 23 | return 0; 24 | 25 | if(std::isnan(value) || std::isinf(value)) 26 | return 0; 27 | 28 | return 0.5 * erfc(-value * M_SQRT1_2); 29 | } 30 | 31 | double ComputeResidProb(double val, float mu, float sigma,int agg_level); 32 | 33 | 34 | bool SameSide(vnl_vector v1, vnl_vector v2, vnl_vector v3,vnl_vector v4, vnl_vector p); 35 | bool PointInTetrahedron(vnl_vector v1, vnl_vector v2, vnl_vector v3,vnl_vector v4, vnl_vector p); 36 | 37 | 38 | EigenVecType log_gaussian(const EigenVecType& x, float mu , float sigma); 39 | template int sgn(T val); 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/utilities/read_3Dvolume_from_4D.h: -------------------------------------------------------------------------------- 1 | #ifndef _READ3DVOLUMEFROM4D_H 2 | #define _READ3DVOLUMEFROM4D_H 3 | 4 | 5 | #include "defines.h" 6 | 7 | void onifti_swap_4bytes( size_t n , void *ar ) ; /* 4 bytes at a time */ 8 | 9 | 10 | ImageType3D::Pointer read_3D_volume_from_4D(std::string fname, int vol_id); 11 | ImageType3DBool::Pointer read_3D_volume_from_4DBool(std::string fname, int vol_id); 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/utilities/read_bmatrix_file.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _READBMATRIXFILE_CXX 2 | #define _READBMATRIXFILE_CXX 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "read_bmatrix_file.h" 10 | 11 | 12 | 13 | 14 | vnl_matrix read_bmatrix_file(std::string filename) 15 | { 16 | int nrows=0; 17 | 18 | std::ifstream infile(filename.c_str()); 19 | std::string line; 20 | while (std::getline(infile, line)) 21 | { 22 | line.erase(std::remove_if(line.begin(), line.end(), ::isspace),line.end()); 23 | if(line != std::string("")) 24 | nrows++; 25 | 26 | } 27 | infile.close(); 28 | 29 | vnl_matrix bmat(nrows,6); 30 | 31 | infile.open(filename.c_str()); 32 | infile>>bmat; 33 | infile.close(); 34 | 35 | return bmat; 36 | } 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /src/utilities/read_bmatrix_file.h: -------------------------------------------------------------------------------- 1 | #ifndef _READBMATRIXFILE_H 2 | #define _READBMATRIXFILE_H 3 | 4 | 5 | #include 6 | 7 | 8 | 9 | vnl_matrix read_bmatrix_file(std::string filename); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /src/utilities/write_bmatrix_file.cxx: -------------------------------------------------------------------------------- 1 | #ifndef _WRITE_BMATRIX_FILE_HXX 2 | #define _WRITE_BMATRIX_FILE_HXX 3 | 4 | #include 5 | #include 6 | #include 7 | #include "write_bmatrix_file.h" 8 | 9 | 10 | void write_bmatrix_file(std::string bmtxt_file,vnl_matrix rotated_bmatrix) 11 | { 12 | std::ofstream outfile(bmtxt_file.c_str()); 13 | outfile< rotated_bmatrix); 6 | 7 | 8 | #endif 9 | --------------------------------------------------------------------------------