18 #include <itkBinaryBallStructuringElement.h>
19 #include <itkBinaryCrossStructuringElement.h>
20 #include <itkBinaryDilateImageFilter.h>
21 #include <itkBinaryErodeImageFilter.h>
22 #include <itkBinaryFillholeImageFilter.h>
23 #include <itkBinaryMorphologicalClosingImageFilter.h>
24 #include <itkBinaryMorphologicalOpeningImageFilter.h>
36 int timeSteps =
static_cast<int>(image->GetTimeSteps());
41 timeSelector->SetInput(image);
43 for (
int t = 0; t < timeSteps; ++t)
45 MITK_INFO <<
" Processing time step " << t;
47 timeSelector->SetTimeNr(t);
48 timeSelector->Update();
51 img3D->DisconnectPipeline();
53 AccessByItk_3(img3D, itkClosing, img3D, factor, structuralElement);
56 image->SetVolume(accessor.
GetData(), t);
61 AccessByItk_3(image, itkClosing, image, factor, structuralElement);
73 int timeSteps =
static_cast<int>(image->GetTimeSteps());
78 timeSelector->SetInput(image);
80 for (
int t = 0; t < timeSteps; ++t)
82 MITK_INFO <<
" Processing time step " << t;
84 timeSelector->SetTimeNr(t);
85 timeSelector->Update();
88 img3D->DisconnectPipeline();
90 AccessByItk_3(img3D, itkErode, img3D, factor, structuralElement);
93 image->SetVolume(accessor.
GetData(), t);
98 AccessByItk_3(image, itkErode, image, factor, structuralElement);
110 int timeSteps =
static_cast<int>(image->GetTimeSteps());
115 timeSelector->SetInput(image);
117 for (
int t = 0; t < timeSteps; ++t)
119 MITK_INFO <<
" Processing time step " << t;
121 timeSelector->SetTimeNr(t);
122 timeSelector->Update();
125 img3D->DisconnectPipeline();
127 AccessByItk_3(img3D, itkDilate, img3D, factor, structuralElement);
130 image->SetVolume(accessor.
GetData(), t);
135 AccessByItk_3(image, itkDilate, image, factor, structuralElement);
147 int timeSteps =
static_cast<int>(image->GetTimeSteps());
152 timeSelector->SetInput(image);
154 for (
int t = 0; t < timeSteps; ++t)
156 MITK_INFO <<
" Processing time step " << t;
158 timeSelector->SetTimeNr(t);
159 timeSelector->Update();
162 img3D->DisconnectPipeline();
164 AccessByItk_3(img3D, itkOpening, img3D, factor, structuralElement);
167 image->SetVolume(accessor.
GetData(), t);
172 AccessByItk_3(image, itkOpening, image, factor, structuralElement);
182 int timeSteps =
static_cast<int>(image->GetTimeSteps());
187 timeSelector->SetInput(image);
189 for (
int t = 0; t < timeSteps; ++t)
191 MITK_INFO <<
" Processing time step " << t;
193 timeSelector->SetTimeNr(t);
194 timeSelector->Update();
197 img3D->DisconnectPipeline();
202 image->SetVolume(accessor.
GetData(), t);
213 template <
typename TPixel,
unsigned int VDimension>
214 void mitk::MorphologicalOperations::itkClosing(
215 itk::Image<TPixel, VDimension> *sourceImage,
220 typedef itk::Image<TPixel, VDimension>
ImageType;
221 typedef itk::BinaryBallStructuringElement<TPixel, VDimension> BallType;
222 typedef itk::BinaryCrossStructuringElement<TPixel, VDimension> CrossType;
223 typedef typename itk::BinaryMorphologicalClosingImageFilter<ImageType, ImageType, BallType> BallClosingFilterType;
224 typedef typename itk::BinaryMorphologicalClosingImageFilter<ImageType, ImageType, CrossType> CrossClosingFilterType;
226 if (structuralElementFlags & (Ball_Axial | Ball_Coronal | Ball_Sagital))
228 BallType ball = CreateStructuringElement<BallType>(structuralElementFlags, factor);
231 closingFilter->SetKernel(ball);
232 closingFilter->SetInput(sourceImage);
233 closingFilter->SetForegroundValue(1);
234 closingFilter->UpdateLargestPossibleRegion();
240 CrossType cross = CreateStructuringElement<CrossType>(structuralElementFlags, factor);
243 closingFilter->SetKernel(cross);
244 closingFilter->SetInput(sourceImage);
245 closingFilter->SetForegroundValue(1);
246 closingFilter->UpdateLargestPossibleRegion();
252 template <
typename TPixel,
unsigned int VDimension>
253 void mitk::MorphologicalOperations::itkErode(
254 itk::Image<TPixel, VDimension> *sourceImage,
259 typedef itk::Image<TPixel, VDimension>
ImageType;
260 typedef itk::BinaryBallStructuringElement<TPixel, VDimension> BallType;
261 typedef itk::BinaryCrossStructuringElement<TPixel, VDimension> CrossType;
262 typedef typename itk::BinaryErodeImageFilter<ImageType, ImageType, BallType> BallErodeFilterType;
263 typedef typename itk::BinaryErodeImageFilter<ImageType, ImageType, CrossType> CrossErodeFilterType;
265 if (structuralElementFlags & (Ball_Axial | Ball_Coronal | Ball_Sagital))
267 BallType ball = CreateStructuringElement<BallType>(structuralElementFlags, factor);
270 erodeFilter->SetKernel(ball);
271 erodeFilter->SetInput(sourceImage);
272 erodeFilter->SetErodeValue(1);
273 erodeFilter->UpdateLargestPossibleRegion();
279 CrossType cross = CreateStructuringElement<CrossType>(structuralElementFlags, factor);
282 erodeFilter->SetKernel(cross);
283 erodeFilter->SetInput(sourceImage);
284 erodeFilter->SetErodeValue(1);
285 erodeFilter->UpdateLargestPossibleRegion();
291 template <
typename TPixel,
unsigned int VDimension>
292 void mitk::MorphologicalOperations::itkDilate(
293 itk::Image<TPixel, VDimension> *sourceImage,
298 typedef itk::Image<TPixel, VDimension>
ImageType;
299 typedef itk::BinaryBallStructuringElement<TPixel, VDimension> BallType;
300 typedef itk::BinaryCrossStructuringElement<TPixel, VDimension> CrossType;
301 typedef typename itk::BinaryDilateImageFilter<ImageType, ImageType, BallType> BallDilateFilterType;
302 typedef typename itk::BinaryDilateImageFilter<ImageType, ImageType, CrossType> CrossDilateFilterType;
304 if (structuralElementFlags & (Ball_Axial | Ball_Coronal | Ball_Sagital))
306 BallType ball = CreateStructuringElement<BallType>(structuralElementFlags, factor);
309 dilateFilter->SetKernel(ball);
310 dilateFilter->SetInput(sourceImage);
311 dilateFilter->SetDilateValue(1);
312 dilateFilter->UpdateLargestPossibleRegion();
318 CrossType cross = CreateStructuringElement<CrossType>(structuralElementFlags, factor);
321 dilateFilter->SetKernel(cross);
322 dilateFilter->SetInput(sourceImage);
323 dilateFilter->SetDilateValue(1);
324 dilateFilter->UpdateLargestPossibleRegion();
330 template <
typename TPixel,
unsigned int VDimension>
331 void mitk::MorphologicalOperations::itkOpening(
332 itk::Image<TPixel, VDimension> *sourceImage,
337 typedef itk::Image<TPixel, VDimension>
ImageType;
338 typedef itk::BinaryBallStructuringElement<TPixel, VDimension> BallType;
339 typedef itk::BinaryCrossStructuringElement<TPixel, VDimension> CrossType;
340 typedef typename itk::BinaryMorphologicalOpeningImageFilter<ImageType, ImageType, BallType> BallOpeningFiltertype;
341 typedef typename itk::BinaryMorphologicalOpeningImageFilter<ImageType, ImageType, CrossType> CrossOpeningFiltertype;
343 if (structuralElementFlags & (Ball_Axial | Ball_Coronal | Ball_Sagital))
345 BallType ball = CreateStructuringElement<BallType>(structuralElementFlags, factor);
348 openingFilter->SetKernel(ball);
349 openingFilter->SetInput(sourceImage);
350 openingFilter->SetForegroundValue(1);
351 openingFilter->SetBackgroundValue(0);
352 openingFilter->UpdateLargestPossibleRegion();
358 CrossType cross = CreateStructuringElement<CrossType>(structuralElementFlags, factor);
361 openingFilter->SetKernel(cross);
362 openingFilter->SetInput(sourceImage);
363 openingFilter->SetForegroundValue(1);
364 openingFilter->SetBackgroundValue(0);
365 openingFilter->UpdateLargestPossibleRegion();
371 template <
typename TPixel,
unsigned int VDimension>
372 void mitk::MorphologicalOperations::itkFillHoles(itk::Image<TPixel, VDimension> *sourceImage,
375 typedef itk::Image<TPixel, VDimension>
ImageType;
376 typedef typename itk::BinaryFillholeImageFilter<ImageType> FillHoleFilterType;
379 fillHoleFilter->SetInput(sourceImage);
380 fillHoleFilter->SetForegroundValue(1);
381 fillHoleFilter->UpdateLargestPossibleRegion();
#define AccessByItk_3(mitkImage, itkImageTypeFunction, arg1, arg2, arg3)
itk::SmartPointer< Self > Pointer
const void * GetData() const
Gives const access to the data.
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
static void Closing(mitk::Image::Pointer &image, int factor, StructuralElementType structuralElement)
Perform morphological operation on 2D, 3D or 3D+t segmentation.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
static void Opening(mitk::Image::Pointer &image, int factor, StructuralElementType structuralElement)
Perform morphological operation on 2D, 3D or 3D+t segmentation.
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
ImageReadAccessor class to get locked read access for a particular image part.
static void Dilate(mitk::Image::Pointer &image, int factor, StructuralElementType structuralElement)
Perform morphological operation on 2D, 3D or 3D+t segmentation.
static void FillHoles(mitk::Image::Pointer &image)
Perform morphological operation on 2D, 3D or 3D+t segmentation.
static void Erode(mitk::Image::Pointer &image, int factor, StructuralElementType structuralElement)
Perform morphological operation on 2D, 3D or 3D+t segmentation.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.