16 #include "itkResampleImageFilter.h" 17 #include "itkGaussianInterpolateImageFunction.h" 25 mitk::pa::VolumeManipulator::VolumeManipulator() {}
27 mitk::pa::VolumeManipulator::~VolumeManipulator() {}
31 for (
unsigned int z = 0; z < image->GetZDim(); z++)
32 for (
unsigned int y = 0; y < image->GetYDim(); y++)
33 for (
unsigned int x = 0; x < image->GetXDim(); x++)
34 if (image->GetData(x, y, z) > threshold)
35 image->SetData(1, x, y, z);
37 image->SetData(0, x, y, z);
42 for (
unsigned int z = 0; z < image->GetZDim(); z++)
43 for (
unsigned int y = 0; y < image->GetYDim(); y++)
44 for (
unsigned int x = 0; x < image->GetXDim(); x++)
45 image->SetData(image->GetData(x, y, z)*factor, x, y, z);
50 for (
unsigned int z = 0; z < image->GetZDim(); z++)
51 for (
unsigned int y = 0; y < image->GetYDim(); y++)
52 for (
unsigned int x = 0; x < image->GetXDim(); x++)
54 if (image->GetData(x, y, z) < 0)
56 MITK_ERROR <<
"Signal was smaller than 0. There is an error in the input image file.";
59 image->SetData(log10(image->GetData(x, y, z)), x, y, z);
66 double sigma = image->GetSpacing() / (ratio * 2);
67 image->SetAbsorptionVolume(
RescaleImage(image->GetAbsorptionVolume(), ratio, sigma));
68 image->SetScatteringVolume(
RescaleImage(image->GetScatteringVolume(), ratio, sigma));
69 image->SetAnisotropyVolume(
RescaleImage(image->GetAnisotropyVolume(), ratio, sigma));
70 image->SetSegmentationVolume(
RescaleImage(image->GetSegmentationVolume(), ratio, 0));
78 typedef itk::ResampleImageFilter<ImageType, ImageType> FilterType;
79 typedef itk::GaussianInterpolateImageFunction<ImageType, double> InterpolatorType;
81 auto input = image->AsMitkImage();
82 ImageType::Pointer itkInput = ImageType::New();
85 ImageType::SizeType outputSize;
86 outputSize[0] = input->GetDimensions()[0] * ratio;
87 outputSize[1] = input->GetDimensions()[1] * ratio;
88 outputSize[2] = input->GetDimensions()[2] * ratio;
90 FilterType::Pointer resampleImageFilter = FilterType::New();
91 resampleImageFilter->SetInput(itkInput);
92 resampleImageFilter->SetSize(outputSize);
95 auto interpolator = InterpolatorType::New();
96 interpolator->SetSigma(sigma);
97 resampleImageFilter->SetInterpolator(interpolator);
99 resampleImageFilter->SetOutputSpacing(input->GetGeometry()->GetSpacing()[0] / ratio);
102 resampleImageFilter->UpdateLargestPossibleRegion();
105 ImageType::Pointer output = resampleImageFilter->GetOutput();
130 double* volume = paVolume->GetData();
131 long width = paVolume->GetYDim();
132 long height = paVolume->GetXDim();
133 long depth = paVolume->GetZDim();
134 const long plane = width*height;
135 const long numel = plane*depth;
137 double nu, boundaryscale, postscale;
145 lambda = (sigma*sigma) / (8.0);
146 dnu = (1.0 + 2.0*lambda - sqrt(1.0 + 4.0*lambda)) / (2.0*lambda);
148 boundaryscale = 1.0 / (1.0 - dnu);
149 postscale = pow(dnu / lambda, 12);
152 for (z = 0; z < depth; z++)
154 for (y = 0; y < height; y++)
156 for (step = 0; step < 4; step++)
158 ptr = volume + width*(y + height*z);
159 ptr[0] *= boundaryscale;
162 for (x = 1; x < width; x++)
164 ptr[x] += nu*ptr[x - 1];
167 ptr[x = width - 1] *= boundaryscale;
171 ptr[x - 1] += nu*ptr[x];
177 for (z = 0; z < depth; z++)
179 for (x = 0; x < width; x++)
181 for (step = 0; step < 4; step++)
183 ptr = volume + x + plane*z;
184 ptr[0] *= boundaryscale;
187 for (i = width; i < plane; i += width)
189 ptr[i] += nu*ptr[i - width];
192 ptr[i = plane - width] *= boundaryscale;
195 for (; i > 0; i -= width)
197 ptr[i - width] += nu*ptr[i];
204 for (y = 0; y < height; y++)
206 for (x = 0; x < width; x++)
208 for (step = 0; step < 4; step++)
210 ptr = volume + x + width*y;
211 ptr[0] *= boundaryscale;
213 for (i = plane; i < numel; i += plane)
215 ptr[i] += nu*ptr[i - plane];
218 ptr[i = numel - plane] *= boundaryscale;
220 for (; i > 0; i -= plane)
222 ptr[i - plane] += nu*ptr[i];
228 for (i = 0; i < numel; i++)
230 volume[i] *= postscale;
static void ThresholdImage(Volume::Pointer image, double threshold)
ThresholdImage applies a binary threshold filter to this image.
itk::Image< unsigned char, 3 > ImageType
static void Log10Image(Volume::Pointer image)
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.
static void RescaleImage(InSilicoTissueVolume::Pointer image, double ratio)
mitk::Image::Pointer image
static void MultiplyImage(Volume::Pointer image, double factor)
Multiplies the image with a given factor.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
MITKCORE_EXPORT const ScalarType eps
static void GaussianBlur3D(Volume::Pointer paVolume, double sigma)
applies a Gaussian blur to an image
static Volume::Pointer New(double *data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing)
returns smartpointer reference to a new instance of this objects. The given data array will be freed ...
this exception is thrown if an invalid value is supposed to be processed