Medical Imaging Interaction Toolkit  2018.4.99-b585543d
Medical Imaging Interaction Toolkit
mitkCLUtil.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef _mitkCLUtil_HXX
14 #define _mitkCLUtil_HXX
15 
16 #include <mitkCLUtil.h>
17 
18 #include <mitkImageAccessByItk.h>
19 
20 
21 
22 #include <Eigen/Dense>
23 #include <itkImage.h>
24 
25 // itk includes
26 #include <itkCheckerBoardImageFilter.h>
27 #include <itkShapedNeighborhoodIterator.h>
28 #include "itkHessianRecursiveGaussianImageFilter.h"
29 #include "itkUnaryFunctorImageFilter.h"
30 #include "vnl/algo/vnl_symmetric_eigensystem.h"
31 #include <itkLaplacianRecursiveGaussianImageFilter.h>
33 
34 // Morphologic Operations
35 #include <itkBinaryBallStructuringElement.h>
36 #include <itkBinaryDilateImageFilter.h>
37 #include <itkBinaryErodeImageFilter.h>
38 #include <itkBinaryFillholeImageFilter.h>
39 #include <itkBinaryMorphologicalClosingImageFilter.h>
40 #include <itkGrayscaleErodeImageFilter.h>
41 #include <itkGrayscaleDilateImageFilter.h>
42 #include <itkGrayscaleFillholeImageFilter.h>
43 
44 // Image Filter
45 #include <itkDiscreteGaussianImageFilter.h>
46 #include <itkSubtractImageFilter.h>
47 
48 void mitk::CLUtil::ProbabilityMap(const mitk::Image::Pointer & image , double mean, double stddev, mitk::Image::Pointer & outimage)
49 {
50  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkProbabilityMap, 3, mean, stddev, outimage);
51 }
52 
54 {
55  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkErodeGrayscale, 3, outimage, radius, d);
56 }
57 
59 {
60  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkDilateGrayscale, 3, outimage, radius, d);
61 }
62 
64 {
65  AccessFixedDimensionByItk_1(image, mitk::CLUtil::itkFillHoleGrayscale, 3, outimage);
66 }
67 
69 {
70  AccessByItk_2(image, mitk::CLUtil::itkInsertLabel, maskImage, label);
71 }
72 
74 {
75  AccessFixedDimensionByItk_2(image, mitk::CLUtil::itkGrabLabel, 3, outimage, label);
76 }
77 
79 {
80  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkConnectedComponentsImage,3, mask, outimage, num_components);
81 }
82 
83 void mitk::CLUtil::MergeLabels(mitk::Image::Pointer & img, const std::map<unsigned int, unsigned int> & map)
84 {
85  AccessByItk_1(img, mitk::CLUtil::itkMergeLabels, map);
86 }
87 
88 void mitk::CLUtil::CountVoxel(mitk::Image::Pointer image, std::map<unsigned int, unsigned int> & map)
89 {
91 }
92 
93 void mitk::CLUtil::CountVoxel(mitk::Image::Pointer image, unsigned int label, unsigned int & count)
94 {
95  AccessByItk_2(image, mitk::CLUtil::itkCountVoxel, label, count);
96 }
97 
99 {
101 }
102 
104 {
105  AccessFixedDimensionByItk_1(image, mitk::CLUtil::itkCreateCheckerboardMask,3, outimage);
106 }
107 
109 {
110  AccessFixedDimensionByItk_2(image1,itkLogicalAndImages, 3, image2, outimage);
111 
112 }
113 
115 {
116  AccessFixedDimensionByItk_2(checkerboard_prediction, mitk::CLUtil::itkInterpolateCheckerboardPrediction,3, checkerboard_mask, outimage);
117 }
118 
120 {
121  AccessFixedDimensionByItk_2(image, mitk::CLUtil::itkGaussianFilter,3, smoothed, sigma);
122 }
123 
125 {
126  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkDifferenceOfGaussianFilter, 3, smoothed, sigma1, sigma2);
127 }
128 
130 {
131  AccessByItk_2(image, mitk::CLUtil::itkLaplacianOfGaussianFilter, sigma1, smoothed);
132 }
133 
134 void mitk::CLUtil::HessianOfGaussianFilter(mitk::Image::Pointer image, std::vector<mitk::Image::Pointer> &out, double sigma)
135 {
136  AccessByItk_2(image, mitk::CLUtil::itkHessianOfGaussianFilter, sigma, out);
137 }
138 
139 void mitk::CLUtil::LocalHistogram(mitk::Image::Pointer image, std::vector<mitk::Image::Pointer> &out, int Bins, int NeighbourhoodSize)
140 {
141  AccessByItk_3(image, mitk::CLUtil::itkLocalHistograms, out, NeighbourhoodSize, Bins);
142 }
143 
144 
145 
147 {
148  AccessFixedDimensionByItk_3(sourceImage, mitk::CLUtil::itkDilateBinary, 3, resultImage, factor, d);
149 }
150 
151 
153 {
154  AccessFixedDimensionByItk_3(sourceImage, mitk::CLUtil::itkErodeBinary, 3, resultImage, factor, d);
155 }
156 
157 
159 {
160  AccessFixedDimensionByItk_3(sourceImage, mitk::CLUtil::itkClosingBinary, 3, resultImage, factor, d);
161 }
162 
163 template<typename TImageType>
164 void mitk::CLUtil::itkProbabilityMap(const TImageType * sourceImage, double mean, double std_dev, mitk::Image::Pointer& resultImage)
165 {
166  itk::Image<double, 3>::Pointer itk_img = itk::Image<double, 3>::New();
167  itk_img->SetRegions(sourceImage->GetLargestPossibleRegion());
168  itk_img->SetOrigin(sourceImage->GetOrigin());
169  itk_img->SetSpacing(sourceImage->GetSpacing());
170  itk_img->SetDirection(sourceImage->GetDirection());
171  itk_img->Allocate();
172 
173 
174  itk::ImageRegionConstIterator<TImageType> it(sourceImage,sourceImage->GetLargestPossibleRegion());
175  itk::ImageRegionIterator<itk::Image<double, 3> > outit(itk_img,itk_img->GetLargestPossibleRegion());
176 
177  while(!it.IsAtEnd())
178  {
179  double x = it.Value();
180 
181  double prob = (1.0/(std_dev*std::sqrt(2.0*itk::Math::pi))) * std::exp(-(((x-mean)*(x-mean))/(2.0*std_dev*std_dev)));
182  outit.Set(prob);
183  ++it;
184  ++outit;
185  }
186 
187  mitk::CastToMitkImage(itk_img, resultImage);
188 }
189 
190 template< typename TImageType >
191 void mitk::CLUtil::itkInterpolateCheckerboardPrediction(TImageType * checkerboard_prediction, Image::Pointer &checkerboard_mask, mitk::Image::Pointer & outimage)
192 {
193  typename TImageType::Pointer itk_checkerboard_mask;
194  mitk::CastToItkImage(checkerboard_mask,itk_checkerboard_mask);
195 
196  typename TImageType::Pointer itk_outimage = TImageType::New();
197  itk_outimage->SetRegions(checkerboard_prediction->GetLargestPossibleRegion());
198  itk_outimage->SetDirection(checkerboard_prediction->GetDirection());
199  itk_outimage->SetOrigin(checkerboard_prediction->GetOrigin());
200  itk_outimage->SetSpacing(checkerboard_prediction->GetSpacing());
201  itk_outimage->Allocate();
202  itk_outimage->FillBuffer(0);
203 
204  //typedef typename itk::ShapedNeighborhoodIterator<TImageType>::SizeType SizeType;
205  typedef itk::Size<3> SizeType;
206  SizeType size;
207  size.Fill(1);
208  itk::ShapedNeighborhoodIterator<TImageType> iit(size,checkerboard_prediction,checkerboard_prediction->GetLargestPossibleRegion());
209  itk::ShapedNeighborhoodIterator<TImageType> mit(size,itk_checkerboard_mask,itk_checkerboard_mask->GetLargestPossibleRegion());
210  itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());
211 
212  typedef typename itk::ShapedNeighborhoodIterator<TImageType>::OffsetType OffsetType;
213  OffsetType offset;
214  offset.Fill(0);
215  offset[0] = 1; // {1,0,0}
216  iit.ActivateOffset(offset);
217  mit.ActivateOffset(offset);
218  offset[0] = -1; // {-1,0,0}
219  iit.ActivateOffset(offset);
220  mit.ActivateOffset(offset);
221  offset[0] = 0; offset[1] = 1; //{0,1,0}
222  iit.ActivateOffset(offset);
223  mit.ActivateOffset(offset);
224  offset[1] = -1; //{0,-1,0}
225  iit.ActivateOffset(offset);
226  mit.ActivateOffset(offset);
227 
228  // iit.ActivateOffset({{0,0,1}});
229  // iit.ActivateOffset({{0,0,-1}});
230  // mit.ActivateOffset({{0,0,1}});
231  // mit.ActivateOffset({{0,0,-1}});
232 
233  while(!iit.IsAtEnd())
234  {
235  if(mit.GetCenterPixel() == 0)
236  {
237  typename TImageType::PixelType mean = 0;
238  for (auto i = iit.Begin(); ! i.IsAtEnd(); i++)
239  { mean += i.Get(); }
240 
241 
242  //std::sort(list.begin(),list.end(),[](const typename TImageType::PixelType x,const typename TImageType::PixelType y){return x<=y;});
243 
244  oit.Set((mean+0.5)/6.0);
245  }
246  else
247  {
248  oit.Set(iit.GetCenterPixel());
249  }
250  ++iit;
251  ++mit;
252  ++oit;
253  }
254 
255  mitk::CastToMitkImage(itk_outimage,outimage);
256 }
257 
258 template< typename TImageType >
259 void mitk::CLUtil::itkCreateCheckerboardMask(TImageType * image, mitk::Image::Pointer & outimage)
260 {
261  typename TImageType::Pointer zeroimg = TImageType::New();
262  zeroimg->SetRegions(image->GetLargestPossibleRegion());
263  zeroimg->SetDirection(image->GetDirection());
264  zeroimg->SetOrigin(image->GetOrigin());
265  zeroimg->SetSpacing(image->GetSpacing());
266 
267  zeroimg->Allocate();
268  zeroimg->FillBuffer(0);
269 
270  typedef itk::CheckerBoardImageFilter<TImageType> FilterType;
271  typename FilterType::Pointer filter = FilterType::New();
272  filter->SetInput1(image);
273  filter->SetInput2(zeroimg);
274  typename FilterType::PatternArrayType pattern;
275  pattern.SetElement(0,(image->GetLargestPossibleRegion().GetSize()[0]));
276  pattern.SetElement(1,(image->GetLargestPossibleRegion().GetSize()[1]));
277  pattern.SetElement(2,(image->GetLargestPossibleRegion().GetSize()[2]));
278  filter->SetCheckerPattern(pattern);
279 
280  filter->Update();
281  mitk::CastToMitkImage(filter->GetOutput(), outimage);
282 }
283 
284 
285 template <class TImageType>
286 void mitk::CLUtil::itkSumVoxelForLabel(TImageType* image, const mitk::Image::Pointer & source , typename TImageType::PixelType label, double & val )
287 {
288  itk::Image<double,3>::Pointer itk_source;
289  mitk::CastToItkImage(source,itk_source);
290 
291  itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion());
292  itk::ImageRegionConstIterator< itk::Image<double,3> > sourceIter(itk_source, itk_source->GetLargestPossibleRegion());
293  while(!inputIter.IsAtEnd())
294  {
295  if(inputIter.Value() == label) val += sourceIter.Value();
296  ++inputIter;
297  ++sourceIter;
298  }
299 }
300 
301 template <class TImageType>
302 void mitk::CLUtil::itkSqSumVoxelForLabel(TImageType* image, const mitk::Image::Pointer & source, typename TImageType::PixelType label, double & val )
303 {
304  itk::Image<double,3>::Pointer itk_source;
305  mitk::CastToItkImage(source,itk_source);
306 
307  itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion());
308  itk::ImageRegionConstIterator< itk::Image<double,3> > sourceIter(itk_source, itk_source->GetLargestPossibleRegion());
309  while(!inputIter.IsAtEnd())
310  {
311  if(inputIter.Value() == label) val += sourceIter.Value() * sourceIter.Value();
312  ++inputIter;
313  ++sourceIter;
314  }
315 }
316 
317 template<typename TStructuringElement>
318 void mitk::CLUtil::itkFitStructuringElement(TStructuringElement & se, MorphologicalDimensions d, int factor)
319 {
320  typename TStructuringElement::SizeType size;
321  size.Fill(factor);
322  switch(d)
323  {
324  case(All):
325  case(Axial):
326  size.SetElement(2,0);
327  break;
328  case(Sagital):
329  size.SetElement(0,0);
330  break;
331  case(Coronal):
332  size.SetElement(1,0);
333  break;
334  }
335  se.SetRadius(size);
336  se.CreateStructuringElement();
337 }
338 
339 template<typename TImageType>
340 void mitk::CLUtil::itkClosingBinary(TImageType * sourceImage, mitk::Image::Pointer& resultImage, int factor, MorphologicalDimensions d)
341 {
342  typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
343  typedef itk::BinaryMorphologicalClosingImageFilter<TImageType, TImageType, BallType> FilterType;
344 
345  BallType strElem;
346  itkFitStructuringElement(strElem,d,factor);
347 
348  typename FilterType::Pointer erodeFilter = FilterType::New();
349  erodeFilter->SetKernel(strElem);
350  erodeFilter->SetInput(sourceImage);
351  erodeFilter->SetForegroundValue(1);
352  erodeFilter->Update();
353 
354  mitk::CastToMitkImage(erodeFilter->GetOutput(), resultImage);
355 
356 }
357 
358 template<typename TImageType>
359 void mitk::CLUtil::itkDilateBinary(TImageType * sourceImage, mitk::Image::Pointer& resultImage, int factor, MorphologicalDimensions d)
360 {
361  typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
362  typedef typename itk::BinaryDilateImageFilter<TImageType, TImageType, BallType> BallDilateFilterType;
363 
364  BallType strElem;
365  itkFitStructuringElement(strElem,d,factor);
366 
367  typename BallDilateFilterType::Pointer erodeFilter = BallDilateFilterType::New();
368  erodeFilter->SetKernel(strElem);
369  erodeFilter->SetInput(sourceImage);
370  erodeFilter->SetDilateValue(1);
371  erodeFilter->Update();
372 
373  mitk::CastToMitkImage(erodeFilter->GetOutput(), resultImage);
374 
375 }
376 
377 template<typename TImageType>
378 void mitk::CLUtil::itkErodeBinary(TImageType * sourceImage, mitk::Image::Pointer& resultImage, int factor, MorphologicalDimensions d)
379 {
380  typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> BallType;
381  typedef typename itk::BinaryErodeImageFilter<TImageType, TImageType, BallType> BallErodeFilterType;
382 
383  BallType strElem;
384  itkFitStructuringElement(strElem,d,factor);
385 
386 
387  typename BallErodeFilterType::Pointer erodeFilter = BallErodeFilterType::New();
388  erodeFilter->SetKernel(strElem);
389  erodeFilter->SetInput(sourceImage);
390  erodeFilter->SetErodeValue(1);
391 // erodeFilter->UpdateLargestPossibleRegion();
392  erodeFilter->Update();
393 
394  mitk::CastToMitkImage(erodeFilter->GetOutput(), resultImage);
395 
396 }
397 
403 template<typename TPixel, unsigned int VDimension>
404 void mitk::CLUtil::itkFillHolesBinary(itk::Image<TPixel, VDimension>* sourceImage, mitk::Image::Pointer& resultImage)
405 {
406  typedef itk::Image<TPixel, VDimension> ImageType;
407  typedef typename itk::BinaryFillholeImageFilter<ImageType> FillHoleFilterType;
408 
409  typename FillHoleFilterType::Pointer fillHoleFilter = FillHoleFilterType::New();
410  fillHoleFilter->SetInput(sourceImage);
411  fillHoleFilter->SetForegroundValue(1);
412  fillHoleFilter->Update();
413 
414  mitk::CastToMitkImage(fillHoleFilter->GetOutput(), resultImage);
415 }
416 
422 template<typename TImageType>
423 void mitk::CLUtil::itkLogicalAndImages(const TImageType * image1, const mitk::Image::Pointer & image2, mitk::Image::Pointer & outimage)
424 {
425 
426  typename TImageType::Pointer itk_outimage = TImageType::New();
427  itk_outimage->SetRegions(image1->GetLargestPossibleRegion());
428  itk_outimage->SetDirection(image1->GetDirection());
429  itk_outimage->SetOrigin(image1->GetOrigin());
430  itk_outimage->SetSpacing(image1->GetSpacing());
431 
432  itk_outimage->Allocate();
433  itk_outimage->FillBuffer(0);
434 
435  typename TImageType::Pointer itk_image2;
436  mitk::CastToItkImage(image2,itk_image2);
437 
438  itk::ImageRegionConstIterator<TImageType> it1(image1, image1->GetLargestPossibleRegion());
439  itk::ImageRegionConstIterator<TImageType> it2(itk_image2, itk_image2->GetLargestPossibleRegion());
440  itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());
441 
442  while(!it1.IsAtEnd())
443  {
444  if(it1.Value() == 0 || it2.Value() == 0)
445  {
446  oit.Set(0);
447  }else
448  oit.Set(it1.Value());
449  ++it1;
450  ++it2;
451  ++oit;
452  }
453 
454  mitk::CastToMitkImage(itk_outimage, outimage);
455 }
456 
463 template<class TImageType>
464 void mitk::CLUtil::itkGaussianFilter(TImageType * image, mitk::Image::Pointer & smoothed ,double sigma)
465 {
466  typedef itk::DiscreteGaussianImageFilter<TImageType,TImageType> FilterType;
467  typename FilterType::Pointer filter = FilterType::New();
468  filter->SetInput(image);
469  filter->SetVariance(sigma);
470  filter->Update();
471 
472  mitk::CastToMitkImage(filter->GetOutput(),smoothed);
473 }
474 
475 template<class TImageType>
476 void mitk::CLUtil::itkDifferenceOfGaussianFilter(TImageType * image, mitk::Image::Pointer & smoothed, double sigma1, double sigma2)
477 {
478  typedef itk::DiscreteGaussianImageFilter<TImageType, TImageType> FilterType;
479  typedef itk::SubtractImageFilter <TImageType, TImageType> SubtractFilterType;
480  typename FilterType::Pointer filter1 = FilterType::New();
481  typename FilterType::Pointer filter2 = FilterType::New();
482  typename SubtractFilterType::Pointer subFilter = SubtractFilterType::New();
483  filter1->SetInput(image);
484  filter1->SetVariance(sigma1);
485  filter1->Update();
486  filter2->SetInput(image);
487  filter2->SetVariance(sigma2);
488  filter2->Update();
489  subFilter->SetInput1(filter1->GetOutput());
490  subFilter->SetInput2(filter2->GetOutput());
491  subFilter->Update();
492 
493  mitk::CastToMitkImage(subFilter->GetOutput(), smoothed);
494 }
495 
496 
497 template<typename TPixel, unsigned int VImageDimension>
498 void mitk::CLUtil::itkLaplacianOfGaussianFilter(itk::Image<TPixel, VImageDimension>* itkImage, double variance, mitk::Image::Pointer &output)
499 {
500  typedef itk::Image<TPixel, VImageDimension> ImageType;
501  typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType > GaussFilterType;
502  typedef itk::LaplacianRecursiveGaussianImageFilter<ImageType, ImageType> LaplacianFilter;
503 
504  typename GaussFilterType::Pointer gaussianFilter = GaussFilterType::New();
505  gaussianFilter->SetInput(itkImage);
506  gaussianFilter->SetVariance(variance);
507  gaussianFilter->Update();
508  typename LaplacianFilter::Pointer laplaceFilter = LaplacianFilter::New();
509  laplaceFilter->SetInput(gaussianFilter->GetOutput());
510  laplaceFilter->Update();
511  mitk::CastToMitkImage(laplaceFilter->GetOutput(), output);
512 }
513 
514 namespace Functor
515 {
516  template <class TInput, class TOutput>
517  class MatrixFirstEigenvalue
518  {
519  public:
520  MatrixFirstEigenvalue() {}
521  virtual ~MatrixFirstEigenvalue() {}
522 
523  int order;
524 
525  inline TOutput operator ()(const TInput& input)
526  {
527  double a, b, c;
528  if (input[0] < 0.01 && input[1] < 0.01 &&input[2] < 0.01 &&input[3] < 0.01 &&input[4] < 0.01 &&input[5] < 0.01)
529  return 0;
530  vnl_symmetric_eigensystem_compute_eigenvals(input[0], input[1], input[2], input[3], input[4], input[5], a, b, c);
531  switch (order)
532  {
533  case 0: return a;
534  case 1: return b;
535  case 2: return c;
536  default: return a;
537  }
538  }
539  bool operator !=(const MatrixFirstEigenvalue) const
540  {
541  return false;
542  }
543  bool operator ==(const MatrixFirstEigenvalue& other) const
544  {
545  return !(*this != other);
546  }
547  };
548 }
549 
550 template<typename TPixel, unsigned int VImageDimension>
551 void mitk::CLUtil::itkHessianOfGaussianFilter(itk::Image<TPixel, VImageDimension>* itkImage, double variance, std::vector<mitk::Image::Pointer> &out)
552 {
553  typedef itk::Image<TPixel, VImageDimension> ImageType;
554  typedef itk::Image<double, VImageDimension> FloatImageType;
555  typedef itk::HessianRecursiveGaussianImageFilter <ImageType> HessianFilterType;
556  typedef typename HessianFilterType::OutputImageType VectorImageType;
557  typedef Functor::MatrixFirstEigenvalue<typename VectorImageType::PixelType, double> DeterminantFunctorType;
558  typedef itk::UnaryFunctorImageFilter<VectorImageType, FloatImageType, DeterminantFunctorType> DetFilterType;
559 
560  typename HessianFilterType::Pointer hessianFilter = HessianFilterType::New();
561  hessianFilter->SetInput(itkImage);
562  hessianFilter->SetSigma(std::sqrt(variance));
563  for (unsigned int i = 0; i < VImageDimension; ++i)
564  {
566  typename DetFilterType::Pointer detFilter = DetFilterType::New();
567  detFilter->SetInput(hessianFilter->GetOutput());
568  detFilter->GetFunctor().order = i;
569  detFilter->Update();
570  mitk::CastToMitkImage(detFilter->GetOutput(), tmpImage);
571  out.push_back(tmpImage);
572  }
573 }
574 
575 template<typename TPixel, unsigned int VImageDimension>
576 void mitk::CLUtil::itkLocalHistograms(itk::Image<TPixel, VImageDimension>* itkImage, std::vector<mitk::Image::Pointer> &out, int size, int bins)
577 {
578  typedef itk::Image<TPixel, VImageDimension> ImageType;
579  typedef itk::MultiHistogramFilter <ImageType, ImageType> MultiHistogramType;
580 
581  typename MultiHistogramType::Pointer filter = MultiHistogramType::New();
582  filter->SetInput(itkImage);
583  filter->SetUseImageIntensityRange(true);
584  filter->SetSize(size);
585  filter->SetBins(bins);
586  filter->Update();
587  for (int i = 0; i < bins; ++i)
588  {
590  mitk::CastToMitkImage(filter->GetOutput(i), img);
591  out.push_back(img);
592  }
593 }
594 
595 template<class TImageType>
596 void mitk::CLUtil::itkErodeGrayscale(TImageType * image, mitk::Image::Pointer & outimage , unsigned int radius, mitk::CLUtil::MorphologicalDimensions d)
597 {
598  typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> StructureElementType;
599  typedef itk::GrayscaleErodeImageFilter<TImageType,TImageType,StructureElementType> FilterType;
600 
601  StructureElementType ball;
602  itkFitStructuringElement(ball,d, radius);
603 
604  typename FilterType::Pointer filter = FilterType::New();
605  filter->SetKernel(ball);
606  filter->SetInput(image);
607  filter->Update();
608 
609  mitk::CastToMitkImage(filter->GetOutput(),outimage);
610 }
611 
612 template<class TImageType>
613 void mitk::CLUtil::itkDilateGrayscale(TImageType * image, mitk::Image::Pointer & outimage , unsigned int radius, mitk::CLUtil::MorphologicalDimensions d)
614 {
615  typedef itk::BinaryBallStructuringElement<typename TImageType::PixelType, 3> StructureElementType;
616  typedef itk::GrayscaleDilateImageFilter<TImageType,TImageType,StructureElementType> FilterType;
617 
618  StructureElementType ball;
619  itkFitStructuringElement(ball,d, radius);
620 
621  typename FilterType::Pointer filter = FilterType::New();
622  filter->SetKernel(ball);
623  filter->SetInput(image);
624  filter->Update();
625 
626  mitk::CastToMitkImage(filter->GetOutput(),outimage);
627 }
628 
629 template<class TImageType>
630 void mitk::CLUtil::itkFillHoleGrayscale(TImageType * image, mitk::Image::Pointer & outimage)
631 {
632  typedef itk::GrayscaleFillholeImageFilter<TImageType,TImageType> FilterType;
633 
634  typename FilterType::Pointer filter = FilterType::New();
635  filter->SetInput(image);
636  filter->Update();
637 
638  mitk::CastToMitkImage(filter->GetOutput(),outimage);
639 }
640 
641 
642 #endif
static void ConnectedComponentsImage(mitk::Image::Pointer &image, mitk::Image::Pointer &mask, mitk::Image::Pointer &outimage, unsigned int &num_components)
ConnectedComponentsImage.
Definition: mitkCLUtil.cpp:78
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
static void LogicalAndImages(const Image::Pointer &image1, const Image::Pointer &image2, Image::Pointer &outimage)
LogicalAndImages.
Definition: mitkCLUtil.cpp:108
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
MorphologicalDimensions
The MorphologicalDimensions enum.
Definition: mitkCLUtil.h:35
static void LocalHistogram(mitk::Image::Pointer image, std::vector< mitk::Image::Pointer > &out, int Bins, int NeighbourhoodSize)
Local Histogram.
Definition: mitkCLUtil.cpp:139
static void GrabLabel(mitk::Image::Pointer &image, mitk::Image::Pointer &outimage, unsigned int label)
GrabLabel.
Definition: mitkCLUtil.cpp:73
itk::Image< unsigned char, 3 > ImageType
static void ErodeBinary(mitk::Image::Pointer &sourceImage, mitk::Image::Pointer &resultImage, int radius, MorphologicalDimensions d)
ErodeBinary.
Definition: mitkCLUtil.cpp:152
static void HessianOfGaussianFilter(mitk::Image::Pointer image, std::vector< mitk::Image::Pointer > &out, double sigma)
SubtractGaussianFilter.
Definition: mitkCLUtil.cpp:134
itk::Image< double, 3 > FloatImageType
Definition: CLBrainMask.cpp:31
static void GaussianFilter(mitk::Image::Pointer image, mitk::Image::Pointer &smoothed, double sigma)
GaussianFilter.
Definition: mitkCLUtil.cpp:119
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
#define AccessFixedDimensionByItk_3(mitkImage, itkImageTypeFunction, dimension, arg1, arg2, arg3)
static void DifferenceOfGaussianFilter(mitk::Image::Pointer image, mitk::Image::Pointer &smoothed, double sigma1, double sigma2)
SubtractGaussianFilter.
Definition: mitkCLUtil.cpp:124
static void DilateGrayscale(mitk::Image::Pointer &image, unsigned int radius, mitk::CLUtil::MorphologicalDimensions d, mitk::Image::Pointer &outimage)
DilateGrayscale.
Definition: mitkCLUtil.cpp:58
static Vector3D offset
static void FillHoleGrayscale(mitk::Image::Pointer &image, mitk::Image::Pointer &outimage)
FillHoleGrayscale.
Definition: mitkCLUtil.cpp:63
static void DilateBinary(mitk::Image::Pointer &sourceImage, mitk::Image::Pointer &resultImage, int radius, MorphologicalDimensions d)
DilateBinary.
Definition: mitkCLUtil.cpp:146
static void ErodeGrayscale(mitk::Image::Pointer &image, unsigned int radius, mitk::CLUtil::MorphologicalDimensions d, mitk::Image::Pointer &outimage)
ErodeGrayscale.
Definition: mitkCLUtil.cpp:53
static void InterpolateCheckerboardPrediction(mitk::Image::Pointer checkerboard_prediction, mitk::Image::Pointer &checkerboard_mask, mitk::Image::Pointer &outimage)
InterpolateCreateCheckerboardPrediction.
Definition: mitkCLUtil.cpp:114
#define AccessFixedDimensionByItk_2(mitkImage, itkImageTypeFunction, dimension, arg1, arg2)
static void InsertLabel(mitk::Image::Pointer &image, mitk::Image::Pointer &maskImage, unsigned int label)
itkInsertLabel
Definition: mitkCLUtil.cpp:68
static void LaplacianOfGaussianFilter(mitk::Image::Pointer image, mitk::Image::Pointer &smoothed, double sigma1)
Laplacian of Gaussian.
Definition: mitkCLUtil.cpp:129
static void ProbabilityMap(const mitk::Image::Pointer &sourceImage, double mean, double std_dev, mitk::Image::Pointer &resultImage)
ProbabilityMap.
Definition: mitkCLUtil.cpp:48
static void itkCountVoxel(TImageType *image, std::map< unsigned int, unsigned int > &map)
Definition: mitkCLUtil.h:319
mitk::Image::Pointer image
static Pointer New()
#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.
Definition: mitkImageCast.h:74
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.
Definition: mitkCLUtil.cpp:158
static void MergeLabels(mitk::Image::Pointer &img, const std::map< unsigned int, unsigned int > &map)
MergeLabels.
Definition: mitkCLUtil.cpp:83
mitk::Image::Pointer mask
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
static void CreateCheckerboardMask(mitk::Image::Pointer image, mitk::Image::Pointer &outimage)
CreateCheckerBoardPredictionMask.
Definition: mitkCLUtil.cpp:103
static void CountVoxel(mitk::Image::Pointer image, std::map< unsigned int, unsigned int > &map)
CountVoxel.
Definition: mitkCLUtil.cpp:88