18 #include <itkThresholdImageFilter.h> 32 template <
typename TPixel,
unsigned int VDimensions>
39 typedef itk::ThresholdImageFilter<InputImageType> ThresholdFilterType;
41 typename ThresholdFilterType::Pointer thresholder = ThresholdFilterType::New();
42 thresholder->SetInput(image);
43 thresholder->ThresholdOutside(th[0], th[1]);
44 thresholder->Update();
50 catch (
const itk::ExceptionObject & )
61 template <
typename TPixel>
65 const unsigned int dimensions[3] = {3, 3, 3};
66 auto image_data =
new TPixel[27];
69 auto ground_truth =
new TPixel[27];
70 double threshold[2] = {90.0, 180.0};
73 for (
unsigned int i = 0; i < 27; i++)
75 image_data[i] =
static_cast<TPixel
>(i * 10);
78 if (image_data[i] >= threshold[0] && image_data[i] <= threshold[1])
79 ground_truth[i] =
static_cast<TPixel
>(i * 10);
83 input->Initialize(mitk::MakeScalarPixelType<TPixel>(), 3, dimensions);
84 input->SetImportVolume(image_data);
92 const TPixel *output_data = readAccessor.
GetData();
95 for (
unsigned int i = 0; i < 27; i++)
97 equal &= (ground_truth[i] == output_data[i]);
100 MITK_INFO <<
" :: At position " << i <<
" : " << ground_truth[i] <<
" ? " << output_data[i] <<
"\n";
114 Assert_ItkImportWithinAccessByItkSucceded_ReturnsTrue<short>();
115 Assert_ItkImportWithinAccessByItkSucceded_ReturnsTrue<float>();
116 Assert_ItkImportWithinAccessByItkSucceded_ReturnsTrue<unsigned char>();
117 Assert_ItkImportWithinAccessByItkSucceded_ReturnsTrue<int>();
Gives locked and index-based read access for a particular image part. The class provides several set-...
::mitk::Image InputImageType
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
bool Assert_ItkImportWithinAccessByItkSucceded_ReturnsTrue()
[ItkThresholdFilter]
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
#define MITK_TEST_CONDITION(COND, MSG)
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
const TPixel * GetData() const
Gives const access to the data.
mitk::Image::Pointer image
static void ItkThresholdFilter(const itk::Image< TPixel, VDimensions > *image, mitk::Image::Pointer &output, const double th[])
[ItkThresholdFilter]
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
int mitkGrabItkImageMemoryTest(int, char *[])