MCPcopy Create free account
hub / github.com/MITK/MITK / CutImage

Method CutImage

Modules/BoundingShape/src/DataManagement/mitkBoundingShapeCropper.cpp:51–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50 template <typename TPixel, unsigned int VImageDimension>
51 void BoundingShapeCropper::CutImage(itk::Image<TPixel, VImageDimension> *inputItkImage, int timeStep)
52 {
53 MITK_INFO << "Scalar Pixeltype" << std::endl;
54
55 typedef TPixel TOutputPixel;
56 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
57 typedef itk::Image<TOutputPixel, VImageDimension> ItkOutputImageType;
58 typedef typename itk::ImageBase<VImageDimension>::RegionType ItkRegionType;
59 typedef itk::ImageRegionIteratorWithIndex<ItkInputImageType> ItkInputImageIteratorType;
60 typedef itk::ImageRegionIteratorWithIndex<ItkOutputImageType> ItkOutputImageIteratorType;
61
62 TOutputPixel outsideValue = this->GetOutsideValue();
63 // currently 0 if not set in advance
64 // TODO: change default value to itk::NumericTraits<TOutputPixel>::min();
65
66 if (this->m_Geometry.IsNull())
67 return;
68
69 if (inputItkImage == nullptr)
70 {
71 mitk::StatusBar::GetInstance()->DisplayErrorText(
72 "An internal error occurred. Can't convert Image. Please report to bugs@mitk.org");
73 std::cout << " image is nullptr...returning" << std::endl;
74 return;
75 }
76
77 // first convert the index
78 typename ItkRegionType::IndexType::IndexValueType tmpIndex[3];
79 for (unsigned int i = 0; i < 3; ++i)
80 tmpIndex[i] = this->m_InputRequestedRegion.GetIndex()[i];
81 typename ItkRegionType::IndexType index;
82 index.SetIndex(tmpIndex);
83
84 // then convert the size
85 typename ItkRegionType::SizeType::SizeValueType tmpSize[3];
86 for (unsigned int i = 0; i < 3; ++i)
87 tmpSize[i] = this->m_InputRequestedRegion.GetSize()[i];
88 typename ItkRegionType::SizeType size;
89 size.SetSize(tmpSize);
90
91 // create the ITK-image-region out of index and size
92 ItkRegionType inputRegionOfInterest(index, size);
93
94 // Get access to the MITK output image via an ITK image
95 typename mitk::ImageToItk<ItkOutputImageType>::Pointer outputimagetoitk =
96 mitk::ImageToItk<ItkOutputImageType>::New();
97 outputimagetoitk->SetInput(this->m_OutputTimeSelector->GetOutput());
98 outputimagetoitk->Update();
99 typename ItkOutputImageType::Pointer outputItkImage = outputimagetoitk->GetOutput();
100
101 // create the iterators
102 ItkInputImageIteratorType inputIt(inputItkImage, inputRegionOfInterest);
103 ItkOutputImageIteratorType outputIt(outputItkImage, outputItkImage->GetLargestPossibleRegion());
104
105 // Cut the boundingbox out of the image by iterating through all images
106 // TODO: use more efficient method by using the contour instead off all single pixels
107 mitk::Point3D p;
108 mitk::BaseGeometry *inputGeometry = this->GetInput()->GetGeometry(timeStep);

Callers

nothing calls this directly

Calls 15

SetIndexMethod · 0.80
GetGeometryMethod · 0.80
GetMatrixMethod · 0.80
GetCenterMethod · 0.80
SetMatrixMethod · 0.80
TransformPointMethod · 0.80
ValueMethod · 0.80
NewFunction · 0.50
IsNullMethod · 0.45
DisplayErrorTextMethod · 0.45
GetIndexMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected