6 #include <itkImageRegionIterator.h>
13 #include <itkConnectedComponentImageFilter.h>
104 template<
typename TMatrixElementType>
111 itk_img->SetRegions(itkMask->GetLargestPossibleRegion());
112 itk_img->SetOrigin(itkMask->GetOrigin());
113 itk_img->SetSpacing(itkMask->GetSpacing());
114 itk_img->SetDirection(itkMask->GetDirection());
118 unsigned int n_numSamples = 0;
121 if(n_numSamples != matrix.rows())
122 MITK_ERROR <<
"Number of samples in matrix and number of points under the masks is not the same!";
124 auto mit = itk::ImageRegionConstIterator<itk::Image<unsigned int, 3> >(itkMask, itkMask->GetLargestPossibleRegion());
125 auto oit = itk::ImageRegionIterator<itk::Image<TMatrixElementType, 3> >(itk_img, itk_img->GetLargestPossibleRegion());
127 unsigned int current_row = 0;
128 while(!mit.IsAtEnd())
131 oit.Set(matrix(current_row++,0));
148 template<
typename TMatrixElementType>
154 unsigned int n_numSamples = 0;
160 Eigen::Matrix<TMatrixElementType, Eigen::Dynamic, Eigen::Dynamic> out_matrix(n_numSamples,1);
162 auto mit = itk::ImageRegionConstIterator<itk::Image<unsigned int, 3> >(current_mask, current_mask->GetLargestPossibleRegion());
163 auto iit = itk::ImageRegionConstIterator<itk::Image<TMatrixElementType, 3> >(current_img,current_img->GetLargestPossibleRegion());
164 unsigned int current_row = 0;
165 while (!mit.IsAtEnd()) {
167 out_matrix(current_row++) = iit.Value();
270 template<
class TImageType>
273 auto it = itk::ImageRegionIterator< TImageType >(image,image->GetLargestPossibleRegion());
276 if(map.find(it.Value()) == map.end())
283 template <
class TImageType>
286 itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion());
287 while(!inputIter.IsAtEnd())
289 if(inputIter.Value() == label) ++count;
294 template<
typename TImageType>
295 static inline void itkCountVoxel(TImageType * mask,
unsigned int & n_numSamples)
297 auto mit = itk::ImageRegionConstIterator<TImageType>(mask, mask->GetLargestPossibleRegion());
298 while (!mit.IsAtEnd())
306 template <
class TImageType1,
class TImageType2>
307 static void itkSampleLabel(TImageType1* image, TImageType2* output,
double acceptrate,
unsigned int label)
309 std::srand (time(NULL));
311 itk::ImageRegionConstIterator< TImageType1 > inputIter(image, image->GetLargestPossibleRegion());
312 itk::ImageRegionIterator< TImageType2 > outputIter(output, output->GetLargestPossibleRegion());
314 while (!inputIter.IsAtEnd())
316 double r = (double)(rand()) / RAND_MAX;
317 if(inputIter.Get() == label && r < acceptrate)
318 outputIter.Set(label);
325 template <
class TImageType>
328 std::srand (time(NULL));
331 itk_out->SetRegions(image->GetLargestPossibleRegion());
332 itk_out->SetDirection(image->GetDirection());
333 itk_out->SetOrigin(image->GetOrigin());
334 itk_out->SetSpacing(image->GetSpacing());
336 itk_out->FillBuffer(0);
338 itk::ImageRegionConstIterator< TImageType > inputIter(image, image->GetLargestPossibleRegion());
339 itk::ImageRegionIterator< TImageType > outputIter(itk_out, itk_out->GetLargestPossibleRegion());
341 for(
unsigned int i = 0 ; i < n_samples_drawn ;)
343 double r = (double)(rand()) / RAND_MAX;
344 if(inputIter.Value() != 0 && r < 0.01 && outputIter.Value() == 0)
346 outputIter.Set(inputIter.Value());
352 if(inputIter.IsAtEnd())
354 inputIter.GoToBegin();
355 outputIter.GoToBegin();
365 template<
class TImageType>
368 template<
class TImageType>
371 template<
class TImageType>
374 template<
typename TImageType >
375 static void itkInsertLabel(TImageType * maskImage,
mitk::Image::Pointer & outimage,
unsigned int label)
380 if(outimage.IsNull())
384 itk_out->SetSpacing(maskImage->GetSpacing());
385 itk_out->SetDirection(maskImage->GetDirection());
386 itk_out->SetOrigin(maskImage->GetOrigin());
387 itk_out->SetRegions(maskImage->GetLargestPossibleRegion());
389 itk_out->FillBuffer(0);
395 itk::ImageRegionIterator<TImageType> oit(itk_out,itk_out->GetLargestPossibleRegion());
396 itk::ImageRegionConstIterator<TImageType> mit(maskImage,maskImage->GetLargestPossibleRegion());
398 while(!mit.IsAtEnd())
412 template<
typename TImageType >
413 static void itkGrabLabel(TImageType * image,
mitk::Image::Pointer & outimage,
unsigned int label)
415 typedef itk::Image<unsigned short, 3> TOutType;
417 itk_out->SetRegions(image->GetLargestPossibleRegion());
418 itk_out->SetDirection(image->GetDirection());
419 itk_out->SetOrigin(image->GetOrigin());
420 itk_out->SetSpacing(image->GetSpacing());
423 itk::ImageRegionConstIterator<TImageType> iit(image, image->GetLargestPossibleRegion());
424 itk::ImageRegionIterator<TOutType> oit(itk_out,itk_out->GetLargestPossibleRegion());
426 while(!iit.IsAtEnd())
440 template<
class TImagetype>
441 static void itkMergeLabels(TImagetype * img,
const std::map<unsigned int, unsigned int> &
map)
444 auto it = itk::ImageRegionIterator<TImagetype>(img,img->GetLargestPossibleRegion());
448 if(map.find(it.Value())!=map.end())
449 it.Set( map.at(it.Value()) );
455 template<
typename TImageType>
463 itk_mask->SetRegions(image->GetLargestPossibleRegion());
464 itk_mask->SetDirection(image->GetDirection());
465 itk_mask->SetOrigin(image->GetOrigin());
466 itk_mask->SetSpacing(image->GetSpacing());
467 itk_mask->Allocate();
468 itk_mask->FillBuffer(1);
473 typedef itk::ConnectedComponentImageFilter<TImageType, MaskImageType, MaskImageType > FilterType;
475 cc_filter->SetMaskImage(itk_mask.GetPointer());
476 cc_filter->SetInput(image);
477 cc_filter->SetBackgroundValue(0);
480 num_components = cc_filter->GetObjectCount();
484 template<
typename TImageType >
487 template<
typename TImageType >
490 template <
class TImageType>
493 template <
class TImageType>
496 template<
typename TStructuringElement>
497 static void itkFitStructuringElement(TStructuringElement & se, MorphologicalDimensions d,
int radius);
499 template<
typename TImageType>
500 static void itkDilateBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int radius , MorphologicalDimensions d);
502 template<
typename TImageType>
503 static void itkErodeBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int radius, MorphologicalDimensions d);
505 template<
typename TImageType>
506 static void itkClosingBinary(TImageType * sourceImage,
mitk::Image::Pointer& resultImage,
int radius, MorphologicalDimensions d);
508 template<
typename TPixel,
unsigned int VDimension>
509 static void itkFillHolesBinary(itk::Image<TPixel, VDimension>* sourceImage,
mitk::Image::Pointer& resultImage);
511 template<
typename TImageType>
514 template<
class TImageType>
515 static void itkGaussianFilter(TImageType * image,
mitk::Image::Pointer & smoothed ,
double sigma);
517 template<
typename TImageType>
518 static void itkProbabilityMap(
const TImageType * sourceImage,
double mean,
double std_dev,
mitk::Image::Pointer& resultImage);
itk::SmartPointer< Self > Pointer
MorphologicalDimensions
The MorphologicalDimensions enum.
static void itkSampleLabel(TImageType1 *image, TImageType2 *output, double acceptrate, unsigned int label)
DataCollection - Class to facilitate loading/accessing structured data.
static mitk::Image::Pointer Transform(const Eigen::Matrix< TMatrixElementType, Eigen::Dynamic, Eigen::Dynamic > &matrix, const mitk::Image::Pointer &mask)
transform
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.
void GaussianFilter(itk::Image< TPixel, VImageDimension > *itkImage, double variance, mitk::Image::Pointer &output)
static Eigen::Matrix< TMatrixElementType, Eigen::Dynamic, Eigen::Dynamic > Transform(const mitk::Image::Pointer &img, const mitk::Image::Pointer &mask)
TransformImageToMatrix.
itk::Image< unsigned char, 3 > MaskImageType
static void itkCountVoxel(TImageType *image, std::map< unsigned int, unsigned int > &map)
static void itkCountVoxel(TImageType *image, typename TImageType::PixelType label, unsigned int &count)
#define MITKCLUTILITIES_EXPORT
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 CountVoxel(mitk::Image::Pointer image, std::map< unsigned int, unsigned int > &map)
CountVoxel.
static void itkSampleLabel(TImageType *image, mitk::Image::Pointer &output, unsigned int n_samples_drawn)
static void itkCountVoxel(TImageType *mask, unsigned int &n_numSamples)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.