go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkImageRandomCoordinateSampler.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkImageRandomCoordinateSampler_h
19#define itkImageRandomCoordinateSampler_h
20
22#include "itkInterpolateImageFunction.h"
23#include "itkBSplineInterpolateImageFunction.h"
24#include "itkMersenneTwisterRandomVariateGenerator.h"
25
26namespace itk
27{
28
39template <class TInputImage>
40class ITK_TEMPLATE_EXPORT ImageRandomCoordinateSampler : public ImageRandomSamplerBase<TInputImage>
41{
42public:
44
48 using Pointer = SmartPointer<Self>;
49 using ConstPointer = SmartPointer<const Self>;
50
52 itkNewMacro(Self);
53
56
58 using typename Superclass::DataObjectPointer;
61 using typename Superclass::InputImageType;
62 using typename Superclass::InputImagePointer;
66 using typename Superclass::ImageSampleType;
69 using typename Superclass::MaskType;
70 using typename Superclass::InputImageSizeType;
71 using InputImageSpacingType = typename InputImageType::SpacingType;
76
78 itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension);
79
83 using InterpolatorType = InterpolateImageFunction<InputImageType, CoordRepType>;
84 using InterpolatorPointer = typename InterpolatorType::Pointer;
85 using DefaultInterpolatorType = BSplineInterpolateImageFunction<InputImageType, CoordRepType, double>;
86
88 using RandomGeneratorType = itk::Statistics::MersenneTwisterRandomVariateGenerator;
89 using RandomGeneratorPointer = typename RandomGeneratorType::Pointer;
90
92 itkSetObjectMacro(Interpolator, InterpolatorType);
94
97 itkSetMacro(SampleRegionSize, InputImageSpacingType);
98 itkGetConstReferenceMacro(SampleRegionSize, InputImageSpacingType);
99
102 itkGetConstMacro(UseRandomSampleRegion, bool);
103 itkSetMacro(UseRandomSampleRegion, bool);
104
105protected:
106 using InputImageContinuousIndexType = typename InterpolatorType::ContinuousIndexType;
107
110
112 ~ImageRandomCoordinateSampler() override = default;
113
115 void
116 PrintSelf(std::ostream & os, Indent indent) const override;
117
119 void
120 GenerateData() override;
121
123 virtual void
125 const InputImageContinuousIndexType & largestContIndex,
126 InputImageContinuousIndexType & randomContIndex);
127
128 InterpolatorPointer m_Interpolator = [] {
129 const auto interpolator = DefaultInterpolatorType::New();
130 interpolator->SetSplineOrder(3);
131 return interpolator;
132 }();
133
134 RandomGeneratorPointer m_RandomGenerator{ RandomGeneratorType::GetInstance() };
135 InputImageSpacingType m_SampleRegionSize{ itk::MakeFilled<InputImageSpacingType>(1.0) };
136
142 virtual void
144 const InputImageContinuousIndexType & largestImageContIndex,
145 InputImageContinuousIndexType & smallestContIndex,
146 InputImageContinuousIndexType & largestContIndex);
147
148private:
149 struct UserData
150 {
152
153 const std::vector<InputImageContinuousIndexType> & m_RandomCoordinates;
156 std::vector<ImageSampleType> & m_Samples;
157 };
158
159 std::vector<InputImageContinuousIndexType> m_RandomCoordinates{};
160
161 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
162 ThreaderCallback(void * arg);
163
164 bool m_UseRandomSampleRegion{ false };
165};
166
167} // end namespace itk
168
169#ifndef ITK_MANUAL_INSTANTIATION
170# include "itkImageRandomCoordinateSampler.hxx"
171#endif
172
173#endif // end #ifndef itkImageRandomCoordinateSampler_h
Samples an image by randomly composing a set of physical coordinates.
typename InterpolatorType::Pointer InterpolatorPointer
BSplineInterpolateImageFunction< InputImageType, CoordRepType, double > DefaultInterpolatorType
typename InterpolatorType::ContinuousIndexType InputImageContinuousIndexType
virtual void GenerateSampleRegion(const InputImageContinuousIndexType &smallestImageContIndex, const InputImageContinuousIndexType &largestImageContIndex, InputImageContinuousIndexType &smallestContIndex, InputImageContinuousIndexType &largestContIndex)
void PrintSelf(std::ostream &os, Indent indent) const override
~ImageRandomCoordinateSampler() override=default
itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType
typename InputImageType::SpacingType InputImageSpacingType
itkGetModifiableObjectMacro(Interpolator, InterpolatorType)
ITK_DISALLOW_COPY_AND_MOVE(ImageRandomCoordinateSampler)
virtual void GenerateRandomCoordinate(const InputImageContinuousIndexType &smallestContIndex, const InputImageContinuousIndexType &largestContIndex, InputImageContinuousIndexType &randomContIndex)
typename RandomGeneratorType::Pointer RandomGeneratorPointer
InterpolateImageFunction< InputImageType, CoordRepType > InterpolatorType
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreaderCallback(void *arg)
itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension)
This class is a base class for any image sampler that randomly picks samples.
typename InputImageType::ConstPointer InputImageConstPointer
typename InputImageType::RegionType InputImageRegionType
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
typename InputImageType::Pointer InputImagePointer
ImageMaskSpatialObject< Self::InputImageDimension > MaskType
typename InputImageType::PixelType InputImagePixelType
A class that defines an image sample, which is the coordinates of a point and its value.
typename InputImageType::PointType InputImagePointType
typename InputImageType::SizeType InputImageSizeType
typename InputImagePointType::ValueType InputImagePointValueType
typename ImageSampleType::RealType ImageSampleValueType
typename InputImageType::IndexType InputImageIndexType
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
const std::vector< InputImageContinuousIndexType > & m_RandomCoordinates


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo