20 #include <itkBinaryThresholdImageFilter.h> 21 #include <itkImageFileWriter.h> 22 #include <itkTestingComparisonImageFilter.h> 28 class DirectOverlayTestClass
31 template <
typename TPixel,
unsigned int VDimensions>
32 static void InternalThreshold(
const itk::Image<TPixel, VDimensions> *
image,
37 typedef itk::Image<unsigned int, VDimensions> OutputImageType;
38 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdFilterType;
40 typename BinaryThresholdFilterType::Pointer thresholder = BinaryThresholdFilterType::New();
41 thresholder->SetInput(image);
42 thresholder->SetLowerThreshold(th[0]);
43 thresholder->SetUpperThreshold(th[1]);
44 thresholder->SetInsideValue(255);
45 thresholder->SetOutsideValue(0);
46 thresholder->Update();
50 std::cout <<
"extra line";
53 template <
typename TPixel,
unsigned int VDimensions>
54 static void InternalThreshold2(
const itk::Image<TPixel, VDimensions> *image,
55 itk::Image<unsigned int, 3>::Pointer &output,
59 typedef itk::Image<unsigned int, VDimensions> OutputImageType;
60 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdFilterType;
62 typename BinaryThresholdFilterType::Pointer thresholder = BinaryThresholdFilterType::New();
63 thresholder->SetInput(image);
64 thresholder->SetLowerThreshold(th[0]);
65 thresholder->SetUpperThreshold(th[1]);
66 thresholder->SetInsideValue(255);
67 thresholder->SetOutsideValue(0);
68 thresholder->Update();
70 output = thresholder->GetOutput();
79 const double th[] = {lower, upper};
80 typedef itk::Image<unsigned int, 3>
ImageType;
81 ImageType::Pointer itkOverlayImage = ImageType::New();
97 catch (
const itk::ExceptionObject &e)
99 MITK_ERROR <<
"Save image: exception : " << e.what();
104 InputImageType::Pointer overlayItk;
111 MITK_ERROR <<
"(CAST) Catched exception while creating accessor " << e.what();
122 InputImageType::Pointer truthItk;
125 bool difference =
false;
177 typedef unsigned int TPixel;
179 itk::ImageRegionConstIteratorWithIndex<InputImageType> iter(truthItk, truthItk->GetLargestPossibleRegion());
180 itk::ImageRegionConstIteratorWithIndex<InputImageType> iter2(overlayItk, overlayItk->GetLargestPossibleRegion());
183 unsigned int counter = 0;
184 while (!iter.IsAtEnd() && !iter2.IsAtEnd())
186 TPixel ref = iter.Get();
187 TPixel val = iter2.Get();
199 std::cout <<
"Differs in " << counter <<
"voxels" << std::endl;
204 "Comparing overlay with ground truth")
207 static void TestDirectOverlay(
char *
in,
char *gt,
const int lower,
const int upper)
212 if (original.IsNotNull() && original->GetDimension() == 3 && truth.IsNotNull() && truth->GetDimension() == 3 &&
215 TestOverlay(original, truth, lower, upper);
230 unsigned int lower = 0, upper = 0;
234 sscanf(argv[3],
"%u", &lower);
235 sscanf(argv[4],
"%u", &upper);
239 MITK_INFO <<
"Got values: " << lower <<
" : " << upper;
241 catch (std::exception &e)
246 DirectOverlayTestClass::TestDirectOverlay(argv[1], argv[2], lower, upper);
itk::Image< unsigned char, 3 > ImageType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
::mitk::Image InputImageType
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Image::Pointer ImportItkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, const BaseGeometry *geometry=nullptr, bool update=true)
Imports an itk::Image (with a specific type) as an mitk::Image.Instantiates instance of ITKImageImpor...
int DirectOverlayTest(int argc, char *argv[])
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
mitk::Image::Pointer image
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)