22 #ifndef __milxRegistration_h 23 #define __milxRegistration_h 25 #include <itkLinearInterpolateImageFunction.h> 26 #include <itkBSplineInterpolateImageFunction.h> 27 #include <itkNearestNeighborInterpolateImageFunction.h> 29 #if ITK_VERSION_MAJOR < 4 30 #include <itkOrientedImage.h> 31 #include <itkOrientationAdapter.h> 34 #include <itkOrientationAdapterBase.h> 43 #include <itkOrientImageFilter.h> 80 typedef float InputPixelType;
81 typedef float OutputPixelType;
82 typedef itk::Vector<InputPixelType, 3 > VectorPixelType;
83 typedef itk::Image<VectorPixelType, 3 > DemonsDeformationFieldType;
85 typedef itk::Image<InputPixelType,3> InputImageType;
86 typedef itk::Image<OutputPixelType,3> OutputImageType;
89 typedef itk::NearestNeighborInterpolateImageFunction<InputImageType, double > NearestNeighborInterpolatorType;
90 typedef itk::LinearInterpolateImageFunction<InputImageType, double > LinearInterpolatorType;
91 typedef itk::BSplineInterpolateImageFunction<InputImageType, double, double > BsplineInterpolatorType;
94 typedef itk::Vector< float, 3 > VectorType;
95 #if ITK_VERSION_MAJOR < 4 96 typedef itk::OrientedImage< InputPixelType, 3> FixedImageType;
97 typedef itk::OrientedImage< InputPixelType, 3 > MovingImageType;
98 typedef itk::OrientedImage< VectorType, 3 > FieldType;
100 typedef itk::Image< InputPixelType, 3> FixedImageType;
101 typedef itk::Image< InputPixelType, 3 > MovingImageType;
102 typedef itk::Image< VectorType, 3 > FieldType;
105 typedef itk::NearestNeighborInterpolateImageFunction<FixedImageType, double > NearestNeighborOrientatedInterpolatorType;
106 typedef itk::LinearInterpolateImageFunction<FixedImageType, double > LinearOrientatedInterpolatorType;
107 typedef itk::BSplineInterpolateImageFunction<FixedImageType, double, double > BsplineOrientatedInterpolatorType;
118 ALADIN_MILXBSPLINE=8,
121 ITK_AFFINE_DIFFDEMONS=11,
122 ITKALADIN_DIFFDEMONS=12,
126 typedef enum { INTERP_NEAREST=0, INTERP_LINEAR=1, INTERP_BSPLINE=2, INTERP_BSPLINE5=3 } InterpolateMode;
127 typedef enum { VOTING=0, MULTISTAPLE=1 } ConsensusMode;
129 void writeFile3D(FixedImageType::Pointer image, std::string outputFileName);
130 FixedImageType::Pointer
readFile3D(std::string fileName);
146 return m_CaseFilenames.size();
149 int GetNumberOfCases2()
151 return m_CaseFilenames2.size();
154 int GetNumberOfAtlases()
156 return m_AtlasFilenames.size();
159 int GetNumberOfLabellings()
161 return m_LabellingFilenames.size();
164 std::vector<int> GetCaseIDs()
169 std::vector<std::string> GetCaseFileNames()
171 return m_CaseFilenames;
174 std::vector<std::string> GetCaseFileNames2()
176 return m_CaseFilenames2;
179 std::string GetCaseFileName(
int caseID)
183 if(m_CaseIDs[i] == caseID)
184 return m_CaseFilenames[i];
186 std::cerr <<
"Warning caseID " << caseID <<
" not found ?" <<std::endl;
190 std::string GetCaseFileName2(
int caseID)
192 if(m_CaseFilenames2.size() == m_CaseFilenames.size())
194 std::cerr <<
"Bailing as File2size != File1size" <<std::endl;
199 if(m_CaseIDs[i] == caseID)
200 return m_CaseFilenames2[i];
202 std::cerr <<
"Warning caseID " << caseID <<
" not found ?" <<std::endl;
206 std::vector<int> GetAtlasIDs()
210 std::vector<std::string> GetAtlasFileNames()
212 return m_AtlasFilenames;
214 std::string GetAtlasFileName(
int caseID)
216 for(
int i = 0; i < this->GetNumberOfAtlases(); i++)
219 return m_AtlasFilenames[i];
221 std::cerr <<
"Warning caseID " << caseID <<
" not found ?" <<std::endl;
225 std::vector<int> GetLabellingIDs()
227 return m_LabellingIDs;
229 std::vector<std::string> GetLabellingFileNames()
231 std::cout <<
"Get Labelled filenames " << m_LabellingFilenames.size() << std::endl;
232 return m_LabellingFilenames;
234 std::vector<std::string> GetLabellingFileNames(
int caseID)
236 std::vector<std::string> labellingNames;
237 for(
int i = 0; i < this->GetNumberOfLabellings(); i++)
239 if(m_LabellingIDs[i] == caseID)
240 labellingNames.push_back(m_LabellingFilenames[i]);
242 return labellingNames;
253 return m_PropagatedAtlases;
255 std::vector<std::string> GetPropagatedOutputTransforms()
257 return m_PropagatedTransforms;
261 for(
int i = 0; i < this->GetNumberOfAtlases(); i++)
264 return m_PropagatedAtlases[i];
266 std::cerr <<
"Warning caseID " << caseID <<
" not found when returning propagated atlases ?" <<std::endl;
270 std::vector<std::string> GetPropagatedOutputLabels()
272 return m_PropagatedLabelling;
274 std::vector<std::string> GetPropagatedOutputLabels(
int caseID)
276 std::vector<std::string> labellingNames;
277 for(
int i = 0; i < this->GetNumberOfLabellings(); i++)
279 if(m_LabellingIDs[i] == caseID)
280 labellingNames.push_back(m_PropagatedLabelling[i]);
282 return labellingNames;
284 bool ClearPropagatedOutputAtlasesLabels()
286 m_PropagatedAtlases.clear();
287 m_PropagatedLabelling.clear();
295 bool SetCase(
int caseID, std::string filenames)
297 std::vector<int> ids;
298 ids.push_back(caseID);
299 std::vector<std::string> caseFilenames;
300 caseFilenames.push_back(filenames);
301 return this->SetCases(ids, caseFilenames);
303 bool SetCases(std::vector<int> caseIDs, std::vector<std::string> caseFilenames)
306 m_CaseFilenames = caseFilenames;
309 bool SetCasePair(
int caseID, std::string filenames, std::string filenames2)
311 std::vector<int> ids;
312 ids.push_back(caseID);
313 std::vector<std::string> caseFilenames;
314 caseFilenames.push_back(filenames);
315 std::vector<std::string> caseFilenames2;
316 caseFilenames2.push_back(filenames2);
317 return this->SetCasesPair(ids, caseFilenames, caseFilenames2);
319 bool SetCasesPair(std::vector<int> caseIDs, std::vector<std::string> caseFilenames, std::vector<std::string> caseFilenames2)
322 m_CaseFilenames = caseFilenames;
323 m_CaseFilenames2 = caseFilenames2;
329 m_CaseFilenames.clear();
339 bool SetAtlases(std::vector<int> atlasIDs, std::vector<std::string> atlasFilenames)
342 m_AtlasFilenames = atlasFilenames;
345 bool SetAtlas(
int atlasIDs, std::string atlasFilenames)
348 m_AtlasFilenames.push_back(atlasFilenames);
352 bool SetAtlases(std::vector<int> atlasIDs, std::vector<std::string> atlasFilenames, std::vector<int> labellingIDs, std::vector<std::string> labellingFilenames)
355 m_AtlasFilenames = atlasFilenames;
356 m_LabellingIDs = labellingIDs;
357 m_LabellingFilenames = labellingFilenames;
358 std::cout <<
"Labelling filename " << m_LabellingFilenames.size() << std::endl;
364 std::vector<std::string> atlasFilenames,
365 std::vector<int> labellingIDs,
366 std::vector<std::string> labellingFilenames,
367 std::vector<int> maskIDs,
368 std::vector<std::string> maskFilenames)
371 m_AtlasFilenames = atlasFilenames;
372 m_LabellingIDs = labellingIDs;
373 m_LabellingFilenames = labellingFilenames;
374 std::cout <<
"Labelling filename " << m_LabellingFilenames.size() << std::endl;
377 m_MaskFilenames= maskFilenames;
378 std::cout <<
"Number of image masks used " << m_MaskFilenames.size() << std::endl;
384 std::vector<std::string> atlasFilenames,
385 std::vector<int> labellingIDs,
386 std::vector<std::string> labellingFilenames,
387 std::vector<int> maskIDs,
388 std::vector<std::string> maskFilenames,
389 std::vector<std::string> maskFilenames2)
392 m_AtlasFilenames = atlasFilenames;
393 m_LabellingIDs = labellingIDs;
394 m_LabellingFilenames = labellingFilenames;
395 std::cout <<
"Labelling filename " << m_LabellingFilenames.size() << std::endl;
398 m_MaskFilenames= maskFilenames;
399 m_MaskFilenames2= maskFilenames2;
400 std::cout <<
"Number of image masks used " << m_MaskFilenames.size() << std::endl;
401 std::cout <<
"Number of image masks2 used " << m_MaskFilenames2.size() << std::endl;
406 bool SetAtlas(
int atlasIDs, std::string atlasFilenames, std::vector<std::string> labellingFilenames)
409 m_AtlasFilenames.push_back(atlasFilenames);
410 for (
unsigned int i=0; i<labellingFilenames.size(); i++)
411 m_LabellingIDs.push_back(atlasIDs);
412 m_LabellingFilenames = labellingFilenames;
413 std::cout <<
"Labelling filename " << m_LabellingFilenames.size() <<
" " << m_LabellingIDs.size() << std::endl;
420 m_AtlasFilenames.clear();
421 m_LabellingIDs.clear();
422 m_LabellingFilenames.clear();
432 m_OutputPrefix = prefix;
434 std::string GetOutputPrefix()
436 return m_OutputPrefix;
445 m_RegistrationInterpolation = mode;
449 bool SetAtlasInterpolation(InterpolateMode mode)
451 m_AtlasInterpolation = mode;
455 bool SetLabelledImageInterpolation(InterpolateMode mode)
457 m_LabelledImageInterpolation = mode;
460 bool SetLabelledImageInterpolation(std::vector<InterpolateMode> modes)
462 m_MultipleLabelledImageInterpolation = modes;
472 m_UseConsensus = flag;
474 bool GetUseConsensus()
476 return m_UseConsensus;
484 std::cout <<
"milxRegistration::SetRegistrationModeSet " << registrationScheme << std::endl;
485 if(registrationScheme == 0)
487 RegistrationMode mode = ALADIN_RIGID;
490 else if(registrationScheme == 1)
492 RegistrationMode mode = ITK_RIGID;
495 else if(registrationScheme == 2)
497 RegistrationMode mode = ALADIN_AFFINE;
500 else if(registrationScheme == 3)
502 RegistrationMode mode = ITK_AFFINE;
505 else if(registrationScheme == 4)
507 RegistrationMode mode = ALADIN_DIFFDEMONS;
510 else if(registrationScheme == 5)
512 RegistrationMode mode = ITK_AFFINEBSPLINE;
515 else if(registrationScheme == 6)
517 RegistrationMode mode = ALIBABA_RIGID;
520 else if(registrationScheme == 7)
522 RegistrationMode mode = ALIBABA_AFFINE;
525 else if(registrationScheme == 8)
527 RegistrationMode mode = ALADIN_MILXBSPLINE;
530 else if(registrationScheme == 9)
532 RegistrationMode mode = NIFTI_REG;
535 else if(registrationScheme == 10)
537 RegistrationMode mode = NIFTI_ALADIN_REG;
540 else if(registrationScheme == 11)
542 RegistrationMode mode = ITK_AFFINE_DIFFDEMONS;
545 else if(registrationScheme == 12)
547 RegistrationMode mode = ITKALADIN_DIFFDEMONS;
550 else if(registrationScheme == 13)
552 RegistrationMode mode = DIFFDEMONS;
557 std::cerr <<
"Unknown registration mode: " << registrationScheme << std::endl;
566 m_RegistrationMode = registrationScheme;
569 RegistrationMode GetRegistrationMode()
571 return this->m_RegistrationMode;
579 std::cout <<
"Set Mode " << consensusScheme << std::endl;
580 if(consensusScheme == 0)
582 ConsensusMode mode = VOTING;
585 else if(consensusScheme == 1)
587 ConsensusMode mode = MULTISTAPLE;
595 m_ConsensusMode = consensusScheme;
598 ConsensusMode GetConsensusMode()
600 return this->m_ConsensusMode;
634 std::vector<std::string> m_AtlasFilenames;
635 std::vector<int> m_LabellingIDs;
636 std::vector<std::string> m_LabellingFilenames;
638 std::vector<int> m_MaskIDs;
639 std::vector<std::string> m_MaskFilenames;
640 std::vector<std::string> m_MaskFilenames2;
642 std::vector<int> m_CaseIDs;
643 std::vector<std::string> m_CaseFilenames;
644 std::vector<std::string> m_CaseFilenames2;
646 std::string m_OutputPrefix;
648 std::vector<std::string> m_PropagatedAtlases;
649 std::vector<std::string> m_PropagatedLabelling;
650 std::vector<std::string> m_PropagatedTransforms;
652 InterpolateMode m_RegistrationInterpolation;
653 InterpolateMode m_AtlasInterpolation;
654 InterpolateMode m_LabelledImageInterpolation;
655 std::vector<InterpolateMode> m_MultipleLabelledImageInterpolation;
657 RegistrationMode m_RegistrationMode;
660 ConsensusMode m_ConsensusMode;
667 LinearInterpolatorType::Pointer m_LinearInterpolator;
668 BsplineInterpolatorType::Pointer m_BsplineInterpolator;
670 NearestNeighborOrientatedInterpolatorType::Pointer m_NearestNeighborOrientatedInterpolator;
671 LinearOrientatedInterpolatorType::Pointer m_LinearOrientatedInterpolator;
672 BsplineOrientatedInterpolatorType::Pointer m_BsplineOrientatedInterpolator;
674 void Voting(std::vector<std::string> inputFilenames,
675 std::string outputFilename,
678 ConsensusMode consensusMode);
689 bool RegisterRigidITK(std::string dataFile, std::string atlasFile, std::string outputPrefix,
bool Invert, std::string dataMaskFile, std::string atlasMaskFile );
690 bool RegisterMilxNonRigid(std::string dataFile, std::string atlasFile, std::string outputName,
bool Invert);
691 bool RegisterAffineITK(std::string dataFile, std::string atlasFile, std::string outputPrefix,
bool Invert, std::string dataMaskFile, std::string atlasMaskFile );
692 bool RegisterNonRigidBsplineITK(std::string dataFile, std::string atlasFile, std::string outputPrefix,
bool Invert, std::string dataMaskFile, std::string atlasMaskFile );
693 double NmiITK(std::string dataFile, std::string atlasFile);
695 void LoadTRSF(std::string filename1, std::string filename2,
double * array,
bool invert);
696 void LoadTRSF(std::string filename,
double * array,
bool invert);
698 bool PropagateAffine(std::string dataFile,
700 std::string targetFile,
702 InterpolateMode mode,
703 itk::SpatialOrientation::ValidCoordinateOrientationFlags &flag,
704 itk::SpatialOrientationAdapter::DirectionType &dir);
706 bool PropagateITKRigid(std::string dataFile, std::string outFile, std::string targetFile, std::string transformFile, InterpolateMode mode);
707 bool PropagateITKAffine(std::string dataFile, std::string outFile, std::string targetFile, std::string transformFile, InterpolateMode mode);
708 bool PropagateITKAffineBspline(std::string inputImage, std::string targetFile, std::string outputFilename, std::string inputTransform, std::string inputBsplineTransform, InterpolateMode mode);
714 unsigned int StringToCharArray(std::string & cmdline,
char ** argument );
void writeFile3D(FixedImageType::Pointer image, std::string outputFileName)
NearestNeighborInterpolatorType::Pointer m_NearestNeighborInterpolator
void SetOutputPrefix(std::string prefix)
std::vector< std::string > GetPropagatedOutputAtlases()
FixedImageType::Pointer readFile3D(std::string fileName)
bool SetCase(int caseID, std::string filenames)
void SetUseConsensus(bool flag)
void SetFilesToSave(int value)
bool LoadSettings(std::string)
std::vector< int > m_AtlasIDs
bool SetAtlases(std::vector< int > atlasIDs, std::vector< std::string > atlasFilenames)
bool SetRegistrationMode(int registrationScheme, std::string configFilename="NULL")
bool RegisterRigidITK(std::string dataFile, std::string atlasFile, std::string outputPrefix, bool Invert, std::string dataMaskFile, std::string atlasMaskFile)
bool ConfigureRegistration(RegistrationMode, std::string)
bool SetConsensusMode(int consensusScheme, std::string configFilename="NULL")
bool SetRegistrationInterpolation(InterpolateMode mode)