diff --git a/Modules/AlgorithmsExt/include/mitkImageToUnstructuredGridFilter.h b/Modules/AlgorithmsExt/include/mitkImageToUnstructuredGridFilter.h index a383ab7a4b..11040c6183 100644 --- a/Modules/AlgorithmsExt/include/mitkImageToUnstructuredGridFilter.h +++ b/Modules/AlgorithmsExt/include/mitkImageToUnstructuredGridFilter.h @@ -1,103 +1,103 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ #define _MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ #include #include #include #include #include namespace mitk { /** * @brief Converts an Image into an UnstructuredGrid represented by Points. * The filter uses a Threshold to extract every pixel, with value higher than * the threshold, as point. * If no threshold is set, every pixel is extracted as a point. */ class MITKALGORITHMSEXT_EXPORT ImageToUnstructuredGridFilter : public UnstructuredGridSource { public: mitkClassMacro(ImageToUnstructuredGridFilter, UnstructuredGridSource) itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** This method is called by Update(). */ void GenerateData() override; /** Initializes the output information */ void GenerateOutputInformation() override; /** Returns a const reference to the input image */ const mitk::Image *GetInput(void) const; mitk::Image *GetInput(void); /** Set the source image. As input every mitk 3D image can be used. */ using itk::ProcessObject::SetInput; virtual void SetInput(const mitk::Image *image); /** * Set the threshold for extracting points. Every pixel, which value * is higher than this value, will be a point. */ void SetThreshold(double threshold); /** Returns the threshold */ double GetThreshold(); /** Returns the number of extracted points after edge detection */ itkGetMacro(NumberOfExtractedPoints, int) protected : /** Constructor */ ImageToUnstructuredGridFilter(); /** Destructor */ ~ImageToUnstructuredGridFilter() override; /** * Access method for extracting the points from the input image */ template void ExtractPoints(const itk::Image *image); + /** The number of points extracted by the filter */ + int m_NumberOfExtractedPoints; private: + /** * Geometry of the input image, needed to tranform the image points * into world points */ mitk::BaseGeometry *m_Geometry; - /** The number of points extracted by the filter */ - int m_NumberOfExtractedPoints; - /** Threshold for extracting the points */ double m_Threshold; /** The output of the filter, which contains the extracted points */ mitk::UnstructuredGrid::Pointer m_UnstructGrid; }; } // namespace mitk #endif //_MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ diff --git a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp index 235f5a9972..766e08fb81 100644 --- a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp +++ b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp @@ -1,166 +1,166 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkImageToPointCloudFilter.h" #include #include #include #include #include #include #include #include #include -mitk::ImageToPointCloudFilter::ImageToPointCloudFilter() : m_NumberOfExtractedPoints(0) +mitk::ImageToPointCloudFilter::ImageToPointCloudFilter() { m_Method = DetectionMethod(0); this->SetNumberOfRequiredInputs(1); this->SetNumberOfIndexedOutputs(1); } mitk::ImageToPointCloudFilter::~ImageToPointCloudFilter() { } void mitk::ImageToPointCloudFilter::GenerateData() { mitk::Image::ConstPointer image = ImageToUnstructuredGridFilter::GetInput(); m_Geometry = image->GetGeometry(); if (image.IsNull()) { MITK_ERROR << "mitk::ImageToContourFilter: No input available. " "Please set the input!" << std::endl; return; } mitk::Image::Pointer notConstImage = const_cast(image.GetPointer()); switch (m_Method) { case 0: AccessByItk_1(notConstImage.GetPointer(), StdDeviations, 2) break; case 1: AccessByItk_1(notConstImage.GetPointer(), StdDeviations, 3) break; case 2: AccessByItk_1(notConstImage.GetPointer(), StdDeviations, 4) break; default: AccessByItk_1(notConstImage.GetPointer(), StdDeviations, 2) break; } } template void mitk::ImageToPointCloudFilter::StdDeviations(itk::Image *image, int amount) { typedef itk::Image InputImageType; typedef itk::CastImageFilter ImagePTypeToFloatPTypeCasterType; typedef itk::LaplacianImageFilter LaplacianFilterType; typename LaplacianFilterType::Pointer lapFilter = LaplacianFilterType::New(); typename ImagePTypeToFloatPTypeCasterType::Pointer caster = ImagePTypeToFloatPTypeCasterType::New(); caster->SetInput(image); caster->Update(); FloatImageType::Pointer fImage = caster->GetOutput(); lapFilter->SetInput(fImage); lapFilter->UpdateLargestPossibleRegion(); mitk::Image::Pointer edgeImage = mitk::ImportItkImage(lapFilter->GetOutput()); mitk::ImageStatisticsCalculator::Pointer statCalc = mitk::ImageStatisticsCalculator::New(); statCalc->SetInputImage(edgeImage); mitk::ImageStatisticsCalculator::StatisticsContainer::Pointer stats = statCalc->GetStatistics(); double mean = stats->GetMean(); double stdDev = stats->GetStd(); double upperThreshold = mean + stdDev * amount; double lowerThreshold = mean - stdDev * amount; typename itk::ImageRegionIterator it(lapFilter->GetOutput(), lapFilter->GetOutput()->GetRequestedRegion()); vtkSmartPointer points = vtkSmartPointer::New(); double greatX = 0, greatY = 0, greatZ = 0; it.GoToBegin(); while (!it.IsAtEnd()) { if (it.Get() > lowerThreshold && it.Get() < upperThreshold) { it.Set(0); } else { it.Set(1); mitk::Point3D imagePoint; mitk::Point3D worldPoint; imagePoint[0] = it.GetIndex()[0]; imagePoint[1] = it.GetIndex()[1]; imagePoint[2] = it.GetIndex()[2]; m_Geometry->IndexToWorld(imagePoint, worldPoint); if (worldPoint[0] > greatX) greatX = worldPoint[0]; if (worldPoint[1] > greatY) greatY = worldPoint[1]; if (worldPoint[2] > greatZ) greatZ = worldPoint[2]; points->InsertNextPoint(worldPoint[0], worldPoint[1], worldPoint[2]); m_NumberOfExtractedPoints++; } ++it; } /*need to build the UnstructuredGrid with at least one vertex otherwise its not visible*/ vtkSmartPointer verts = vtkSmartPointer::New(); verts->GetPointIds()->SetNumberOfIds(m_NumberOfExtractedPoints); for (int i = 0; i < m_NumberOfExtractedPoints; i++) { verts->GetPointIds()->SetId(i, i); } vtkSmartPointer uGrid = vtkSmartPointer::New(); uGrid->Allocate(1); uGrid->InsertNextCell(verts->GetCellType(), verts->GetPointIds()); uGrid->SetPoints(points); mitk::UnstructuredGrid::Pointer outputGrid = mitk::UnstructuredGrid::New(); outputGrid->SetVtkUnstructuredGrid(uGrid); this->SetNthOutput(0, outputGrid); } void mitk::ImageToPointCloudFilter::GenerateOutputInformation() { Superclass::GenerateOutputInformation(); } diff --git a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h index 992b9c30f4..efb1061d3e 100644 --- a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h +++ b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h @@ -1,91 +1,88 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkImageToPointCloudFilter_h_Included #define mitkImageToPointCloudFilter_h_Included #include #include #include namespace mitk { /** * @brief The filter extracts the edge pixels of an image as points and stores * them in an UnstructuredGrid. Every pixel which grey value is between the * mean +- standard deviation * (2 or 3), will be extracted as point. The * DetectionMethod can be set to choose if the doubled or tripled standard * deviation is used. */ class MITKSURFACEINTERPOLATION_EXPORT ImageToPointCloudFilter : public ImageToUnstructuredGridFilter { public: /** * @brief The method which calculates and extracts the edge pixels/points. * For the edge detection the laplacian filter is used and for extraction * the standard deviation multiplied with 2, 3 or 4 (depending on selected * method) is used. */ enum DetectionMethod { LAPLACIAN_STD_DEV2 = 0, LAPLACIAN_STD_DEV3 = 1, LAPLACIAN_STD_DEV4 = 2 }; mitkClassMacro(ImageToPointCloudFilter, ImageToUnstructuredGridFilter) itkFactorylessNewMacro(Self) typedef itk::Image FloatImageType; /** Returns the selected DetectionMethod */ itkGetMacro(Method, DetectionMethod) /** Sets the DetectionMethod for edge detection and extraction */ itkSetMacro(Method, DetectionMethod) protected : /** This method is called by Update(). */ void GenerateData() override; /** Initializes the output information */ void GenerateOutputInformation() override; /** Constructor */ ImageToPointCloudFilter(); /** Destructor */ ~ImageToPointCloudFilter() override; private: /** Uses the laplace filter to create an image and extracts a pixel as point * if the grey value is between the mean +- standard deviation * (2 or 3) */ template void StdDeviations(itk::Image *image, int amount); /** The geometry of the input image for transforming the pixel coordinates to * world coordinates */ mitk::BaseGeometry *m_Geometry; - /** The number of extracted points */ - int m_NumberOfExtractedPoints; - /** The selected detection method */ DetectionMethod m_Method; }; } #endif