1 #ifndef _mitkCLUtil_HXX
2 #define _mitkCLUtil_HXX
10 #include <Eigen/Dense>
14 #include <itkCheckerBoardImageFilter.h>
15 #include <itkShapedNeighborhoodIterator.h>
17 #include <itkBinaryBallStructuringElement.h>
18 #include <itkBinaryDilateImageFilter.h>
19 #include <itkBinaryErodeImageFilter.h>
20 #include <itkBinaryFillholeImageFilter.h>
21 #include <itkBinaryMorphologicalClosingImageFilter.h>
22 #include <itkGrayscaleErodeImageFilter.h>
23 #include <itkGrayscaleDilateImageFilter.h>
24 #include <itkGrayscaleFillholeImageFilter.h>
27 #include <itkDiscreteGaussianImageFilter.h>
51 AccessByItk_2(image, mitk::CLUtil::itkInsertLabel, maskImage, label);
97 AccessFixedDimensionByItk_2(checkerboard_prediction, mitk::CLUtil::itkInterpolateCheckerboardPrediction,3, checkerboard_mask, outimage);
123 template<
typename TImageType>
124 void mitk::CLUtil::itkProbabilityMap(
const TImageType * sourceImage,
double mean,
double std_dev,
mitk::Image::Pointer& resultImage)
127 itk_img->SetRegions(sourceImage->GetLargestPossibleRegion());
128 itk_img->SetOrigin(sourceImage->GetOrigin());
129 itk_img->SetSpacing(sourceImage->GetSpacing());
130 itk_img->SetDirection(sourceImage->GetDirection());
134 itk::ImageRegionConstIterator<TImageType> it(sourceImage,sourceImage->GetLargestPossibleRegion());
135 itk::ImageRegionIterator<itk::Image<double, 3> > outit(itk_img,itk_img->GetLargestPossibleRegion());
139 double x = it.Value();
141 double prob = (1.0/(std_dev*std::sqrt(2.0*
M_PI))) * std::exp(-(((x-mean)*(x-mean))/(2.0*std_dev*std_dev)));
150 template<
typename TImageType >
157 itk_outimage->SetRegions(checkerboard_prediction->GetLargestPossibleRegion());
158 itk_outimage->SetDirection(checkerboard_prediction->GetDirection());
159 itk_outimage->SetOrigin(checkerboard_prediction->GetOrigin());
160 itk_outimage->SetSpacing(checkerboard_prediction->GetSpacing());
161 itk_outimage->Allocate();
162 itk_outimage->FillBuffer(0);
165 typedef itk::Size<3> SizeType;
168 itk::ShapedNeighborhoodIterator<TImageType> iit(size,checkerboard_prediction,checkerboard_prediction->GetLargestPossibleRegion());
169 itk::ShapedNeighborhoodIterator<TImageType> mit(size,itk_checkerboard_mask,itk_checkerboard_mask->GetLargestPossibleRegion());
170 itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());
172 typedef typename itk::ShapedNeighborhoodIterator<TImageType>::OffsetType OffsetType;
176 iit.ActivateOffset(offset);
177 mit.ActivateOffset(offset);
179 iit.ActivateOffset(offset);
180 mit.ActivateOffset(offset);
181 offset[0] = 0; offset[1] = 1;
182 iit.ActivateOffset(offset);
183 mit.ActivateOffset(offset);
185 iit.ActivateOffset(offset);
186 mit.ActivateOffset(offset);
193 while(!iit.IsAtEnd())
195 if(mit.GetCenterPixel() == 0)
198 for (
auto i = iit.Begin(); ! i.IsAtEnd(); i++)
204 oit.Set((mean+0.5)/6.0);
208 oit.Set(iit.GetCenterPixel());
218 template<
typename TImageType >
219 void mitk::CLUtil::itkCreateCheckerboardMask(TImageType * image,
mitk::Image::Pointer & outimage)
222 zeroimg->SetRegions(image->GetLargestPossibleRegion());
223 zeroimg->SetDirection(image->GetDirection());
224 zeroimg->SetOrigin(image->GetOrigin());
225 zeroimg->SetSpacing(image->GetSpacing());
228 zeroimg->FillBuffer(0);
230 typedef itk::CheckerBoardImageFilter<TImageType> FilterType;
232 filter->SetInput1(image);
233 filter->SetInput2(zeroimg);
234 typename FilterType::PatternArrayType pattern;
235 pattern.SetElement(0,(image->GetLargestPossibleRegion().GetSize()[0]));
236 pattern.SetElement(1,(image->GetLargestPossibleRegion().GetSize()[1]));
237 pattern.SetElement(2,(image->GetLargestPossibleRegion().GetSize()[2]));
238 filter->SetCheckerPattern(pattern);
245 template <
class TImageType>
251 itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion());
252 itk::ImageRegionConstIterator< itk::Image<double,3> > sourceIter(itk_source, itk_source->GetLargestPossibleRegion());
253 while(!inputIter.IsAtEnd())
255 if(inputIter.Value() == label) val += sourceIter.Value();
261 template <
class TImageType>
267 itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion());
268 itk::ImageRegionConstIterator< itk::Image<double,3> > sourceIter(itk_source, itk_source->GetLargestPossibleRegion());
269 while(!inputIter.IsAtEnd())
271 if(inputIter.Value() == label) val += sourceIter.Value() * sourceIter.Value();
277 template<
typename TStructuringElement>
278 void mitk::CLUtil::itkFitStructuringElement(TStructuringElement & se, MorphologicalDimensions d,
int factor)
280 typename TStructuringElement::SizeType size;
286 size.SetElement(2,0);
289 size.SetElement(0,0);
292 size.SetElement(1,0);
296 se.CreateStructuringElement();
299 template<
typename TImageType>
300 void mitk::CLUtil::itkClosingBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int factor, MorphologicalDimensions d)
302 typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
303 typedef itk::BinaryMorphologicalClosingImageFilter<TImageType, TImageType, BallType> FilterType;
306 itkFitStructuringElement(strElem,d,factor);
309 erodeFilter->SetKernel(strElem);
310 erodeFilter->SetInput(sourceImage);
311 erodeFilter->SetForegroundValue(1);
312 erodeFilter->Update();
318 template<
typename TImageType>
319 void mitk::CLUtil::itkDilateBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int factor, MorphologicalDimensions d)
321 typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
322 typedef typename itk::BinaryDilateImageFilter<TImageType, TImageType, BallType> BallDilateFilterType;
325 itkFitStructuringElement(strElem,d,factor);
328 erodeFilter->SetKernel(strElem);
329 erodeFilter->SetInput(sourceImage);
330 erodeFilter->SetDilateValue(1);
331 erodeFilter->Update();
337 template<
typename TImageType>
338 void mitk::CLUtil::itkErodeBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int factor, MorphologicalDimensions d)
340 typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
341 typedef typename itk::BinaryErodeImageFilter<TImageType, TImageType, BallType> BallErodeFilterType;
344 itkFitStructuringElement(strElem,d,factor);
348 erodeFilter->SetKernel(strElem);
349 erodeFilter->SetInput(sourceImage);
350 erodeFilter->SetErodeValue(1);
352 erodeFilter->Update();
363 template<
typename TPixel,
unsigned int VDimension>
364 void mitk::CLUtil::itkFillHolesBinary(itk::Image<TPixel, VDimension>* sourceImage,
mitk::Image::Pointer& resultImage)
366 typedef itk::Image<TPixel, VDimension>
ImageType;
367 typedef typename itk::BinaryFillholeImageFilter<ImageType> FillHoleFilterType;
370 fillHoleFilter->SetInput(sourceImage);
371 fillHoleFilter->SetForegroundValue(1);
372 fillHoleFilter->Update();
382 template<
typename TImageType>
387 itk_outimage->SetRegions(image1->GetLargestPossibleRegion());
388 itk_outimage->SetDirection(image1->GetDirection());
389 itk_outimage->SetOrigin(image1->GetOrigin());
390 itk_outimage->SetSpacing(image1->GetSpacing());
392 itk_outimage->Allocate();
393 itk_outimage->FillBuffer(0);
398 itk::ImageRegionConstIterator<TImageType> it1(image1, image1->GetLargestPossibleRegion());
399 itk::ImageRegionConstIterator<TImageType> it2(itk_image2, itk_image2->GetLargestPossibleRegion());
400 itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());
402 while(!it1.IsAtEnd())
404 if(it1.Value() == 0 || it2.Value() == 0)
408 oit.Set(it1.Value());
423 template<
class TImageType>
424 void mitk::CLUtil::itkGaussianFilter(TImageType * image,
mitk::Image::Pointer & smoothed ,
double sigma)
426 typedef itk::DiscreteGaussianImageFilter<TImageType,TImageType> FilterType;
428 filter->SetInput(image);
429 filter->SetVariance(sigma);
435 template<
class TImageType>
438 typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> StructureElementType;
439 typedef itk::GrayscaleErodeImageFilter<TImageType,TImageType,StructureElementType> FilterType;
441 StructureElementType ball;
442 itkFitStructuringElement(ball,d, radius);
445 filter->SetKernel(ball);
446 filter->SetInput(image);
452 template<
class TImageType>
455 typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> StructureElementType;
456 typedef itk::GrayscaleDilateImageFilter<TImageType,TImageType,StructureElementType> FilterType;
458 StructureElementType ball;
459 itkFitStructuringElement(ball,d, radius);
462 filter->SetKernel(ball);
463 filter->SetInput(image);
469 template<
class TImageType>
472 typedef itk::GrayscaleFillholeImageFilter<TImageType,TImageType> FilterType;
475 filter->SetInput(image);
static void ConnectedComponentsImage(mitk::Image::Pointer &image, mitk::Image::Pointer &mask, mitk::Image::Pointer &outimage, unsigned int &num_components)
ConnectedComponentsImage.
static void LogicalAndImages(const Image::Pointer &image1, const Image::Pointer &image2, Image::Pointer &outimage)
LogicalAndImages.
itk::SmartPointer< Self > Pointer
MorphologicalDimensions
The MorphologicalDimensions enum.
static void GrabLabel(mitk::Image::Pointer &image, mitk::Image::Pointer &outimage, unsigned int label)
GrabLabel.
static void ErodeBinary(mitk::Image::Pointer &sourceImage, mitk::Image::Pointer &resultImage, int radius, MorphologicalDimensions d)
ErodeBinary.
itk::SmartPointer< Self > Pointer
static void GaussianFilter(mitk::Image::Pointer image, mitk::Image::Pointer &smoothed, double sigma)
GaussianFilter.
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
#define AccessFixedDimensionByItk_3(mitkImage, itkImageTypeFunction, dimension, arg1, arg2, arg3)
static void DilateGrayscale(mitk::Image::Pointer &image, unsigned int radius, mitk::CLUtil::MorphologicalDimensions d, mitk::Image::Pointer &outimage)
DilateGrayscale.
static void FillHoleGrayscale(mitk::Image::Pointer &image, mitk::Image::Pointer &outimage)
FillHoleGrayscale.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
static void DilateBinary(mitk::Image::Pointer &sourceImage, mitk::Image::Pointer &resultImage, int radius, MorphologicalDimensions d)
DilateBinary.
static void ErodeGrayscale(mitk::Image::Pointer &image, unsigned int radius, mitk::CLUtil::MorphologicalDimensions d, mitk::Image::Pointer &outimage)
ErodeGrayscale.
static void InterpolateCheckerboardPrediction(mitk::Image::Pointer checkerboard_prediction, mitk::Image::Pointer &checkerboard_mask, mitk::Image::Pointer &outimage)
InterpolateCreateCheckerboardPrediction.
#define AccessFixedDimensionByItk_2(mitkImage, itkImageTypeFunction, dimension, arg1, arg2)
static void InsertLabel(mitk::Image::Pointer &image, mitk::Image::Pointer &maskImage, unsigned int label)
itkInsertLabel
static void ProbabilityMap(const mitk::Image::Pointer &sourceImage, double mean, double std_dev, mitk::Image::Pointer &resultImage)
ProbabilityMap.
static void itkCountVoxel(TImageType *image, std::map< unsigned int, unsigned int > &map)
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
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 ClosingBinary(mitk::Image::Pointer &sourceImage, mitk::Image::Pointer &resultImage, int radius, MorphologicalDimensions d)
ClosingBinary.
static void MergeLabels(mitk::Image::Pointer &img, const std::map< unsigned int, unsigned int > &map)
MergeLabels.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
static void CreateCheckerboardMask(mitk::Image::Pointer image, mitk::Image::Pointer &outimage)
CreateCheckerBoardPredictionMask.
static void CountVoxel(mitk::Image::Pointer image, std::map< unsigned int, unsigned int > &map)
CountVoxel.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.