Skip to content
Browse files

BUG: rm calls to 'exit' which were killing Slicer

  • Loading branch information...
1 parent ca3c6bc commit 80474833a463d9651371ca30acf3673d3d7a875a Kent Williams committed with hjmjohnson
Showing with 1,570 additions and 941 deletions.
  1. +2 −2 BRAINSABC/TestSuite/BlendImageFilterTest.cxx
  2. +9 −4 BRAINSABC/brainseg/AtlasRegistrationMethod.txx
  3. +563 −553 BRAINSABC/brainseg/BRAINSABC.cxx
  4. +0 −1 BRAINSABC/brainseg/BRAINSABCUtilities.h
  5. +8 −8 BRAINSABC/brainseg/BRAINSCleanMask.cxx
  6. +6 −9 BRAINSABC/brainseg/EMSegmentationFilter.txx
  7. +1 −1 BRAINSABC/brainseg/EMSplitPriorMST.h
  8. +1 −2 BRAINSABC/brainseg/GenerateLabelMapFromProbabilityMap.cxx
  9. +8 −9 BRAINSABC/brainseg/LLSBiasCorrector.txx
  10. +2 −4 BRAINSABC/brainseg/StandardizeMaskIntensity.h
  11. +3 −14 BRAINSCommonLib/BRAINSFitHelper.cxx
  12. +57 −99 BRAINSCommonLib/BRAINSFitHelperTemplate.hxx
  13. +1 −4 BRAINSCommonLib/DebugImageViewerClient.h
  14. +7 −25 BRAINSCommonLib/GenericTransformImage.cxx
  15. +6 −60 BRAINSCommonLib/Imgmath.h
  16. +1 −2 BRAINSCommonLib/ReadMask.h
  17. +2 −2 ...mmonLib/TestLargestForegroundFilledMaskImageFilter/TestLargestForegroundFilledMaskImageFilter.cxx
  18. +1 −1 BRAINSCommonLib/TestSuite/itkResampleInPlaceImageFilterTest.cxx
  19. +6 −6 BRAINSCommonLib/Test_FindCenterOfBrainFilter/FindCenterOfBrainCLP.cxx
  20. +1 −2 BRAINSCommonLib/genericRegistrationHelper.h
  21. +3 −6 BRAINSCommonLib/genericRegistrationHelper.hxx
  22. +2 −4 BRAINSCommonLib/itkBRAINSROIAutoImageFilter.h
  23. +1 −2 BRAINSCommonLib/itkDiffusionTensor3DReconstructionWithMaskImageFilter.hxx
  24. +1 −2 BRAINSCommonLib/itkFindCenterOfBrainFilter.hxx
  25. +1 −4 BRAINSCommonLib/itkIO.h
  26. +23 −88 BRAINSCommonLib/itkInverseConsistentLandmarks.hxx
  27. +1 −2 BRAINSCommonLib/itkOtsuHistogramMatchingImageFilter.hxx
  28. +40 −23 BRAINSFit/BRAINSFit.cxx
  29. +810 −0 BRAINSFit/BRAINSFit.cxx.orig
  30. +2 −2 BRAINSFit/TestSuite/makexfrmedImage.cxx
  31. +1 −0 CMakeFiles/cmake.check_cache
View
4 BRAINSABC/TestSuite/BlendImageFilterTest.cxx
@@ -46,9 +46,9 @@ int main(int, char * *)
{
std::cerr << "Expected " << blend << " found " << itBlend.Get()
<< std::endl;
- exit(1);
+ return EXIT_FAILURE;
}
}
- exit(0);
+ return EXIT_SUCCESS;
}
View
13 BRAINSABC/brainseg/AtlasRegistrationMethod.txx
@@ -150,7 +150,7 @@ AtlasRegistrationMethod<TOutputPixel, TProbabilityPixel>
muLogMacro(
<< "Failed to read transform file caused exception." << this->m_IntraSubjectTransformFileNames[i]
<< std::endl );
- exit(-1);
+ itkExceptionMacro(<< "Failed to read transform file " << this->m_IntraSubjectTransformFileNames[i]);
}
}
else if( m_ImageLinearTransformChoice == "Identity" )
@@ -371,7 +371,7 @@ AtlasRegistrationMethod<TOutputPixel, TProbabilityPixel>
{
muLogMacro(
<< "Failed to read transform file caused exception." << this->m_AtlasToSubjectTransformFileName << std::endl );
- exit(-1);
+ itkExceptionMacro(<< "Failed to read transform file " << this->m_AtlasToSubjectTransformFileName);
}
}
else if( m_AtlasLinearTransformChoice == "Identity" )
@@ -390,7 +390,11 @@ AtlasRegistrationMethod<TOutputPixel, TProbabilityPixel>
muLogMacro( << "m_IntraSubjectTransforms.size() = " << m_IntraSubjectTransforms.size() << std::endl );
muLogMacro(
<< "m_IntraSubjectOriginalImageList.size() = " << m_IntraSubjectOriginalImageList.size() << std::endl );
- exit(-1);
+ itkExceptionMacro(<< "ERROR: atlas and template image list sizes do not match. "
+ << "m_AtlasOriginalImageList.size() = " << m_AtlasOriginalImageList.size() << std::endl
+ << "m_IntraSubjectTransforms.size() = " << m_IntraSubjectTransforms.size() << std::endl
+ << "m_IntraSubjectOriginalImageList.size() = " << m_IntraSubjectOriginalImageList.size());
+
}
muLogMacro(<< "Registering all atlas images to first subject." << std::endl);
for( unsigned int atlasIter = 0; atlasIter < m_AtlasOriginalImageList.size(); atlasIter++ )
@@ -483,7 +487,8 @@ AtlasRegistrationMethod<TOutputPixel, TProbabilityPixel>
writer->SetFileName(fn.c_str() );
writer->Update();
muLogMacro( << __FILE__ << " " << __LINE__ << " " << std::endl );
- exit( -1 );
+ itkExceptionMacro(<< "Histogram match");
+
}
}
else
View
1,116 BRAINSABC/brainseg/BRAINSABC.cxx
@@ -93,7 +93,7 @@ static std::string GetStripedImageFileNameExtension(const std::string & ImageFil
size_t rfind_location = returnString.rfind(ExtensionsToRemove[s]);
if( ( rfind_location != std::string::npos )
&& ( rfind_location == ( returnString.size() - ExtensionsToRemove[s].size() ) )
- )
+ )
{
returnString.replace(rfind_location, ExtensionsToRemove[s].size(), "");
}
@@ -159,7 +159,7 @@ static std::vector<FloatImageType::Pointer> ResampleImageList(
if( resamplerInterpolatorType == "BSpline" )
{
typedef itk::BSplineInterpolateImageFunction<FloatImageType, double, double>
- SplineInterpolatorType;
+ SplineInterpolatorType;
// Spline interpolation, only available for input images, not
// atlas
@@ -171,16 +171,16 @@ static std::vector<FloatImageType::Pointer> ResampleImageList(
else if( resamplerInterpolatorType == "WindowedSinc" )
{
typedef itk::ConstantBoundaryCondition<FloatImageType>
- BoundaryConditionType;
+ BoundaryConditionType;
static const unsigned int WindowedSincHammingWindowRadius = 5;
typedef itk::Function::HammingWindowFunction<
WindowedSincHammingWindowRadius, double, double> WindowFunctionType;
typedef itk::WindowedSincInterpolateImageFunction
- <FloatImageType,
- WindowedSincHammingWindowRadius,
- WindowFunctionType,
- BoundaryConditionType,
- double> WindowedSincInterpolatorType;
+ <FloatImageType,
+ WindowedSincHammingWindowRadius,
+ WindowFunctionType,
+ BoundaryConditionType,
+ double> WindowedSincInterpolatorType;
WindowedSincInterpolatorType::Pointer windowInt
= WindowedSincInterpolatorType::New();
resampler->SetInterpolator(windowInt);
@@ -188,7 +188,7 @@ static std::vector<FloatImageType::Pointer> ResampleImageList(
else // Default to m_UseNonLinearInterpolation == "Linear"
{
typedef itk::LinearInterpolateImageFunction<FloatImageType, double>
- LinearInterpolatorType;
+ LinearInterpolatorType;
LinearInterpolatorType::Pointer linearInt
= LinearInterpolatorType::New();
resampler->SetInterpolator(linearInt);
@@ -223,9 +223,9 @@ static std::vector<FloatImageType::Pointer> ResampleImageList(
while( !maskIt.IsAtEnd() )
{
if( tmpIt.Get() == outsideFOVCode ) // Voxel came from outside
- // the original FOV during
- // registration, so
- // invalidate it.
+ // the original FOV during
+ // registration, so
+ // invalidate it.
{
maskIt.Set(0); // Set it as an invalid voxel in
// intraSubjectFOVIntersectionMask
@@ -246,7 +246,7 @@ static void RescaleFunctionLocal( std::vector<FloatImageType::Pointer> & localLi
for( unsigned int i = 0; i < localList.size(); i++ )
{
typedef itk::RescaleIntensityImageFilter<FloatImageType, FloatImageType>
- RescaleType;
+ RescaleType;
RescaleType::Pointer rescaler = RescaleType::New();
rescaler->SetOutputMinimum(1);
rescaler->SetOutputMaximum(MAX_IMAGE_OUTPUT_VALUE);
@@ -266,20 +266,20 @@ static void RescaleFunctionLocal( std::vector<FloatImageType::Pointer> & localLi
FloatImageType::IndexType ind;
// T.O.D.O. This could be done in-place using the -inplace flag of the
// rescaleImageIntensityFilter.
- {
+ {
#pragma omp parallel for
- for( long kk = 0; kk < (long)size[2]; kk++ )
+ for( long kk = 0; kk < (long)size[2]; kk++ )
+ {
+ for( long jj = 0; jj < (long)size[1]; jj++ )
{
- for( long jj = 0; jj < (long)size[1]; jj++ )
+ for( long ii = 0; ii < (long)size[0]; ii++ )
{
- for( long ii = 0; ii < (long)size[0]; ii++ )
- {
- const ProbabilityImageIndexType currIndex = {{ii, jj, kk}};
- tmp->SetPixel( currIndex, rImg->GetPixel(ind) );
- }
+ const ProbabilityImageIndexType currIndex = {{ii, jj, kk}};
+ tmp->SetPixel( currIndex, rImg->GetPixel(ind) );
}
}
}
+ }
#endif
}
}
@@ -327,12 +327,12 @@ static std::vector<bool> FindDuplicateImages(const std::vector<FloatImagePointer
class EmptyVectorException
{
- public:
- EmptyVectorException(const char* pStr = "The list of input images was empty. Nothing to averge.") :
- pMessage(pStr) {}
- const char * what() const {return pMessage;}
- private:
- const char * pMessage;
+public:
+ EmptyVectorException(const char* pStr = "The list of input images was empty. Nothing to averge.") :
+ pMessage(pStr) {}
+ const char * what() const {return pMessage;}
+private:
+ const char * pMessage;
};
// Take a list of coregistered images, all of the same type (T1,T2) and return the average image.
@@ -354,13 +354,13 @@ static FloatImageType::Pointer AverageImageList(
// Create an image iterator over the first image. Use that iterator to get an index into the other
// images, sum each of the voxel values and divide by the number of input images and set the output
// voxel at this index to that value.
-
+
// Duplicate the first input image to use as an output image.
- typedef itk::ImageDuplicator< FloatImageType > DuplicatorType;
- DuplicatorType::Pointer duplicator = DuplicatorType::New();
- duplicator->SetInputImage(inputImageList[0]);
- duplicator->Update();
- FloatImageType::Pointer averageImage = duplicator->GetOutput();
+ typedef itk::ImageDuplicator< FloatImageType > DuplicatorType;
+ DuplicatorType::Pointer duplicator = DuplicatorType::New();
+ duplicator->SetInputImage(inputImageList[0]);
+ duplicator->Update();
+ FloatImageType::Pointer averageImage = duplicator->GetOutput();
// Create an image iterator over the first image.
typedef itk::ImageRegionIterator< FloatImageType > ImageRegionIteratorType;
@@ -413,7 +413,7 @@ int main(int argc, char * *argv)
<< outputVolumes.size() << " names in output volumes list"
<< "OR it must be exactly 1, and be the template for writing files."
<< std::endl;
- exit(1);
+ return EXIT_FAILURE;
}
if( inputVolumeTypes.size() != inputVolumes.size() )
{
@@ -439,7 +439,7 @@ int main(int argc, char * *argv)
{
muLogMacro( << "ERROR: Commanline arguments are not valid." << std::endl );
GENERATE_ECHOARGS;
- exit(-1);
+ return EXIT_FAILURE;
}
AtlasDefinition atlasDefinitionParser;
try
@@ -451,7 +451,7 @@ int main(int argc, char * *argv)
muLogMacro( << "Error reading Atlas Definition from "
<< atlasDefinition
<< std::endl );
- exit(1);
+ return EXIT_FAILURE;
}
;
atlasDefinitionParser.DebugPrint();
@@ -476,15 +476,15 @@ int main(int argc, char * *argv)
if( !itksys::SystemTools::MakeDirectory( outputDir.c_str() ) )
{
muLogMacro( << "ERROR: Could not create requested output directory " << outputDir << std::endl );
- exit(-1);
+ return EXIT_FAILURE;
}
// Set up the logger
- {
- const std::string logfn = outputDir + defaultSuffix + ".log";
- ( mu::Log::GetInstance() )->EchoOn();
- ( mu::Log::GetInstance() )->SetOutputFileName( logfn.c_str() );
- }
+ {
+ const std::string logfn = outputDir + defaultSuffix + ".log";
+ ( mu::Log::GetInstance() )->EchoOn();
+ ( mu::Log::GetInstance() )->SetOutputFileName( logfn.c_str() );
+ }
// Set up suffix string for images
std::string fmt = outputFormat;
@@ -615,33 +615,33 @@ int main(int argc, char * *argv)
AtlasDefTable.add(currentRow, 2 + pwi, priorUseForBiasVector[pwi], "%d");
}
- { // Print out the ranges.
- currentRow++;
- for( unsigned int pwi = 0; pwi < PriorNames.size(); pwi++ )
+ { // Print out the ranges.
+ currentRow++;
+ for( unsigned int pwi = 0; pwi < PriorNames.size(); pwi++ )
+ {
+ std::map<std::string, AtlasDefinition::BoundsType> temp_range_List;
+ for( unsigned int tt = 0; tt < inputVolumeTypes.size(); tt++ )
{
- std::map<std::string, AtlasDefinition::BoundsType> temp_range_List;
- for( unsigned int tt = 0; tt < inputVolumeTypes.size(); tt++ )
- {
- AtlasDefTable.add(currentRow + tt * 2 + 0, 0, std::string(inputVolumeTypes[tt]) + std::string(" Lower") );
- AtlasDefTable.add(currentRow + tt * 2 + 0, 1, ": [");
- AtlasDefTable.add(currentRow + tt * 2 + 0, PriorNames.size() + 2 + 1, "]");
+ AtlasDefTable.add(currentRow + tt * 2 + 0, 0, std::string(inputVolumeTypes[tt]) + std::string(" Lower") );
+ AtlasDefTable.add(currentRow + tt * 2 + 0, 1, ": [");
+ AtlasDefTable.add(currentRow + tt * 2 + 0, PriorNames.size() + 2 + 1, "]");
- AtlasDefTable.add(currentRow + tt * 2 + 1, 0, std::string(inputVolumeTypes[tt]) + std::string(" Upper") );
- AtlasDefTable.add(currentRow + tt * 2 + 1, 1, ": [");
- AtlasDefTable.add(currentRow + tt * 2 + 1, PriorNames.size() + 2 + 1, "]");
+ AtlasDefTable.add(currentRow + tt * 2 + 1, 0, std::string(inputVolumeTypes[tt]) + std::string(" Upper") );
+ AtlasDefTable.add(currentRow + tt * 2 + 1, 1, ": [");
+ AtlasDefTable.add(currentRow + tt * 2 + 1, PriorNames.size() + 2 + 1, "]");
- temp_range_List[inputVolumeTypes[tt]] = atlasDefinitionParser.GetBounds(PriorNames[pwi], inputVolumeTypes[tt]);
- AtlasDefTable.add(currentRow + tt * 2 + 0, 2 + pwi, temp_range_List[inputVolumeTypes[tt]].GetLower(), "%4.2f");
- AtlasDefTable.add(currentRow + tt * 2 + 1, 2 + pwi, temp_range_List[inputVolumeTypes[tt]].GetUpper(), "%4.2f");
- }
+ temp_range_List[inputVolumeTypes[tt]] = atlasDefinitionParser.GetBounds(PriorNames[pwi], inputVolumeTypes[tt]);
+ AtlasDefTable.add(currentRow + tt * 2 + 0, 2 + pwi, temp_range_List[inputVolumeTypes[tt]].GetLower(), "%4.2f");
+ AtlasDefTable.add(currentRow + tt * 2 + 1, 2 + pwi, temp_range_List[inputVolumeTypes[tt]].GetUpper(), "%4.2f");
}
}
+ }
- {
- std::ostringstream oss;
- AtlasDefTable.Print(oss);
- muLogMacro( << oss.str() );
- }
+ {
+ std::ostringstream oss;
+ AtlasDefTable.Print(oss);
+ muLogMacro( << oss.str() );
+ }
muLogMacro(
<< "Max bias polynomial degree: " << maxBiasDegree << std::endl );
muLogMacro(<< "Atlas warping: " << !atlasWarpingOff << std::endl );
@@ -657,34 +657,34 @@ int main(int argc, char * *argv)
std::vector<FloatImagePointer> atlasOriginalImageList;
ByteImagePointer atlasBrainMask;
- { // Read template images needed for atlas registration
- // muLogMacro(<< "Read template mask");
- const std::string templateMask = atlasDefinitionParser.GetTemplateBrainMask();
- if( templateMask.size() < 1 )
- {
- muLogMacro( << "No template mask specified" << std::endl );
- exit(-1);
- }
- typedef itk::ImageFileReader<ByteImageType> ReaderType;
- typedef ReaderType::Pointer ReaderPointer;
- {
- muLogMacro( << "Reading mask : " << templateMask << "...\n");
+ { // Read template images needed for atlas registration
+ // muLogMacro(<< "Read template mask");
+ const std::string templateMask = atlasDefinitionParser.GetTemplateBrainMask();
+ if( templateMask.size() < 1 )
+ {
+ muLogMacro( << "No template mask specified" << std::endl );
+ return EXIT_FAILURE;
+ }
+ typedef itk::ImageFileReader<ByteImageType> ReaderType;
+ typedef ReaderType::Pointer ReaderPointer;
- ReaderPointer imgreader = ReaderType::New();
- imgreader->SetFileName( templateMask.c_str() );
+ muLogMacro( << "Reading mask : " << templateMask << "...\n");
- try
- {
- imgreader->Update();
- }
- catch( ... )
- {
- muLogMacro( << "ERROR: Could not read image " << templateMask << "." << std::endl );
- exit(-1);
- }
- atlasBrainMask = imgreader->GetOutput();
- }
+ ReaderPointer imgreader = ReaderType::New();
+ imgreader->SetFileName( templateMask.c_str() );
+
+ try
+ {
+ imgreader->Update();
+ }
+ catch( ... )
+ {
+ muLogMacro( << "ERROR: Could not read image " << templateMask << "." << std::endl );
+ return EXIT_FAILURE;
}
+ atlasBrainMask = imgreader->GetOutput();
+
+ }
std::vector<FloatImagePointer> intraSubjectRegisteredImageList;
std::vector<FloatImagePointer> intraSubjectRegisteredRawImageList;
@@ -708,387 +708,397 @@ int main(int argc, char * *argv)
}
std::vector<bool> duplicatesFound;
+ {
+ typedef AtlasRegistrationMethod<float, float> AtlasRegType;
+ AtlasRegType::Pointer atlasreg = AtlasRegType::New();
+
+ if( debuglevel > 0 )
{
- typedef AtlasRegistrationMethod<float, float> AtlasRegType;
- AtlasRegType::Pointer atlasreg = AtlasRegType::New();
+ atlasreg->DebugOn();
+ atlasreg->SetDebugLevel(debuglevel);
+ }
- if( debuglevel > 0 )
- {
- atlasreg->DebugOn();
- atlasreg->SetDebugLevel(debuglevel);
- }
+ atlasreg->SetSuffix(defaultSuffix);
+ // Compute list of file names for the atlasOriginalPriors
+ for( unsigned int q = 0; q < PriorNames.size(); q++ )
+ {
+ priorfnlist.push_back( atlasDefinitionParser.GetPriorFilename( PriorNames[q] ) );
+ }
+ {
+ std::vector<FloatImagePointer> intraSubjectRawImageList;
+ intraSubjectRawImageList.clear();
+ intraSubjectRawImageList.resize(inputVolumes.size(), 0);
+ std::vector<FloatImagePointer> intraSubjectNoiseRemovedImageList;
+ intraSubjectNoiseRemovedImageList.clear();
+ intraSubjectNoiseRemovedImageList.resize(inputVolumes.size(), 0);
+ { // StartOriginalImagesList
+ const std::string suffixstr = "";
+ { // Read subject images needed for atlas registration
+ // muLogMacro(<< "Read subject images");
+ if( inputVolumes.size() < 1 )
+ {
+ muLogMacro( << "No data images specified" << std::endl );
+ return EXIT_FAILURE;
+ }
- atlasreg->SetSuffix(defaultSuffix);
- // Compute list of file names for the atlasOriginalPriors
- for( unsigned int q = 0; q < PriorNames.size(); q++ )
+ typedef itk::ImageFileReader<FloatImageType> ReaderType;
+ typedef ReaderType::Pointer ReaderPointer;
+
+ std::vector<std::string> intraSubjectTransformFileNames( inputVolumes.size() );
+ for( unsigned int i = 0; i < inputVolumes.size(); i++ )
+ {
+ muLogMacro(
+ << "Reading image " << i + 1 << ": " << inputVolumes[i] << "...\n");
+
+ ReaderPointer imgreader = ReaderType::New();
+ imgreader->SetFileName( inputVolumes[i].c_str() );
+
+ try
{
- priorfnlist.push_back( atlasDefinitionParser.GetPriorFilename( PriorNames[q] ) );
+ imgreader->Update();
}
+ catch( ... )
{
- std::vector<FloatImagePointer> intraSubjectRawImageList;
- intraSubjectRawImageList.clear();
- intraSubjectRawImageList.resize(inputVolumes.size(), 0);
- std::vector<FloatImagePointer> intraSubjectNoiseRemovedImageList;
- intraSubjectNoiseRemovedImageList.clear();
- intraSubjectNoiseRemovedImageList.resize(inputVolumes.size(), 0);
- { // StartOriginalImagesList
- const std::string suffixstr = "";
- { // Read subject images needed for atlas registration
- // muLogMacro(<< "Read subject images");
- if( inputVolumes.size() < 1 )
- {
- muLogMacro( << "No data images specified" << std::endl );
- exit(-1);
- }
-
- typedef itk::ImageFileReader<FloatImageType> ReaderType;
- typedef ReaderType::Pointer ReaderPointer;
-
- std::vector<std::string> intraSubjectTransformFileNames( inputVolumes.size() );
- for( unsigned int i = 0; i < inputVolumes.size(); i++ )
- {
- muLogMacro(
- << "Reading image " << i + 1 << ": " << inputVolumes[i] << "...\n");
-
- ReaderPointer imgreader = ReaderType::New();
- imgreader->SetFileName( inputVolumes[i].c_str() );
-
- try
- {
- imgreader->Update();
- }
- catch( ... )
- {
- muLogMacro( << "ERROR: Could not read image " << inputVolumes[i] << "." << std::endl );
- exit(-1);
- }
- // Initialize with file read in
- FloatImageType::Pointer typewiseEqualizedToFirstImage = imgreader->GetOutput();
+ muLogMacro( << "ERROR: Could not read image " << inputVolumes[i] << "." << std::endl );
+ return EXIT_FAILURE;
+ }
+ // Initialize with file read in
+ FloatImageType::Pointer typewiseEqualizedToFirstImage = imgreader->GetOutput();
#if 0 // This needs more testing.
// Now go looking to see if this image type has already been found,
// and equalize to the first image of this type if found.
- for( unsigned int prevImageIndex = 0; prevImageIndex < i; prevImageIndex++ )
- {
- if( inputVolumeTypes[i] == inputVolumeTypes[prevImageIndex] )
- // If it matches a previous found image type,
- // then histogram equalize
- {
- muLogMacro( << "Equalizing image (" << i << ") to image (" << prevImageIndex << ")" << std::endl );
- typedef itk::HistogramMatchingImageFilter<FloatImageType,
- FloatImageType> HistogramMatchingFilterType;
- HistogramMatchingFilterType::Pointer histogramfilter
- = HistogramMatchingFilterType::New();
-
- histogramfilter->SetInput( imgreader->GetOutput() );
- histogramfilter->SetReferenceImage( intraSubjectNoiseRemovedImageList[prevImageIndex] );
-
- histogramfilter->SetNumberOfHistogramLevels( 128 );
- histogramfilter->SetNumberOfMatchPoints( 16 );
- // histogramfilter->ThresholdAtMeanIntensityOn();
- histogramfilter->Update();
- // Overwrite if necessary.
- typewiseEqualizedToFirstImage = histogramfilter->GetOutput();
- break;
- }
- }
+ for( unsigned int prevImageIndex = 0; prevImageIndex < i; prevImageIndex++ )
+ {
+ if( inputVolumeTypes[i] == inputVolumeTypes[prevImageIndex] )
+ // If it matches a previous found image type,
+ // then histogram equalize
+ {
+ muLogMacro( << "Equalizing image (" << i << ") to image (" << prevImageIndex << ")" << std::endl );
+ typedef itk::HistogramMatchingImageFilter<FloatImageType,
+ FloatImageType> HistogramMatchingFilterType;
+ HistogramMatchingFilterType::Pointer histogramfilter
+ = HistogramMatchingFilterType::New();
+
+ histogramfilter->SetInput( imgreader->GetOutput() );
+ histogramfilter->SetReferenceImage( intraSubjectNoiseRemovedImageList[prevImageIndex] );
+
+ histogramfilter->SetNumberOfHistogramLevels( 128 );
+ histogramfilter->SetNumberOfMatchPoints( 16 );
+ // histogramfilter->ThresholdAtMeanIntensityOn();
+ histogramfilter->Update();
+ // Overwrite if necessary.
+ typewiseEqualizedToFirstImage = histogramfilter->GetOutput();
+ break;
+ }
+ }
#endif
- // Normalize Image Intensities:
- muLogMacro( << "Standardizing Intensities: ...\n" );
- intraSubjectRawImageList[i] = StandardizeMaskIntensity<FloatImageType, ByteImageType>(
- typewiseEqualizedToFirstImage,
- NULL,
- 0.0005, 1.0 - 0.0005,
- 1, 0.95 * MAX_IMAGE_OUTPUT_VALUE,
- 0, MAX_IMAGE_OUTPUT_VALUE);
- muLogMacro( << "done.\n" );
+ // Normalize Image Intensities:
+ muLogMacro( << "Standardizing Intensities: ...\n" );
+ intraSubjectRawImageList[i] = StandardizeMaskIntensity<FloatImageType, ByteImageType>(
+ typewiseEqualizedToFirstImage,
+ NULL,
+ 0.0005, 1.0 - 0.0005,
+ 1, 0.95 * MAX_IMAGE_OUTPUT_VALUE,
+ 0, MAX_IMAGE_OUTPUT_VALUE);
+ muLogMacro( << "done.\n" );
#if 1
- {
- std::vector<unsigned int> unused_gridSize;
- intraSubjectNoiseRemovedImageList[i] =
- DenoiseFiltering<FloatImageType>(intraSubjectRawImageList[i], filterMethod, filterIteration,
- filterTimeStep,
- unused_gridSize);
- if( debuglevel > 1 )
- {
- // DEBUG: This code is for debugging purposes only;
- typedef itk::ImageFileWriter<FloatImageType> WriterType;
- WriterType::Pointer writer = WriterType::New();
- writer->UseCompressionOn();
-
- std::stringstream template_index_stream("");
- template_index_stream << i;
- const std::string fn = outputDir + "/DENOISED_INDEX_" + template_index_stream.str() + ".nii.gz";
- writer->SetInput(intraSubjectNoiseRemovedImageList[i]);
- writer->SetFileName(fn.c_str() );
- writer->Update();
- muLogMacro( << "DEBUG: Wrote image " << fn << std::endl);
- }
- }
+ {
+ std::vector<unsigned int> unused_gridSize;
+ intraSubjectNoiseRemovedImageList[i] =
+ DenoiseFiltering<FloatImageType>(intraSubjectRawImageList[i], filterMethod, filterIteration,
+ filterTimeStep,
+ unused_gridSize);
+ if( debuglevel > 1 )
+ {
+ // DEBUG: This code is for debugging purposes only;
+ typedef itk::ImageFileWriter<FloatImageType> WriterType;
+ WriterType::Pointer writer = WriterType::New();
+ writer->UseCompressionOn();
+
+ std::stringstream template_index_stream("");
+ template_index_stream << i;
+ const std::string fn = outputDir + "/DENOISED_INDEX_" + template_index_stream.str() + ".nii.gz";
+ writer->SetInput(intraSubjectNoiseRemovedImageList[i]);
+ writer->SetFileName(fn.c_str() );
+ writer->Update();
+ muLogMacro( << "DEBUG: Wrote image " << fn << std::endl);
+ }
+ }
#else
- intraSubjectNoiseRemovedImageList[i] = intraSubjectRawImageList[i];
+ intraSubjectNoiseRemovedImageList[i] = intraSubjectRawImageList[i];
#endif
- intraSubjectTransformFileNames[i] = outputDir
- + GetStripedImageFileNameExtension(inputVolumes[i]) + std::string(
- "_to_")
- + GetStripedImageFileNameExtension(inputVolumes[0]) + suffixstr
- + std::string(".mat");
- }
- atlasreg->SetIntraSubjectOriginalImageList(intraSubjectNoiseRemovedImageList);
- atlasreg->SetIntraSubjectTransformFileNames(intraSubjectTransformFileNames);
- }
-
- { // Read template images needed for atlas registration
- // muLogMacro(<< "Read template images");
- if( templateVolumes.size() < 1 )
- {
- muLogMacro( << "No data images specified" << std::endl );
- exit(-1);
- }
-
- typedef itk::ImageFileReader<FloatImageType> ReaderType;
- typedef ReaderType::Pointer ReaderPointer;
-
- atlasOriginalImageList.clear();
- atlasOriginalImageList.resize(templateVolumes.size(), 0);
- for( unsigned int atlasIndex = 0; atlasIndex < templateVolumes.size(); atlasIndex++ )
- {
- //KENT: HACK: This currently just checks one previous location in the list to
- // determine if the image was already loaded, It should check the
- // entire list and avoid loading duplicate images into the list
- // of atlas images.
- if( ( atlasIndex > 0 ) && ( templateVolumes[atlasIndex] == templateVolumes[atlasIndex - 1] ) )
- { // If they are the same name, then just use same reference
- muLogMacro(
- << "Referencing previous image " << atlasIndex + 1 << ": " << templateVolumes[atlasIndex] << "...\n");
- atlasOriginalImageList[atlasIndex] = atlasOriginalImageList[atlasIndex - 1];
- }
- else
- {
- muLogMacro(
- << "Reading image " << atlasIndex + 1 << ": " << templateVolumes[atlasIndex] << "...\n");
-
- ReaderPointer imgreader = ReaderType::New();
- imgreader->SetFileName( templateVolumes[atlasIndex].c_str() );
-
- try
- {
- imgreader->Update();
- }
- catch( ... )
- {
- muLogMacro( << "ERROR: Could not read image " << templateVolumes[atlasIndex] << "." << std::endl );
- exit(-1);
- }
-
- muLogMacro( << "Standardizing Intensities: ..." );
- FloatImagePointer img_i = StandardizeMaskIntensity<FloatImageType, ByteImageType>(
- imgreader->GetOutput(),
- atlasBrainMask,
- 0.0005, 1.0 - 0.0005,
- 1, 0.95 * MAX_IMAGE_OUTPUT_VALUE,
- 0, MAX_IMAGE_OUTPUT_VALUE);
- muLogMacro( << "done." << std::endl );
- atlasOriginalImageList[atlasIndex] = img_i;
- if( debuglevel > 7 )
- {
- typedef itk::ImageFileWriter<FloatImageType> FloatWriterType;
- FloatWriterType::Pointer writer = FloatWriterType::New();
-
- std::stringstream write_atlas_index_stream("");
- write_atlas_index_stream << atlasIndex;
- const std::string fn
- = outputDir + std::string("RenormalizedAtlasTemplate_") + write_atlas_index_stream.str() + suffstr;
-
- writer->SetInput(atlasOriginalImageList[atlasIndex] );
- writer->SetFileName( fn.c_str() );
- writer->UseCompressionOn();
- writer->Update();
- }
- }
- }
- atlasreg->SetAtlasOriginalImageList(atlasOriginalImageList);
- atlasreg->SetInputVolumeTypes(inputVolumeTypes);
- const std::string atlasTransformFileName = outputDir
- + GetStripedImageFileNameExtension(templateVolumes[0])
- + std::string("_to_")
- + GetStripedImageFileNameExtension(inputVolumes[0]) + suffixstr
- + std::string("PreSegmentation.mat");
- atlasreg->SetAtlasToSubjectTransformFileName(atlasTransformFileName);
- }
+ intraSubjectTransformFileNames[i] = outputDir
+ + GetStripedImageFileNameExtension(inputVolumes[i]) + std::string(
+ "_to_")
+ + GetStripedImageFileNameExtension(inputVolumes[0]) + suffixstr
+ + std::string(".mat");
+ }
+ atlasreg->SetIntraSubjectOriginalImageList(intraSubjectNoiseRemovedImageList);
+ atlasreg->SetIntraSubjectTransformFileNames(intraSubjectTransformFileNames);
+ }
- // atlasreg->SetOutputDebugDir(outputDir);
+ { // Read template images needed for atlas registration
+ // muLogMacro(<< "Read template images");
+ if( templateVolumes.size() < 1 )
+ {
+ muLogMacro( << "No data images specified" << std::endl );
+ return EXIT_FAILURE;
+ }
- if( !( ( atlasToSubjectTransformType.compare("Identity") == 0 )
- || ( atlasToSubjectTransformType.compare("Rigid") == 0 )
- || ( atlasToSubjectTransformType.compare("Affine") == 0 )
- || ( atlasToSubjectTransformType.compare("BSpline") == 0 ) )
- )
- {
- muLogMacro(
- "ERROR: Invalid atlasToSubjectTransformType specified" << atlasToSubjectTransformType << std::endl);
- exit(-1);
- }
+ typedef itk::ImageFileReader<FloatImageType> ReaderType;
+ typedef ReaderType::Pointer ReaderPointer;
- if( !( ( subjectIntermodeTransformType.compare("Identity") == 0 )
- || ( subjectIntermodeTransformType.compare("Rigid") == 0 )
- || ( subjectIntermodeTransformType.compare("Affine") == 0 )
- || ( subjectIntermodeTransformType.compare("BSpline") == 0 ) )
- )
- {
- muLogMacro(
- "ERROR: Invalid subjectIntermodeTransformType specified" << subjectIntermodeTransformType << std::endl);
- exit(-1);
- }
+ atlasOriginalImageList.clear();
+ atlasOriginalImageList.resize(templateVolumes.size(), 0);
+ for( unsigned int atlasIndex = 0; atlasIndex < templateVolumes.size(); atlasIndex++ )
+ {
+ //KENT: HACK: This currently just checks one previous location in the list to
+ // determine if the image was already loaded, It should check the
+ // entire list and avoid loading duplicate images into the list
+ // of atlas images.
+ if( ( atlasIndex > 0 ) && ( templateVolumes[atlasIndex] == templateVolumes[atlasIndex - 1] ) )
+ { // If they are the same name, then just use same reference
+ muLogMacro(
+ << "Referencing previous image " << atlasIndex + 1 << ": " << templateVolumes[atlasIndex] << "...\n");
+ atlasOriginalImageList[atlasIndex] = atlasOriginalImageList[atlasIndex - 1];
+ }
+ else
+ {
+ muLogMacro(
+ << "Reading image " << atlasIndex + 1 << ": " << templateVolumes[atlasIndex] << "...\n");
- atlasreg->SetAtlasLinearTransformChoice(atlasToSubjectTransformType);
- atlasreg->SetImageLinearTransformChoice(subjectIntermodeTransformType);
-
- atlasreg->SetWarpGrid(
- gridSize[0],
- gridSize[1],
- gridSize[2]);
- muLogMacro(<< "Registering and resampling images..." << std::endl);
- // EMSTimer* regtimer = new EMSTimer();
- // muLogMacro(<< "Registration took " <<
- // regtimer->GetElapsedHours() << " hours, ");
- // muLogMacro(<< regtimer->GetElapsedMinutes() << " minutes, ");
- // muLogMacro(<< regtimer->GetElapsedSeconds() << " seconds\n");
- // delete regtimer;
- itk::TimeProbe regtimer;
- regtimer.Start();
- atlasreg->SetOutputDebugDir(outputDir);
- atlasreg->Update();
- regtimer.Stop();
- itk::RealTimeClock::TimeStampType elapsedTime
- = regtimer.GetTotal();
- muLogMacro(<< "Registration took " << elapsedTime << " " << regtimer.GetUnit() << std::endl);
-
- std::vector<GenericTransformType::Pointer> intraSubjectTransforms = atlasreg->GetIntraSubjectTransforms();
-
- // ::ResampleImages()
- {
- // muLogMacro(<< "ResampleImages");
-
- // Define the internal reader type
- typedef itk::ResampleImageFilter<FloatImageType, FloatImageType> ResampleType;
- typedef ResampleType::Pointer ResamplePointer;
-
- intraSubjectRegisteredImageList =
- ResampleImageList(resamplerInterpolatorType, intraSubjectNoiseRemovedImageList,
- intraSubjectTransforms);
- intraSubjectRegisteredRawImageList = ResampleImageList(resamplerInterpolatorType, intraSubjectRawImageList,
- intraSubjectTransforms);
- assert( intraSubjectRegisteredImageList.size() == intraSubjectNoiseRemovedImageList.size() );
- assert( intraSubjectRegisteredImageList.size() == intraSubjectRawImageList.size() );
- intraSubjectNoiseRemovedImageList.clear();
- intraSubjectRawImageList.clear();
- } // End registering data
+ ReaderPointer imgreader = ReaderType::New();
+ imgreader->SetFileName( templateVolumes[atlasIndex].c_str() );
- {
- // Now check that the intraSubjectNoiseRemovedImageList has positive
- // definite covariance matrix.
- // The algorithm is not stable if the covariance matrix is not
- // positive definite, and this
- // occurs when two or more of the images are linearly dependant (i.e.
- // nearly the same image).
- duplicatesFound = FindDuplicateImages(intraSubjectRegisteredImageList);
- for( size_t q = 0; q < duplicatesFound.size(); q++ )
- {
- if( duplicatesFound[q] == true )
- {
- std::cout << "WARNING: Found images that were very highly correlated." << std::endl;
- std::cout << "WARNING: Removing image " << inputVolumes[q] << " from further processing" << std::endl;
- std::cout << "WARNING:" << std::endl;
- }
- }
- }
- } // EndOriginalImagesList
-
- atlasToSubjectPreSegmentationTransform = atlasreg->GetAtlasToSubjectTransform();
- if( debuglevel > 9 )
- { // NOTE THIS IS REALLY ANNOYING FOR LARGE BSPLINE REGISTRATIONS!
- muLogMacro( << __FILE__ << " " << __LINE__ << " " << atlasToSubjectPreSegmentationTransform->GetFixedParameters(
- ) << std::endl );
- muLogMacro(
- << __FILE__ << " " << __LINE__ << " " << atlasToSubjectPreSegmentationTransform->GetParameters() << std::endl );
+ try
+ {
+ imgreader->Update();
}
- if( debuglevel > 4 )
+ catch( ... )
{
- // Write the registered template and images
- if( !writeLess )
- {
- muLogMacro(<< "Writing registered template...\n");
-
- typedef itk::ResampleImageFilter<FloatImageType, FloatImageType> ResampleType;
- typedef ResampleType::Pointer ResamplePointer;
- ResamplePointer resampler = ResampleType::New();
-
- resampler->SetInput(atlasOriginalImageList[0]);
- resampler->SetTransform(atlasToSubjectPreSegmentationTransform);
-
- resampler->SetOutputParametersFromImage(intraSubjectRegisteredRawImageList[0]);
- resampler->SetDefaultPixelValue(0);
- resampler->Update();
- typedef itk::CastImageFilter<FloatImageType, ShortImageType>
- ShortRescaleType;
- ShortRescaleType::Pointer rescaler = ShortRescaleType::New();
- rescaler->SetInput( resampler->GetOutput() );
- rescaler->Update();
-
- typedef itk::ImageFileWriter<ShortImageType> ShortWriterType;
- ShortWriterType::Pointer writer = ShortWriterType::New();
-
- std::string fn
- = outputDir + std::string("AtlasToSubjectInitialization_") + suffstr;
-
- writer->SetInput( rescaler->GetOutput() );
- writer->SetFileName( fn.c_str() );
- writer->UseCompressionOn();
- writer->Update();
- }
- for( unsigned int i = 0; i < intraSubjectRegisteredRawImageList.size(); i++ )
- {
- typedef itk::RescaleIntensityImageFilter<FloatImageType, ShortImageType>
- ShortRescaleType;
-
- ShortRescaleType::Pointer rescaler = ShortRescaleType::New();
- rescaler->SetOutputMinimum(0);
- rescaler->SetOutputMaximum(MAX_IMAGE_OUTPUT_VALUE);
- rescaler->SetInput(intraSubjectRegisteredRawImageList[i]);
- rescaler->Update();
-
- std::string fn
- = outputDir + GetStripedImageFileNameExtension( ( inputVolumes[i] ) )
- + std::string("_registered") + suffstr;
-
- typedef itk::ImageFileWriter<ShortImageType> ShortWriterType;
- ShortWriterType::Pointer writer = ShortWriterType::New();
-
- writer->SetInput( rescaler->GetOutput() );
- writer->SetFileName( fn.c_str() );
- writer->UseCompressionOn();
- writer->Update();
- }
+ muLogMacro( << "ERROR: Could not read image " << templateVolumes[atlasIndex] << "." << std::endl );
+ return EXIT_FAILURE;
+ }
+
+ muLogMacro( << "Standardizing Intensities: ..." );
+ FloatImagePointer img_i = StandardizeMaskIntensity<FloatImageType, ByteImageType>(
+ imgreader->GetOutput(),
+ atlasBrainMask,
+ 0.0005, 1.0 - 0.0005,
+ 1, 0.95 * MAX_IMAGE_OUTPUT_VALUE,
+ 0, MAX_IMAGE_OUTPUT_VALUE);
+ muLogMacro( << "done." << std::endl );
+ atlasOriginalImageList[atlasIndex] = img_i;
+ if( debuglevel > 7 )
+ {
+ typedef itk::ImageFileWriter<FloatImageType> FloatWriterType;
+ FloatWriterType::Pointer writer = FloatWriterType::New();
+
+ std::stringstream write_atlas_index_stream("");
+ write_atlas_index_stream << atlasIndex;
+ const std::string fn
+ = outputDir + std::string("RenormalizedAtlasTemplate_") + write_atlas_index_stream.str() + suffstr;
+
+ writer->SetInput(atlasOriginalImageList[atlasIndex] );
+ writer->SetFileName( fn.c_str() );
+ writer->UseCompressionOn();
+ writer->Update();
}
}
- } // end atlas reg block
+ }
+ atlasreg->SetAtlasOriginalImageList(atlasOriginalImageList);
+ atlasreg->SetInputVolumeTypes(inputVolumeTypes);
+ const std::string atlasTransformFileName = outputDir
+ + GetStripedImageFileNameExtension(templateVolumes[0])
+ + std::string("_to_")
+ + GetStripedImageFileNameExtension(inputVolumes[0]) + suffixstr
+ + std::string("PreSegmentation.mat");
+ atlasreg->SetAtlasToSubjectTransformFileName(atlasTransformFileName);
+ }
+
+ // atlasreg->SetOutputDebugDir(outputDir);
+
+ if( !( ( atlasToSubjectTransformType.compare("Identity") == 0 )
+ || ( atlasToSubjectTransformType.compare("Rigid") == 0 )
+ || ( atlasToSubjectTransformType.compare("Affine") == 0 )
+ || ( atlasToSubjectTransformType.compare("BSpline") == 0 ) )
+ )
+ {
+ muLogMacro(
+ "ERROR: Invalid atlasToSubjectTransformType specified" << atlasToSubjectTransformType << std::endl);
+ return EXIT_FAILURE;
+ }
+ if( !( ( subjectIntermodeTransformType.compare("Identity") == 0 )
+ || ( subjectIntermodeTransformType.compare("Rigid") == 0 )
+ || ( subjectIntermodeTransformType.compare("Affine") == 0 )
+ || ( subjectIntermodeTransformType.compare("BSpline") == 0 ) )
+ )
{
- // Now based on the duplicates found, update input lists to only use unique
- // images
- intraSubjectRegisteredImageList = RemoveDuplicates(intraSubjectRegisteredImageList, duplicatesFound);
- intraSubjectRegisteredRawImageList = RemoveDuplicates(intraSubjectRegisteredRawImageList, duplicatesFound);
- inputVolumes = RemoveDuplicates(inputVolumes, duplicatesFound);
- inputVolumeTypes = RemoveDuplicates(inputVolumeTypes, duplicatesFound);
+ muLogMacro(
+ "ERROR: Invalid subjectIntermodeTransformType specified" << subjectIntermodeTransformType << std::endl);
+ return EXIT_FAILURE;
}
- muLogMacro(<< "Rescale intensity of filtered images...\n");
+ atlasreg->SetAtlasLinearTransformChoice(atlasToSubjectTransformType);
+ atlasreg->SetImageLinearTransformChoice(subjectIntermodeTransformType);
+
+ atlasreg->SetWarpGrid(
+ gridSize[0],
+ gridSize[1],
+ gridSize[2]);
+ muLogMacro(<< "Registering and resampling images..." << std::endl);
+ // EMSTimer* regtimer = new EMSTimer();
+ // muLogMacro(<< "Registration took " <<
+ // regtimer->GetElapsedHours() << " hours, ");
+ // muLogMacro(<< regtimer->GetElapsedMinutes() << " minutes, ");
+ // muLogMacro(<< regtimer->GetElapsedSeconds() << " seconds\n");
+ // delete regtimer;
+ itk::TimeProbe regtimer;
+ regtimer.Start();
+ atlasreg->SetOutputDebugDir(outputDir);
+ try
{
+ atlasreg->Update();
+ }
+ catch(itk::ExceptionObject &e)
+ {
+ std::cerr << "Exception caught!" << std::endl;
+ std::cerr << e << std::endl;
+ return EXIT_FAILURE;
+ }
- RescaleFunctionLocal(intraSubjectRegisteredImageList);
- RescaleFunctionLocal(intraSubjectRegisteredRawImageList);
+ regtimer.Stop();
+ itk::RealTimeClock::TimeStampType elapsedTime
+ = regtimer.GetTotal();
+ muLogMacro(<< "Registration took " << elapsedTime << " " << regtimer.GetUnit() << std::endl);
+
+ std::vector<GenericTransformType::Pointer> intraSubjectTransforms = atlasreg->GetIntraSubjectTransforms();
+
+ // ::ResampleImages()
+ {
+ // muLogMacro(<< "ResampleImages");
+
+ // Define the internal reader type
+ typedef itk::ResampleImageFilter<FloatImageType, FloatImageType> ResampleType;
+ typedef ResampleType::Pointer ResamplePointer;
+
+ intraSubjectRegisteredImageList =
+ ResampleImageList(resamplerInterpolatorType, intraSubjectNoiseRemovedImageList,
+ intraSubjectTransforms);
+ intraSubjectRegisteredRawImageList = ResampleImageList(resamplerInterpolatorType, intraSubjectRawImageList,
+ intraSubjectTransforms);
+ assert( intraSubjectRegisteredImageList.size() == intraSubjectNoiseRemovedImageList.size() );
+ assert( intraSubjectRegisteredImageList.size() == intraSubjectRawImageList.size() );
+ intraSubjectNoiseRemovedImageList.clear();
+ intraSubjectRawImageList.clear();
+ } // End registering data
+
+ {
+ // Now check that the intraSubjectNoiseRemovedImageList has positive
+ // definite covariance matrix.
+ // The algorithm is not stable if the covariance matrix is not
+ // positive definite, and this
+ // occurs when two or more of the images are linearly dependant (i.e.
+ // nearly the same image).
+ duplicatesFound = FindDuplicateImages(intraSubjectRegisteredImageList);
+ for( size_t q = 0; q < duplicatesFound.size(); q++ )
+ {
+ if( duplicatesFound[q] == true )
+ {
+ std::cout << "WARNING: Found images that were very highly correlated." << std::endl;
+ std::cout << "WARNING: Removing image " << inputVolumes[q] << " from further processing" << std::endl;
+ std::cout << "WARNING:" << std::endl;
+ }
+ }
+ }
+ } // EndOriginalImagesList
+
+ atlasToSubjectPreSegmentationTransform = atlasreg->GetAtlasToSubjectTransform();
+ if( debuglevel > 9 )
+ { // NOTE THIS IS REALLY ANNOYING FOR LARGE BSPLINE REGISTRATIONS!
+ muLogMacro( << __FILE__ << " " << __LINE__ << " " << atlasToSubjectPreSegmentationTransform->GetFixedParameters(
+ ) << std::endl );
+ muLogMacro(
+ << __FILE__ << " " << __LINE__ << " " << atlasToSubjectPreSegmentationTransform->GetParameters() << std::endl );
}
+ if( debuglevel > 4 )
+ {
+ // Write the registered template and images
+ if( !writeLess )
+ {
+ muLogMacro(<< "Writing registered template...\n");
+
+ typedef itk::ResampleImageFilter<FloatImageType, FloatImageType> ResampleType;
+ typedef ResampleType::Pointer ResamplePointer;
+ ResamplePointer resampler = ResampleType::New();
+
+ resampler->SetInput(atlasOriginalImageList[0]);
+ resampler->SetTransform(atlasToSubjectPreSegmentationTransform);
+
+ resampler->SetOutputParametersFromImage(intraSubjectRegisteredRawImageList[0]);
+ resampler->SetDefaultPixelValue(0);
+ resampler->Update();
+ typedef itk::CastImageFilter<FloatImageType, ShortImageType>
+ ShortRescaleType;
+ ShortRescaleType::Pointer rescaler = ShortRescaleType::New();
+ rescaler->SetInput( resampler->GetOutput() );
+ rescaler->Update();
+
+ typedef itk::ImageFileWriter<ShortImageType> ShortWriterType;
+ ShortWriterType::Pointer writer = ShortWriterType::New();
+
+ std::string fn
+ = outputDir + std::string("AtlasToSubjectInitialization_") + suffstr;
+
+ writer->SetInput( rescaler->GetOutput() );
+ writer->SetFileName( fn.c_str() );
+ writer->UseCompressionOn();
+ writer->Update();
+ }
+ for( unsigned int i = 0; i < intraSubjectRegisteredRawImageList.size(); i++ )
+ {
+ typedef itk::RescaleIntensityImageFilter<FloatImageType, ShortImageType>
+ ShortRescaleType;
+
+ ShortRescaleType::Pointer rescaler = ShortRescaleType::New();
+ rescaler->SetOutputMinimum(0);
+ rescaler->SetOutputMaximum(MAX_IMAGE_OUTPUT_VALUE);
+ rescaler->SetInput(intraSubjectRegisteredRawImageList[i]);
+ rescaler->Update();
+
+ std::string fn
+ = outputDir + GetStripedImageFileNameExtension( ( inputVolumes[i] ) )
+ + std::string("_registered") + suffstr;
+
+ typedef itk::ImageFileWriter<ShortImageType> ShortWriterType;
+ ShortWriterType::Pointer writer = ShortWriterType::New();
+
+ writer->SetInput( rescaler->GetOutput() );
+ writer->SetFileName( fn.c_str() );
+ writer->UseCompressionOn();
+ writer->Update();
+ }
+ }
+ }
+ } // end atlas reg block
+
+ {
+ // Now based on the duplicates found, update input lists to only use unique
+ // images
+ intraSubjectRegisteredImageList = RemoveDuplicates(intraSubjectRegisteredImageList, duplicatesFound);
+ intraSubjectRegisteredRawImageList = RemoveDuplicates(intraSubjectRegisteredRawImageList, duplicatesFound);
+ inputVolumes = RemoveDuplicates(inputVolumes, duplicatesFound);
+ inputVolumeTypes = RemoveDuplicates(inputVolumeTypes, duplicatesFound);
+ }
+
+ muLogMacro(<< "Rescale intensity of filtered images...\n");
+ {
+
+ RescaleFunctionLocal(intraSubjectRegisteredImageList);
+ RescaleFunctionLocal(intraSubjectRegisteredRawImageList);
+ }
// Start the segmentation process.
for( unsigned int segmentationLevel = 0; segmentationLevel < 1; segmentationLevel++ )
{
@@ -1145,34 +1155,34 @@ int main(int argc, char * *argv)
SegFilterType::Pointer segfilter = SegFilterType::New();
// __MAX__PROBS
+ {
+ std::vector<FloatImagePointer> atlasOriginalPriors( PriorNames.size() );
+ for( unsigned int i = 0; i < PriorNames.size(); i++ )
{
- std::vector<FloatImagePointer> atlasOriginalPriors( PriorNames.size() );
- for( unsigned int i = 0; i < PriorNames.size(); i++ )
- {
- typedef itk::ImageFileReader<FloatImageType> ReaderType;
- typedef ReaderType::Pointer ReaderPointer;
- ReaderPointer priorReader = ReaderType::New();
- priorReader->SetFileName( atlasDefinitionParser.GetPriorFilename(PriorNames[i]) );
- priorReader->Update();
- FloatImageType::Pointer temp = priorReader->GetOutput();
- atlasOriginalPriors[i] = temp;
- }
- segfilter->SetPriors(atlasOriginalPriors);
+ typedef itk::ImageFileReader<FloatImageType> ReaderType;
+ typedef ReaderType::Pointer ReaderPointer;
+ ReaderPointer priorReader = ReaderType::New();
+ priorReader->SetFileName( atlasDefinitionParser.GetPriorFilename(PriorNames[i]) );
+ priorReader->Update();
+ FloatImageType::Pointer temp = priorReader->GetOutput();
+ atlasOriginalPriors[i] = temp;
}
+ segfilter->SetPriors(atlasOriginalPriors);
+ }
+ {
+ SegFilterType::RangeDBType myRanges;
+ for( unsigned int q = 0; q < PriorNames.size(); q++ )
{
- SegFilterType::RangeDBType myRanges;
- for( unsigned int q = 0; q < PriorNames.size(); q++ )
+ std::map<std::string, AtlasDefinition::BoundsType> temp_range_List;
+ for( unsigned int tt = 0; tt < inputVolumeTypes.size(); tt++ )
{
- std::map<std::string, AtlasDefinition::BoundsType> temp_range_List;
- for( unsigned int tt = 0; tt < inputVolumeTypes.size(); tt++ )
- {
- temp_range_List[inputVolumeTypes[tt]] = atlasDefinitionParser.GetBounds(PriorNames[q], inputVolumeTypes[tt]);
- }
- myRanges[PriorNames[q]] = temp_range_List;
+ temp_range_List[inputVolumeTypes[tt]] = atlasDefinitionParser.GetBounds(PriorNames[q], inputVolumeTypes[tt]);
}
- segfilter->SetTissueTypeThresholdMapsRange(myRanges);
- segfilter->SetPriorNames(PriorNames);
+ myRanges[PriorNames[q]] = temp_range_List;
}
+ segfilter->SetTissueTypeThresholdMapsRange(myRanges);
+ segfilter->SetPriorNames(PriorNames);
+ }
// //Static component that does not depend on priors-consolidation.
muLogMacro(<< "Start segmentation...\n");
@@ -1205,12 +1215,12 @@ int main(int argc, char * *argv)
// SEGMENTATION PROCESS AND SKIPPING MOST OF EMLoop
// If this "Post" transform is given, then jump over the looping, and
// warp priors,do estimates, and bias correct in one step.
- {
- ReadGenericTransform;
+ {
+ ReadGenericTransform;
- segfilter->SetTemplateGenericTransform();
- // Turn off warping, and just use the input given from disk.
- }
+ segfilter->SetTemplateGenericTransform();
+ // Turn off warping, and just use the input given from disk.
+ }
#endif
if( !atlasWarpingOff )
@@ -1251,7 +1261,7 @@ int main(int argc, char * *argv)
std::cerr << imgset.size() << " images in filter output, but "
<< outputVolumes.size() << " names in output volumes list"
<< std::endl;
- exit(1);
+ return EXIT_FAILURE;
}
else
{
@@ -1280,7 +1290,7 @@ int main(int argc, char * *argv)
writer->Update();
}
}
-
+
// Average together all the input images of a given type
typedef std::map<std::string, std::vector<FloatImageType::Pointer> > imgTypeMapType;
imgTypeMapType volumesByImgType;
@@ -1300,7 +1310,7 @@ int main(int argc, char * *argv)
std::string volumeType = mapItr->first;
// Can't average images of type other since it's really a mix of types.
std::transform(volumeType.begin(), volumeType.end(), volumeType.begin(), tolower) ;
- if(volumeType == "other")
+ if(volumeType == "other")
{
continue;
}
@@ -1333,7 +1343,7 @@ int main(int argc, char * *argv)
for( unsigned int index = 0; index < WarpedAtlasList.size(); index++ )
{
typedef itk::RescaleIntensityImageFilter<FloatImageType, ByteImageType>
- ByteRescaleType;
+ ByteRescaleType;
ByteRescaleType::Pointer rescaler = ByteRescaleType::New();
rescaler->SetOutputMinimum(0);
@@ -1357,7 +1367,7 @@ int main(int argc, char * *argv)
}
if(atlasToSubjectTransform != "")
{
- /* HACK Remove this completely
+ /* HACK Remove this completely
const std::string postSegmentationTransformFileName = outputDir
+ GetStripedImageFileNameExtension(templateVolumes[0])
+ std::string("_to_")
@@ -1381,108 +1391,108 @@ int main(int argc, char * *argv)
// Write the labels
muLogMacro(<< "Writing labels...\n");
+ {
+ typedef itk::ImageFileWriter<ByteImageType> ByteWriterType;
+ ByteWriterType::Pointer writer = ByteWriterType::New();
+
+ writer->SetInput( segfilter->GetOutput() );
+ std::string fn;
+ if(outputLabels == "")
{
- typedef itk::ImageFileWriter<ByteImageType> ByteWriterType;
- ByteWriterType::Pointer writer = ByteWriterType::New();
+ fn = outputDir;
+ fn += GetStripedImageFileNameExtension(names[0]);
+ fn += std::string("_DirtyLabels");
+ fn += suffstr;
+ }
+ else
+ {
+ fn = outputDirtyLabels;
+ }
+ writer->SetFileName( fn.c_str() );
+ writer->UseCompressionOn();
+ writer->Update();
+ }
+ {
+ typedef itk::ImageFileWriter<ByteImageType> ByteWriterType;
+ ByteWriterType::Pointer writer = ByteWriterType::New();
- writer->SetInput( segfilter->GetOutput() );
- std::string fn;
- if(outputLabels == "")
- {
- fn = outputDir;
- fn += GetStripedImageFileNameExtension(names[0]);
- fn += std::string("_DirtyLabels");
- fn += suffstr;
- }
- else
- {
- fn = outputDirtyLabels;
- }
- writer->SetFileName( fn.c_str() );
- writer->UseCompressionOn();
- writer->Update();
+ std::string fn;
+ if(outputLabels == "")
+ {
+ fn = outputDir;
+ fn += GetStripedImageFileNameExtension(names[0]);
+ fn += std::string("_labels");
+ fn += suffstr;
}
+ else
{
- typedef itk::ImageFileWriter<ByteImageType> ByteWriterType;
- ByteWriterType::Pointer writer = ByteWriterType::New();
+ fn = outputLabels;
+ }
+ writer->SetInput( segfilter->GetCleanedOutput() );
+ writer->SetFileName( fn.c_str() );
+ writer->UseCompressionOn();
+ try
+ {
+ writer->Update();
+ }
+ catch( itk::ExceptionObject & e )
+ {
+ muLogMacro( << e << std::endl );
+ return -1;
+ }
+ catch( std::exception & e )
+ {
+ muLogMacro( << "Exception: " << e.what() << std::endl );
+ return -1;
+ }
+ catch( std::string & s )
+ {
+ muLogMacro( << "Exception: " << s << std::endl );
+ return -1;
+ }
+ catch( ... )
+ {
+ muLogMacro( << "Unknown exception" << std::endl );
+ muLogMacro( << "failed to write image " << fn << std::endl );
+ return -1;
+ }
+ }
+ // Write final Posteriors
+ {
+ // NOTE : Priors and Posteriors should correspond, so use the PriorNames
+ // to get the names.
+ for( unsigned int probabilityIndex = 0; probabilityIndex < PriorNames.size(); probabilityIndex++ )
+ {
std::string fn;
- if(outputLabels == "")
+ if(posteriorTemplate == "")
{
fn = outputDir;
fn += GetStripedImageFileNameExtension(names[0]);
- fn += std::string("_labels");
+ fn += "_POSTERIOR_";
+ fn += PriorNames[probabilityIndex];
fn += suffstr;
}
else
{
- fn = outputLabels;
+ char buf[8192];
+ sprintf(buf,posteriorTemplate.c_str(),
+ PriorNames[probabilityIndex].c_str());
+ fn = buf;
}
+ typedef itk::ImageFileWriter<FloatImageType> FloatWriterType;
+ FloatWriterType::Pointer writer = FloatWriterType::New();
- writer->SetInput( segfilter->GetCleanedOutput() );
+ FloatImageType::Pointer currPosterior = segfilter->GetPosteriors()[probabilityIndex];
+ writer->SetInput( currPosterior );
writer->SetFileName( fn.c_str() );
writer->UseCompressionOn();
- try
- {
- writer->Update();
- }
- catch( itk::ExceptionObject & e )
- {
- muLogMacro( << e << std::endl );
- return -1;
- }
- catch( std::exception & e )
- {
- muLogMacro( << "Exception: " << e.what() << std::endl );
- return -1;
- }
- catch( std::string & s )
- {
- muLogMacro( << "Exception: " << s << std::endl );
- return -1;
- }
- catch( ... )
- {
- muLogMacro( << "Unknown exception" << std::endl );
- muLogMacro( << "failed to write image " << fn << std::endl );
- return -1;
- }
- }
- // Write final Posteriors
- {
- // NOTE : Priors and Posteriors should correspond, so use the PriorNames
- // to get the names.
- for( unsigned int probabilityIndex = 0; probabilityIndex < PriorNames.size(); probabilityIndex++ )
- {
- std::string fn;
- if(posteriorTemplate == "")
- {
- fn = outputDir;
- fn += GetStripedImageFileNameExtension(names[0]);
- fn += "_POSTERIOR_";
- fn += PriorNames[probabilityIndex];
- fn += suffstr;
- }
- else
- {
- char buf[8192];
- sprintf(buf,posteriorTemplate.c_str(),
- PriorNames[probabilityIndex].c_str());
- fn = buf;
- }
- typedef itk::ImageFileWriter<FloatImageType> FloatWriterType;
- FloatWriterType::Pointer writer = FloatWriterType::New();
-
- FloatImageType::Pointer currPosterior = segfilter->GetPosteriors()[probabilityIndex];
- writer->SetInput( currPosterior );
- writer->SetFileName( fn.c_str() );
- writer->UseCompressionOn();
- writer->Update();
- }
+ writer->Update();
}
}
+ }
timer.Stop();
muLogMacro(<< "All segmentation processes took " << timer.GetTotal() << " " << timer.GetUnit() << std::endl );
- return 0;
+ return EXIT_SUCCESS;
}
View
1 BRAINSABC/brainseg/BRAINSABCUtilities.h
@@ -36,7 +36,6 @@ typedef unsigned int LOOPITERTYPE;
if( !vnl_math_isfinite( XXXTESTXXX ) ) \
{ \
std::cout << "Found " << XXXTESTXXX << " at " << srcfile << " " << srcline << std::endl; \
- /*exit(-1);*/ \
} \
}
#else
View
16 BRAINSABC/brainseg/BRAINSCleanMask.cxx
@@ -10,12 +10,12 @@ int main(int argc, char * *argv)
if( inputVolume == "" )
{
std::cerr << "No input volume name given" << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
if( outputVolume == "" )
{
std::cerr << "No output volume name given" << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
typedef itk::Image<unsigned char, 3> ImageType;
@@ -29,12 +29,12 @@ int main(int argc, char * *argv)
{
std::cerr << "error reading " << inputVolume << std::endl
<< e << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
catch( ... )
{
std::cerr << "Unable to open " << inputVolume << std::endl;
- exit(1);
+ return EXIT_FAILURE;
}
ImageType::Pointer output;
try
@@ -44,13 +44,13 @@ int main(int argc, char * *argv)
catch( itk::ExceptionObject & e )
{
std::cerr << e << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
catch( ... )
{
std::cerr << "Error during processing of "
<< inputVolume << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
try
@@ -61,12 +61,12 @@ int main(int argc, char * *argv)
{
std::cerr << "error writing " << inputVolume << std::endl
<< e << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
catch( ... )
{
std::cerr << "Unable to write " << outputVolume << std::endl;
- return 1;
+ return EXIT_FAILURE;
}
return 0;
}
View
15 BRAINSABC/brainseg/EMSegmentationFilter.txx
@@ -867,8 +867,7 @@ WarpImageList(const std::vector<typename TInputImage::Pointer> & originalList,
{
if( originalList.size() != backgroundValues.size() )
{
- std::cout << "ERROR: originalList and backgroundValues arrays sizes do not match" << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "ERROR: originalList and backgroundValues arrays sizes do not match" << std::endl);
}
std::vector<typename TInputImage::Pointer> warpedList(originalList.size() );
@@ -1573,8 +1572,7 @@ EMSegmentationFilter<TInputImage, TProbabilityImage>
{
if( this->m_TemplateGenericTransform.IsNull() )
{
- std::cout << "ERROR: Must suppply an intial transformation!" << std::endl;
- exit(-1);
+ itkExceptionMacro( << "ERROR: Must suppply an intial transformation!" );
}
this->m_NonAirRegion = ComputeTissueRegion<TInputImage, ByteImageType>(this->m_InputImages[0], 3);
@@ -1658,11 +1656,10 @@ EMSegmentationFilter<TInputImage, TProbabilityImage>
}
catch( ... )
{
- std::cerr << "ERROR:\nERROR:\nERROR:\nERROR:"
- <<
- " Linearly dependant input images detected. Please remove the images in the above table that show very similar values images."
- << "ERROR:\nERROR:\nERROR:\nERROR:" << std::endl;
- exit(-1);
+ itkExceptionMacro( << "ERROR:\nERROR:\nERROR:\nERROR:"
+ << " Linearly dependant input images detected. "
+ << "Please remove the images in the above table that show very similar values images."
+ << "ERROR:\nERROR:\nERROR:\nERROR:" );
}
}
}
View
2 BRAINSABC/brainseg/EMSplitPriorMST.h
@@ -6,7 +6,7 @@ void
EMSegmentationFilter<TInputImage, TProbabilityImage>
::SplitPriorMST(unsigned int /*iprior*/)
{
- exit(-1);
+ throw; // don't exit
#if 0
const unsigned int numChannels = m_InputImages.size();
const unsigned int numPriors = m_WarpedPriors.size();
View
3 BRAINSABC/brainseg/GenerateLabelMapFromProbabilityMap.cxx
@@ -24,8 +24,7 @@ main(int argc, char *argv[])
{
std::cerr << argv[0] << ": Missing required probability maps"
<< std::cerr;
- exit(1);
-
+ return EXIT_FAILURE;
}
const unsigned int numberOfProbabilityMaps = inputVolumes.size();
View
17 BRAINSABC/brainseg/LLSBiasCorrector.txx
@@ -677,15 +677,14 @@ LLSBiasCorrector<TInputImage, TProbabilityImage>
#if 1
if( !std::isfinite( (double)coeffs[0][0]) )
{
- std::cout
- << "\ncoeffs: \n" << coeffs
- // << "\nlhs_ij: \n" << lhs_ij
- << "\nbasisT: \n" << basisT
- // << "\nWij_A: \n" << Wij_A
- << "\nlhs: \n" << lhs
- << "\nrhs: \n" << rhs
- << std::endl;
- exit(-1);
+ itkExceptionMacro(
+ << "\ncoeffs: \n" << coeffs
+ // << "\nlhs_ij: \n" << lhs_ij
+ << "\nbasisT: \n" << basisT
+ // << "\nWij_A: \n" << Wij_A
+ << "\nlhs: \n" << lhs
+ << "\nrhs: \n" << rhs
+ );
}
#endif
// Clear memory for the basis transpose
View
6 BRAINSABC/brainseg/StandardizeMaskIntensity.h
@@ -87,10 +87,8 @@ typename ImageType::Pointer StandardizeMaskIntensity(
maskedStatistics->GetHistogram( maskInteriorLabel );
if( hist.IsNull() )
{
- std::cout << "TODO: THIS SHOULD BE AN EXCEPTION"
- << "histogram had no value for label "
- << __FILE__ << " " << __LINE__ << " " << maskInteriorLabel << std::endl;
- exit(-1);
+ itkGenericExceptionMacro("histogram had no value for label "
+ << maskInteriorLabel);
}
// Remark: Since itk's filter uses the same bounds to scale and to clip,
View
17 BRAINSCommonLib/BRAINSFitHelper.cxx
@@ -39,8 +39,7 @@ MaskImageType::ConstPointer ExtractConstPointerToImageMaskFromImageSpatialObject
if( temp == NULL )
{
- std::cout << "Invalid mask converstion attempted." << __FILE__ << " " << __LINE__ << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "Invalid mask converstion attempted.");
}
ImageMaskSpatialObjectType::ConstPointer ImageMask( temp );
const MaskImageType::ConstPointer tempOutputVolumeROI = ImageMask->GetImage();
@@ -161,13 +160,6 @@ BRAINSFitHelper::StartRegistration(void)
// Do Histogram equalization on moving image if requested.
if( m_HistogramMatch )
{
-#if 0
- std::cerr << " ********* ERROR ************"
- << " Histogram Equalization Option for BRAINSFit does not work"
- << " for now. Please do not use --histogramMatch"
- << std::endl;
- exit(-1);
-#else
typedef itk::OtsuHistogramMatchingImageFilter<FixedVolumeType, MovingVolumeType> HistogramMatchingFilterType;
HistogramMatchingFilterType::Pointer histogramfilter = HistogramMatchingFilterType::New();
@@ -187,15 +179,13 @@ BRAINSFitHelper::StartRegistration(void)
histogramfilter->SetReferenceImage(this->m_FixedVolume);
if( this->m_FixedBinaryVolume.IsNull() )
{
- std::cout << "ERROR: Histogram matching requires a fixed mask." << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "ERROR: Histogram matching requires a fixed mask.");
}
histogramfilter->SetReferenceMask( m_FixedBinaryVolume.GetPointer() );
histogramfilter->SetInput(this->m_PreprocessedMovingVolume);
if( this->m_MovingBinaryVolume.IsNull() )
{
- std::cout << "ERROR: Histogram matching requires a moving mask." << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "ERROR: Histogram matching requires a moving mask.");
}
histogramfilter->SetSourceMask( m_MovingBinaryVolume.GetPointer() );
histogramfilter->SetNumberOfHistogramLevels(this->m_NumberOfHistogramBins);
@@ -220,7 +210,6 @@ BRAINSFitHelper::StartRegistration(void)
throw;
}
}
-#endif
}
else
{
View
156 BRAINSCommonLib/BRAINSFitHelperTemplate.hxx
@@ -15,6 +15,7 @@
#include "itkLabelObject.h"
#include "itkStatisticsLabelObject.h"
#include "itkLabelImageToStatisticsLabelMapFilter.h"
+#include "itkMacro.h"
namespace itk
{
@@ -30,6 +31,11 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
// transform types.
// Rigid=1, ScaleVersor3D=2, ScaleSkewVersor3D=3, Affine=4, and (BSpline or
// ROIBspline)=5
+#define VTROExceptionMacroMacro() \
+ itkGenericExceptionMacro(<< "Ordering of transforms does not proceed from\n" \
+ << "smallest to largest. Please review settings for transformType.\n" \
+ << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpine)")
+
unsigned int CurrentTransformRank = 0;
for( unsigned int l = 0; l < transformType.size(); ++l )
{
@@ -41,10 +47,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpine)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
else if( transformType[l] == "ScaleVersor3D" )
@@ -55,10 +58,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpline)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
else if( transformType[l] == "ScaleSkewVersor3D" )
@@ -69,10 +69,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpline)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
else if( transformType[l] == "Affine" )
@@ -83,10 +80,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpline)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
else if( transformType[l] == "BSpline" )
@@ -97,10 +91,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpline)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
else if( transformType[l] == "ROIBSpline" )
@@ -111,10 +102,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
}
else
{
- std::cerr << "Ordering of transforms does not proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < (BSpline | ROIBSpline)" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
@@ -122,10 +110,7 @@ ValidateTransformRankOrdering(const std::vector<std::string> & transformType)
{
std::cerr << " ERROR: Invalid transform type specified for element " << l << " of --transformType: "
<< transformType[l] << std::endl;
- std::cerr << "Ordering of transforms must proceed from\n"
- << "smallest to largest. Please review settings for transformType.\n"
- << "Rigid < ScaleVersor3D < ScaleSkewVersor3D < Affine < BSpline" << std::endl;
- exit(-1);
+ VTROExceptionMacroMacro();
}
}
}
@@ -244,8 +229,7 @@ typename TransformType::Pointer DoCenteredInitialization(
typename SpatialObjectType::Pointer p = dynamic_cast<SpatialObjectType *>( mask.GetPointer() );
if( p.IsNull() )
{
- std::cout << "ERROR::" << __FILE__ << " " << __LINE__ << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "Can't convert mask pointer to SpatialObject");
}
movingMask = p;
}
@@ -278,8 +262,7 @@ typename TransformType::Pointer DoCenteredInitialization(
typename SpatialObjectType::Pointer p = dynamic_cast<SpatialObjectType *>( mask.GetPointer() );
if( p.IsNull() )
{
- std::cout << "ERROR::" << __FILE__ << " " << __LINE__ << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "Can't convert mask pointer to SpatialObject");
}
fixedMask = p;
}
@@ -497,9 +480,8 @@ typename TransformType::Pointer DoCenteredInitialization(
// was
// added:
{
- std::cout << "FAILURE: Improper mode for initializeTransformMode: "
- << initializeTransformMode << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "FAILURE: Improper mode for initializeTransformMode: "
+ << initializeTransformMode);
}
std::cout << "Initializing transform with " << initializeTransformMode
<< " to " << std::endl;
@@ -624,16 +606,14 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::FitCommonCode(
catch( itk::ExceptionObject& err )
{
// pass exception to caller
- std::cout << "ERROR OCCURED: " << err << std::endl;
- exit(-1);
- throw err;
+ throw;
}
- { // Put the transform on the CurrentTransformList
- // Initialize next level of transformations with previous transform
- // result
- this->m_CurrentGenericTransform = finalTransform;
- }
+ // Put the transform on the CurrentTransformList
+ // Initialize next level of transformations with previous transform
+ // result
+ this->m_CurrentGenericTransform = finalTransform;
+
}
template <class FixedImageType, class MovingImageType>
@@ -661,10 +641,8 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::StartRegistration(void
{
if( m_MinimumStepLength.size() != 1 )
{
- std::cout << "ERROR: Wrong number of parameters for MinimumStepLength."
- << "It either needs to be 1 or the same size as TransformType."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "ERROR: Wrong number of parameters for MinimumStepLength."
+ << "It either needs to be 1 or the same size as TransformType.");
}
for( unsigned int q = 0; q < m_TransformType.size(); ++q )
{
@@ -680,10 +658,8 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::StartRegistration(void
{
if( m_NumberOfIterations.size() != 1 )
{
- std::cout << "ERROR: Wrong number of parameters for NumberOfIterations."
- << " It either needs to be 1 or the same size as TransformType."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(<< "ERROR: Wrong number of parameters for NumberOfIterations."
+ << " It either needs to be 1 or the same size as TransformType.")
}
for( unsigned int q = 0; q < m_TransformType.size(); ++q )
{
@@ -1296,33 +1272,27 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::StartRegistration(void
{
// Error, initializing from wrong size transform parameters;
// Use its bulk transform only?
- std::cerr
- << "Trouble using the m_CurrentGenericTransform for initializing a BSPlineDeformableTransform:"
- << std::endl;
- std::cerr
- <<
- "The initializing BSplineDeformableTransform has a different"
- << " number of Parameters, than what is required for the requested grid."
- << std::endl;
- std::cerr
- << "BRAINSFit was only able to use the bulk transform that was before it."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(
+ << "Trouble using the m_CurrentGenericTransform"
+ << "for initializing a BSPlineDeformableTransform:"
+ << std::endl
+ << "The initializing BSplineDeformableTransform has a different"
+ << " number of Parameters, than what is required for the requested grid."
+ << std::endl
+ << "BRAINSFit was only able to use the bulk transform that was before it.");
}
}
else
{
- std::cerr
- << "ERROR: initialization BSpline transform does not have the same "
- << "parameter dimensions as the one currently specified."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(
+ << "ERROR: initialization BSpline transform does not have the same "
+ << "parameter dimensions as the one currently specified.");
}
}
else
{
- std::cerr << "ERROR: Invalid transform initializer type found: " << transformFileType << std::endl;
- exit(-1);
+ itkGenericExceptionMacro( << "ERROR: Invalid transform initializer type found: "
+ << transformFileType )
}
}
catch( itk::ExceptionObject & excp )
@@ -1614,33 +1584,26 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::StartRegistration(void
{
// Error, initializing from wrong size transform parameters;
// Use its bulk transform only?
- std::cerr
- << "Trouble using the m_CurrentGenericTransform for initializing a BSPlineDeformableTransform:"
- << std::endl;
- std::cerr
- <<
- "The initializing BSplineDeformableTransform has a different"
- << " number of Parameters, than what is required for the requested grid."
- << std::endl;
- std::cerr
- << "BRAINSFit was only able to use the bulk transform that was before it."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(
+ << "Trouble using the m_CurrentGenericTransform for initializing a BSPlineDeformableTransform:"
+ << std::endl
+ << "The initializing BSplineDeformableTransform has a different"
+ << " number of Parameters, than what is required for the requested grid."
+ << std::endl
+ << "BRAINSFit was only able to use the bulk transform that was before it.");
}
}
else
{
- std::cerr
- << "ERROR: initialization BSpline transform does not have the same "
- << "parameter dimensions as the one currently specified."
- << std::endl;
- exit(-1);
+ itkGenericExceptionMacro(
+ << "ERROR: initialization BSpline transform does not have the same "
+ << "parameter dimensions as the one currently specified.")
}
}
else
{
- std::cerr << "ERROR: Invalid transform initializer type found: " << transformFileType << std::endl;
- exit(-1);
+ itkGenericExceptionMacro( << "ERROR: Invalid transform initializer type found: "
+ << transformFileType );
}
}
catch( itk::ExceptionObject & excp )
@@ -1708,20 +1671,15 @@ BRAINSFitHelperTemplate<FixedImageType, MovingImageType>::StartRegistration(void
else
{
- std::cout
- << "Error choosing what kind of transform to fit \""
- << currentTransformType << "(" << currentTransformIndex + 1 << " of " << m_TransformType.size() << "). "
- << std::endl;
- std::cout << std::flush << std::endl;
- exit(-1);
- return;
+ itkGenericExceptionMacro(
+ << "Error choosing what kind of transform to fit \""
+ << currentTransformType << "(" << currentTransformIndex + 1 << " of " << m_TransformType.size() << "). ");
}
if( currentTransformId > m_GenericTransformList.size() - 1 )
{
- std::cerr << "Out of bounds access for transform vector!" << std::endl;
- exit(-1);
- return;
+ itkGenericExceptionMacro(
+ << "Out of bounds access for transform vector!" << std::endl);
}
m_GenericTransformList[currentTransformId++] = m_CurrentGenericTransform;
}
View
5 BRAINSCommonLib/DebugImageViewerClient.h
@@ -40,10 +40,7 @@ ScaleAndCast(const typename InputImageType::Pointer & image,
}
catch ( itk::ExceptionObject & e )
{
- std::cerr << "Exception in Image cast." << std::endl;
- std::cerr << e.GetDescription() << std::endl;
- std::cerr << e.GetLocation() << std::endl;
- exit(-1);
+ throw;
}
typename OutputImageType::Pointer returnScaled = RealToProbMapCast->GetOutput();
return returnScaled;
View
32 BRAINSCommonLib/GenericTransformImage.cxx
@@ -209,11 +209,7 @@ int WriteBothTransformsToDisk(const GenericTransformType::ConstPointer genericTr
}
catch( itk::ExceptionObject & excp )
{
- std::cout << "[FAILED]" << std::endl;
- std::cerr << "Error while writing the genericTransformToWrite"
- << std::endl;
- std::cerr << excp << std::endl;
- exit(-1);
+ throw; // rethrow exception, handle in some other scope.
}
return 0;
}
@@ -243,22 +239,14 @@ GenericTransformType::Pointer ReadTransformFromDisk(const std::string & initialT
<< initialTransform << std::endl;
transformListReader->SetFileName( initialTransform.c_str() );
- try
- {
- transformListReader->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cerr << "ExceptionObject caught !" << std::endl;
- std::cerr << err << std::endl;
- exit(-1);
- }
+
+ transformListReader->Update();
+
currentTransformList = *( transformListReader->GetTransformList() );
if( currentTransformList.size() == 0 )
{
- std::cout << "Number of currentTransformList = " << currentTransformList.size() << std::endl;
- std::cout << "FATAL ERROR: Failed to read transform" << initialTransform << std::endl;
- exit(-1);
+ itkGenericExceptionMacro( << "Number of currentTransformList = " << currentTransformList.size()
+ << "FATAL ERROR: Failed to read transform" << initialTransform);
}
}
if( currentTransformList.size() == 1 ) // Most simple transform types
@@ -461,11 +449,7 @@ void WriteTransformToDisk(GenericTransformType const *const MyTransform, const s
}
catch( itk::ExceptionObject & excp )
{
- std::cout << "[FAILED]" << std::endl;
- std::cerr << "Error while writing transform file: "
- << TransformFilename << std::endl;
- std::cerr << excp << std::endl;
- return;
+ throw;
}
// Test if the file exists.
if( !itksys::SystemTools::FileExists( TransformFilename.c_str() ) )
@@ -477,8 +461,6 @@ void WriteTransformToDisk(GenericTransformType const *const MyTransform, const s
<< std::endl;
e.SetDescription( msg.str().c_str() );
throw e;
- exit(-1);
- return;
}
}
}
View
66 BRAINSCommonLib/Imgmath.h
@@ -50,16 +50,7 @@ typename ImageType::Pointer Iadd(const typename ImageType::Pointer input1,
typename FilterType::Pointer filter = FilterType::New();
filter->SetInput1(input1);
filter->SetInput2(input2);
- try
- {
- filter->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cout << "Exception Object caught: " << std::endl;
- std::cout << err << std::endl;
- exit(-1);
- }
+ filter->Update();
typename ImageType::Pointer image = filter->GetOutput();
return image;
}
@@ -74,16 +65,7 @@ typename ImageType::Pointer Isub(const typename ImageType::Pointer input1,
typename FilterType::Pointer filter = FilterType::New();
filter->SetInput1(input1);
filter->SetInput2(input2);
- try
- {
- filter->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cout << "Exception Object caught: " << std::endl;
- std::cout << err << std::endl;
- exit(-1);
- }
+ filter->Update();
typename ImageType::Pointer image = filter->GetOutput();
return image;
}
@@ -98,16 +80,7 @@ typename ImageType::Pointer Imul(const typename ImageType::Pointer input1,
typename FilterType::Pointer filter = FilterType::New();
filter->SetInput1(input1);
filter->SetInput2(input2);
- try
- {
- filter->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cout << "Exception Object caught: " << std::endl;
- std::cout << err << std::endl;
- exit(-1);
- }
+ filter->Update();
typename ImageType::Pointer image = filter->GetOutput();
return image;
}
@@ -122,16 +95,7 @@ typename ImageType::Pointer Idiv(const typename ImageType::Pointer input1,
typename FilterType::Pointer filter = FilterType::New();
filter->SetInput1(input1);
filter->SetInput2(input2);
- try
- {
- filter->Update();
- }
- catch( itk::ExceptionObject & err )
- {
- std::cout << "Exception Object caught: " << std::endl;
- std::cout << err << std::endl;
- exit(-1);
- }
+ filter->Update();
typename ImageType::Pointer image = filter->GetOutput();
return image;
}