ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkTileMontage.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
19#ifndef itkTileMontage_h
20#define itkTileMontage_h
21
22#include "itkImageFileReader.h"
25
26#include <atomic>
27#include <deque>
28#include <mutex>
29#include <vector>
30
31namespace itk
32{
49template <typename TImageType,
50 typename TCoordinate =
51 typename std::conditional<std::is_same<typename TImageType::PixelType, double>::value, double, float>::type>
52class ITK_TEMPLATE_EXPORT TileMontage : public ProcessObject
53{
54public:
55 ITK_DISALLOW_COPY_AND_MOVE(TileMontage);
56
62 using ImageType = TImageType;
63
65 itkNewMacro(Self);
66
68 itkOverrideGetNameOfClassMacro(TileMontage);
69
71 static constexpr unsigned int ImageDimension = ImageType::ImageDimension;
72
77
79 using PixelType = typename ImageType::PixelType;
80 using RegionType = typename ImageType::RegionType;
81 using PointType = typename ImageType::PointType;
82 using SpacingType = typename ImageType::SpacingType;
83 using OffsetType = typename ImageType::OffsetType;
84 using ImageIndexType = typename ImageType::IndexType;
85
88
90
92
94
97 using TransformPointer = typename TransformType::Pointer;
98 using TransformConstPointer = typename TransformType::ConstPointer;
99
103
106
110 itkSetMacro(OriginAdjustment, PointType);
111 itkGetConstMacro(OriginAdjustment, PointType);
112
115 itkSetMacro(ForcedSpacing, SpacingType);
116 itkGetConstMacro(ForcedSpacing, SpacingType);
117
126 itkSetMacro(AbsoluteThreshold, float);
127 itkGetConstMacro(AbsoluteThreshold, float);
128
137 itkSetMacro(RelativeThreshold, float);
138 itkGetConstMacro(RelativeThreshold, float);
139
147 itkSetMacro(PositionTolerance, SizeValueType);
148 itkGetConstMacro(PositionTolerance, SizeValueType);
149
155 itkSetMacro(CropToOverlap, bool);
156 itkGetConstMacro(CropToOverlap, bool);
157
161 virtual void
163 {
164 if (this->m_ObligatoryPadding != pad)
165 {
166 this->m_ObligatoryPadding = pad;
167 this->Modified();
168 }
169 }
170 itkGetConstMacro(ObligatoryPadding, SizeType);
171
174 itkSetEnumMacro(PaddingMethod, typename PCMType::PaddingMethodEnum);
175 itkGetConstMacro(PaddingMethod, typename PCMType::PaddingMethodEnum);
176
179 itkSetEnumMacro(PeakInterpolationMethod, typename PCMOptimizerType::PeakInterpolationMethodEnum);
180 itkGetConstMacro(PeakInterpolationMethod, typename PCMOptimizerType::PeakInterpolationMethodEnum);
181
183 itkGetConstMacro(MontageSize, SizeType);
184 void
186
189 void
191 {
192 this->SetNthInput(linearIndex, image);
193 m_FFTCache[linearIndex] = nullptr;
194 m_Tiles[linearIndex] = nullptr;
195 }
196 void
197 SetInputTile(SizeValueType linearIndex, const std::string & imageFilename)
198 {
199 m_Filenames[linearIndex] = imageFilename;
200 this->SetInputTile(linearIndex, m_Dummy);
201 }
202 void
204 {
205 this->SetInputTile(this->nDIndexToLinearIndex(position), image);
206 }
207 void
208 SetInputTile(TileIndexType position, const std::string & imageFilename)
209 {
210 this->SetInputTile(this->nDIndexToLinearIndex(position), imageFilename);
211 }
212
214 const TransformType *
216 {
217 return static_cast<TransformOutputType *>(this->GetOutput(this->nDIndexToLinearIndex(position)))->Get();
218 }
219
221 using TileReliabilities = std::vector<float>;
222
226 itkGetConstReferenceMacro(TileReliabilities, TileReliabilities);
227 float
229 {
230 return m_TileReliabilities[linearIndex];
231 }
232 float
234 {
236 return GetTileReliability(linearIndex);
237 }
238
239protected:
241 ~TileMontage() override = default;
242 void
243 PrintSelf(std::ostream & os, Indent indent) const override;
244
246 void
247 GenerateData() override;
248
250 void
252
254
261
264
265 using TranslationOffset = typename TransformType::OutputVectorType;
266 using ImagePointer = typename ImageType::Pointer;
267 using ImageConstPointer = typename ImageType::ConstPointer;
268
269 template <typename TImageToRead>
270 typename TImageToRead::Pointer
271 GetImageHelper(TileIndexType nDIndex, bool metadataOnly, RegionType region);
272
274 typename ImageType::Pointer
275 GetImage(TileIndexType nDIndex, bool metadataOnly);
276
283
285 void
287
289 void
291
293 void
295
298 void
300 TransformConstPointer transform,
301 const ImageType * input,
302 const ImageType * input0);
303
306 using FFTPointer = typename FFTType::Pointer;
307 using FFTConstPointer = typename FFTType::ConstPointer;
308
309 using OffsetVector = std::vector<TranslationOffset>;
311
312 void
314
315 std::deque<std::mutex> m_TileReadLocks; // to avoid reading the same tile by more than one thread in parallel
316 // deque is not reallocated when resized, so no mutex moving causing a crash
317
318private:
322
323 std::atomic<SizeValueType> m_FinishedPairs = { 0 };
324
330 bool m_CropToOverlap = true;
332
333 std::mutex m_MemberProtector; // to prevent concurrent access to non-thread-safe internal member variables
334
335 typename PCMType::PaddingMethodEnum m_PaddingMethod = PCMType::PaddingMethodEnum::MirrorWithExponentialDecay;
336
337 std::vector<std::string> m_Filenames;
338 std::vector<FFTConstPointer> m_FFTCache;
339 std::vector<ImagePointer> m_Tiles; // metadata/image storage (if filenames are given instead of actual images)
340 std::vector<OffsetVector> m_TransformCandidates; // to adjacent tiles
341 std::vector<ConfidencesType> m_CandidateConfidences;
342 std::vector<TranslationOffset> m_CurrentAdjustments;
343 std::vector<float> m_TileReliabilities;
344
346 PCMOptimizerType::PeakInterpolationMethodEnum::Parabolic;
347
348 const typename ImageType::Pointer m_Dummy = ImageType::New();
349
350 // members needed for ResampleIntoSingleImage
351 ContinuousIndexType m_MinInner; // minimum index for cropped montage
352 ContinuousIndexType m_MaxInner; // maximum index for cropped montage
353 ContinuousIndexType m_MinOuter; // minimum index for total montage
354 ContinuousIndexType m_MaxOuter; // maximum index for total montage
355
356 template <typename TImageTypeInner, typename TPixelAccumulateType, typename TInterpolatorInner>
358}; // class TileMontage
359
360} // namespace itk
361
362#ifndef ITK_MANUAL_INSTANTIATION
363# include "itkTileMontage.hxx"
364#endif
365
366#endif // itkTileMontage_h
Different methods of padding the images to satisfy FFT size requirements.
A templated class holding a point in n-Dimensional image space.
Decorates any subclass of itkObject with a DataObject API.
SmartPointer< Self > Pointer
Data source that reads image data from a single file.
Control indentation during Print() invocation.
Definition itkIndent.h:53
virtual void Modified() const
Base class for phase-correlation-based image registration.
TranslationTransform< typename MovingImageType::PointType::ValueType, ImageDimension > TransformType
PhaseCorrelationImageRegistrationMethodEnums::PaddingMethod PaddingMethodEnum
Computes the spectrum ratio in phase correlation method.
Defines common interface for optimizers, that estimates the shift from correlation surface.
PhaseCorrelationOptimizerEnums::PeakInterpolationMethod PeakInterpolationMethodEnum
DataObject * GetOutput(const DataObjectIdentifierType &key)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
Implements transparent reference counting.
void SetInputTile(SizeValueType linearIndex, ImageType *image)
void SetInputTile(TileIndexType position, const std::string &imageFilename)
void GenerateData() override
void ReleaseMemory(TileIndexType finishedTile)
void RegisterPair(TileIndexType fixed, TileIndexType moving)
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType) override
const TransformType * GetOutputTransform(TileIndexType position)
void SetInputTile(TileIndexType position, ImageType *image)
void SetMontageSize(SizeType montageSize)
TileIndexType LinearIndexTonDIndex(DataObjectPointerArraySizeType linearIndex) const
void UpdateMosaicBounds(TileIndexType index, TransformConstPointer transform, const ImageType *input, const ImageType *input0)
float GetTileReliability(TileIndexType nDIndex) const
float GetTileReliability(DataObjectPointerArraySizeType linearIndex) const
~TileMontage() override=default
DataObjectPointerArraySizeType ReferenceLinearIndex(DataObjectPointerArraySizeType candidateIndex) const
void SetInputTile(SizeValueType linearIndex, const std::string &imageFilename)
TImageToRead::Pointer GetImageHelper(TileIndexType nDIndex, bool metadataOnly, RegionType region)
void PrintSelf(std::ostream &os, Indent indent) const override
ImageType::Pointer GetImage(TileIndexType nDIndex, bool metadataOnly)
void WriteOutTransform(TileIndexType index, TranslationOffset offset)
void GenerateOutputInformation() override
virtual void SetObligatoryPadding(const SizeType pad)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:82
#define itkSetMacro(name, type)
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition itkSize.h:70