- MeshBuilder& MeshBuilder::AddGaussianSmoothingPreprocessOperation(
- const SmoothingImageConfiguration& configuration)
- {
- mImagesOperations.emplace_back(
- std::make_shared<GaussianSmoothingImageOperation>(configuration));
- return *this;
- }
- vtkSmartPointer<vtkImageData> GaussianSmoothingImageOperation::Exec(
- const vtkSmartPointer<vtkImageData>& imageData)
- {
- ORTHO_LOG_INFO("GaussianSmoothingImageOperation - Start");
- // The padding is now adjusted automatically
- double spacingImage[3];
- imageData->GetSpacing(spacingImage);
- // Compute the image padding
- double paddingImage[3] = {
- mConfiguration.mGaussianSmoothingActualRadiusX / spacingImage[0],
- mConfiguration.mGaussianSmoothingActualRadiusY / spacingImage[1],
- mConfiguration.mGaussianSmoothingActualRadiusZ / spacingImage[2] };
- // pad the input volume because if the segmentation touches the edge of the dataset,
- // the generated mesh will contain holes
- vtkSmartPointer<vtkImageConstantPad> padImageFilter = vtkImageConstantPad::New();
- padImageFilter->SetInputData(imageData);
- padImageFilter->SetConstant(0);
- int extent[6];
- imageData->GetExtent(extent);
- double space[3];
- imageData->GetSpacing(space);
- std::cout << "image data" << space[0] << std::endl;
- // Add one voxel for the volume boundary in order to ensure an empty space
- // pad the x dimension
- extent[0] -= (paddingImage[0] + 1);
- std::cout << extent[0] << std::endl;
- extent[1] += (paddingImage[0] + 1);
- std::cout << extent[1] << std::endl;
- // pad the y dimension
- extent[2] -= (paddingImage[1] + 1);
- std::cout << extent[2] << std::endl;
- extent[3] += (paddingImage[1] + 1);
- std::cout << extent[3] << std::endl;
- // pad the z dimension
- extent[4] -= (paddingImage[2] + 1);
- std::cout << extent[4] << std::endl;
- extent[5] += (paddingImage[2] + 1);
- std::cout << extent[5] << std::endl;
- padImageFilter->SetOutputWholeExtent(extent);
- padImageFilter->Update();
- std::cout << "pad image" << padImageFilter->GetOutput()->GetSpacing() << std::endl;
- // Convert to a floating point volume.
- // Note from proulxc: This is unfortunate, memory wise, but the VTK gaussian filter
- // on integer types performs weirdly. It appears to apply the mask in three successive
- // passes, rounding each time and causing non-symmetries and numerical errors in the
- // process.
- const double MAX_VALUE = 1.0;
- vtkSmartPointer<vtkImageCast> castImage =
- vtkSmartPointer<vtkImageCast>::New();
- castImage->SetInputConnection(padImageFilter->GetOutputPort());
- castImage->SetOutputScalarTypeToFloat();
- castImage->Update();
- double space2[3];
- castImage->GetOutput()->GetSpacing(space2);
- std::cout << "cast image" << space2[0] << std::endl;
- vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothingFilter =
- vtkSmartPointer<vtkImageGaussianSmooth>::New();
- gaussianSmoothingFilter->SetInputConnection(castImage->GetOutputPort());
- gaussianSmoothingFilter->SetDimensionality(3);
- double sigmaX = mConfiguration.mGaussianSmoothingFilterStdX;
- double sigmaY = mConfiguration.mGaussianSmoothingFilterStdY;
- double sigmaZ = mConfiguration.mGaussianSmoothingFilterStdZ;
- // Note that radius factor is multiplied by standard deviation to obtain
- // the actual radius. Eg: sigma = 2 and radius factor = 2 -> actual radius = 4
- // i.e. 9x9x9 kernel. We compute the radius factor so that the actual radius
- // will always be the one set in the Algo Parameters config file, regardless of sigma.
- double radiusFactorX = 1.0;
- double radiusFactorY = 1.0;
- double radiusFactorZ = 1.0;
- double actualRadiusX = mConfiguration.mGaussianSmoothingActualRadiusX;
- double actualRadiusY = mConfiguration.mGaussianSmoothingActualRadiusY;
- double actualRadiusZ = mConfiguration.mGaussianSmoothingActualRadiusZ;
- if (sigmaX >= std::numeric_limits<double>::epsilon())
- {
- radiusFactorX = actualRadiusX / sigmaX;
- }
- if (sigmaY >= std::numeric_limits<double>::epsilon())
- {
- radiusFactorY = actualRadiusY / sigmaY;
- }
- if (sigmaZ >= std::numeric_limits<double>::epsilon())
- {
- radiusFactorZ = actualRadiusZ / sigmaZ;
- }
- gaussianSmoothingFilter->SetRadiusFactors(radiusFactorX, radiusFactorY, radiusFactorZ);
- gaussianSmoothingFilter->SetStandardDeviations(sigmaX, sigmaY, sigmaZ);
- gaussianSmoothingFilter->Update();
- ORTHO_LOG_INFO("GaussianSmoothingImageOperation - End");
- const auto mhdWriter = vtkSmartPointer<vtkMetaImageWriter>::New();
- auto im = gaussianSmoothingFilter->GetOutput();
- double spac[3];
- im->GetSpacing(spac);
- std::cout << "smoothed image" << spac[0] << std::endl;
- mhdWriter->SetInputData(im);
- mhdWriter->SetCompression(false);
- mhdWriter->SetFileName("C:/temp/vtk9_smoothingwithdirMat.mhd");
- mhdWriter->Write();
- return im;
- }
[text] Smoothing operatiobn
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- Smoothing operatiobn
- Paste Code
- 17 Feb-2023
- 4.88 Kb
You can Share it:
Latest Code Pastes