8 #include <itkBinaryThresholdImageFilter.h>
9 #include <itkImageFileWriter.h>
10 #include <itkTestingComparisonImageFilter.h>
16 class DirectOverlayTestClass
19 template <
typename TPixel,
unsigned int VDimensions>
20 static void InternalThreshold(
const itk::Image<TPixel, VDimensions> *image,
25 typedef itk::Image<unsigned int, VDimensions> OutputImageType;
26 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdFilterType;
29 thresholder->SetInput(image);
30 thresholder->SetLowerThreshold(th[0]);
31 thresholder->SetUpperThreshold(th[1]);
32 thresholder->SetInsideValue(255);
33 thresholder->SetOutsideValue(0);
34 thresholder->Update();
38 std::cout <<
"extra line";
41 template <
typename TPixel,
unsigned int VDimensions>
42 static void InternalThreshold2(
const itk::Image<TPixel, VDimensions> *image,
47 typedef itk::Image<unsigned int, VDimensions> OutputImageType;
48 typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdFilterType;
51 thresholder->SetInput(image);
52 thresholder->SetLowerThreshold(th[0]);
53 thresholder->SetUpperThreshold(th[1]);
54 thresholder->SetInsideValue(255);
55 thresholder->SetOutsideValue(0);
56 thresholder->Update();
58 output = thresholder->GetOutput();
67 const double th[] = {lower, upper};
68 typedef itk::Image<unsigned int, 3>
ImageType;
85 catch (
const itk::ExceptionObject &e)
87 MITK_ERROR <<
"Save image: exception : " << e.what();
99 MITK_ERROR <<
"(CAST) Catched exception while creating accessor " << e.what();
113 bool difference =
false;
165 typedef unsigned int TPixel;
167 itk::ImageRegionConstIteratorWithIndex<InputImageType> iter(truthItk, truthItk->GetLargestPossibleRegion());
168 itk::ImageRegionConstIteratorWithIndex<InputImageType> iter2(overlayItk, overlayItk->GetLargestPossibleRegion());
171 unsigned int counter = 0;
172 while (!iter.IsAtEnd() && !iter2.IsAtEnd())
174 TPixel ref = iter.Get();
175 TPixel val = iter2.Get();
187 std::cout <<
"Differs in " << counter <<
"voxels" << std::endl;
192 "Comparing overlay with ground truth")
195 static void TestDirectOverlay(
char *
in,
char *gt,
const int lower,
const int upper)
200 if (original.IsNotNull() && original->GetDimension() == 3 && truth.IsNotNull() && truth->GetDimension() == 3 &&
203 TestOverlay(original, truth, lower, upper);
218 unsigned int lower = 0, upper = 0;
222 sscanf(argv[3],
"%u", &lower);
223 sscanf(argv[4],
"%u", &upper);
227 MITK_INFO <<
"Got values: " << lower <<
" : " << upper;
229 catch (std::exception &e)
234 DirectOverlayTestClass::TestDirectOverlay(argv[1], argv[2], lower, upper);
itk::SmartPointer< Self > Pointer
itk::Image< unsigned char, 3 > ImageType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
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...
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
int DirectOverlayTest(int argc, char *argv[])
itk::Image< double, 3 > InputImageType
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.
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.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.