forked from InsightSoftwareConsortium/ITKIsotropicWavelets
/
itkWaveletFrequencyForward.hxx
550 lines (504 loc) · 23.1 KB
/
itkWaveletFrequencyForward.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkWaveletFrequencyForward_hxx
#define itkWaveletFrequencyForward_hxx
#include <itkWaveletFrequencyForward.h>
#include <itkCastImageFilter.h>
#include <itkImage.h>
#include <algorithm>
#include <itkMultiplyImageFilter.h>
#include <itkShrinkDecimateImageFilter.h>
#include <itkChangeInformationImageFilter.h>
#include <itkWaveletUtilities.h>
namespace itk
{
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
WaveletFrequencyForward()
{
this->SetNumberOfRequiredInputs(1);
m_WaveletFilterBank = WaveletFilterBankType::New();
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
std::pair<unsigned int, unsigned int>
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
OutputIndexToLevelBand(unsigned int linear_index)
{
return itk::utils::IndexToLevelBandSteerablePyramid(linear_index, this->m_Levels, this->m_HighPassSubBands);
};
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
typename WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::OutputsType
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::GetOutputs()
{
OutputsType outputPtrs;
for (unsigned int nout = 0; nout < this->m_TotalOutputs; ++nout)
{
outputPtrs.push_back(this->GetOutput(nout));
}
return outputPtrs;
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
typename WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::OutputsType
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::GetOutputsHighPass()
{
OutputsType outputPtrs;
for (unsigned int nout = 1; nout < this->m_TotalOutputs; ++nout)
{
outputPtrs.push_back(this->GetOutput(nout));
}
return outputPtrs;
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
typename WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
OutputImagePointer
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::GetOutputLowPass()
{
return this->GetOutput(this->m_TotalOutputs - 1);
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
typename WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::OutputsType
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
GetOutputsHighPassByLevel(unsigned int level)
{
OutputsType outputPtrs;
unsigned int nOutput_start = level * this->m_HighPassSubBands;
unsigned int nOutput_end = (level + 1) * this->m_HighPassSubBands;
if (nOutput_end > this->m_TotalOutputs)
{
nOutput_end = this->m_TotalOutputs;
}
for (unsigned int nOutput = nOutput_start; nOutput < nOutput_end; ++nOutput)
{
outputPtrs.push_back(this->GetOutput(nOutput));
}
return outputPtrs;
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
unsigned int
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
ComputeMaxNumberOfLevels(const typename InputImageType::SizeType & inputSize, const unsigned int scaleFactor)
{
return itk::utils::ComputeMaxNumberOfLevels(inputSize, scaleFactor);
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::SetLevels(
unsigned int inputLevels)
{
unsigned int current_outputs = 1 + this->m_Levels * this->m_HighPassSubBands;
if (this->m_TotalOutputs == current_outputs && this->m_Levels == inputLevels)
{
return;
}
this->m_Levels = inputLevels;
this->m_TotalOutputs = 1 + inputLevels * this->m_HighPassSubBands;
this->SetNumberOfRequiredOutputs(this->m_TotalOutputs);
this->Modified();
for (unsigned int n_output = 0; n_output < this->m_TotalOutputs; ++n_output)
{
this->SetNthOutput(n_output, this->MakeOutput(n_output));
}
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::SetHighPassSubBands(
unsigned int k)
{
if (this->m_HighPassSubBands == k)
{
return;
}
this->m_HighPassSubBands = k;
// Trigger setting new number of outputs avoiding code duplication
this->SetLevels(this->m_Levels);
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::PrintSelf(
std::ostream & os,
Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << " Levels: " << this->m_Levels << " HighPassSubBands: " << this->m_HighPassSubBands
<< " TotalOutputs: " << this->m_TotalOutputs << std::endl;
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
GenerateOutputInformation()
{
// call the superclass's implementation of this method
Superclass::GenerateOutputInformation();
// get pointers to the input and output
InputImageConstPointer inputPtr = this->GetInput();
if (!inputPtr)
{
itkExceptionMacro(<< "Input has not been set");
}
typename InputImageType::SizeType inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
typename InputImageType::IndexType inputStartIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
/** inputOrigin and inputSpacing is lost and should be restored
* at the end of the inverse wavelet transform. */
typename OutputImageType::PointType inputModifiedOrigin(0);
typename OutputImageType::SpacingType inputModifiedSpacing(1);
// typename OutputImageType::DirectionType outputDirection = inputDirection;
OutputImagePointer outputPtr;
typename OutputImageType::SizeType inputSizePerLevel = inputSize;
typename OutputImageType::IndexType inputStartIndexPerLevel = inputStartIndex;
typename OutputImageType::PointType inputOriginPerLevel = inputModifiedOrigin;
typename OutputImageType::SpacingType inputSpacingPerLevel = inputModifiedSpacing;
// typename OutputImageType::DirectionType inputDirectionPerLevel = inputDirection;
// we need to compute the output spacing, the output image size,
// and the output image start index
for (unsigned int level = 0; level < this->m_Levels; ++level)
{
// Bands per level . No downsampling in the first level iteration.
for (unsigned int band = 0; band < this->m_HighPassSubBands; ++band)
{
unsigned int current_output = level * m_HighPassSubBands + band;
outputPtr = this->GetOutput(current_output);
if (!outputPtr)
{
continue;
}
typename OutputImageType::RegionType largestPossibleRegion;
largestPossibleRegion.SetSize(inputSizePerLevel);
largestPossibleRegion.SetIndex(inputStartIndexPerLevel);
outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
outputPtr->SetOrigin(inputOriginPerLevel);
outputPtr->SetSpacing(inputSpacingPerLevel);
// outputPtr->SetDirection(outputDirection);
}
// Calculate for next levels new Size and Index, per dim.
for (unsigned int idim = 0; idim < OutputImageType::ImageDimension; idim++)
{
// Size divided by scale
inputSizePerLevel[idim] =
static_cast<SizeValueType>(std::floor(static_cast<double>(inputSizePerLevel[idim]) / this->m_ScaleFactor));
if (inputSizePerLevel[idim] < 1)
{
inputSizePerLevel[idim] = 1;
}
// Index dividided by scale
inputStartIndexPerLevel[idim] = static_cast<IndexValueType>(
std::ceil(static_cast<double>(inputStartIndexPerLevel[idim]) / this->m_ScaleFactor));
// Spacing
inputSpacingPerLevel[idim] = inputSpacingPerLevel[idim] * this->m_ScaleFactor;
// Origin, the same.
// inputOriginPerLevel[idim] = inputOriginPerLevel[idim];
// inputOriginPerLevel[idim] = inputOriginPerLevel[idim] / this->m_ScaleFactor;
}
// Set the low pass at the end.
if (level == this->m_Levels - 1)
{
outputPtr = this->GetOutput(this->m_TotalOutputs - 1);
if (!outputPtr)
{
continue;
}
typename OutputImageType::RegionType largestPossibleRegion;
largestPossibleRegion.SetSize(inputSizePerLevel);
largestPossibleRegion.SetIndex(inputStartIndexPerLevel);
outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
outputPtr->SetOrigin(inputOriginPerLevel);
outputPtr->SetSpacing(inputSpacingPerLevel);
// outputPtr->SetDirection(inputDirectionPerLevel);
}
}
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
GenerateOutputRequestedRegion(DataObject * refOutput)
{
// call the superclass's implementation of this method
Superclass::GenerateOutputRequestedRegion(refOutput);
// find the index for this output
auto refIndex = static_cast<unsigned int>(refOutput->GetSourceOutputIndex());
std::pair<unsigned int, unsigned int> pairRef = this->OutputIndexToLevelBand(refIndex);
unsigned int refLevel = pairRef.first;
// unsigned int refBand = pairRef.second;
// compute baseIndex and baseSize
using SizeType = typename OutputImageType::SizeType;
using IndexType = typename OutputImageType::IndexType;
using RegionType = typename OutputImageType::RegionType;
auto * ptr = itkDynamicCastInDebugMode<TOutputImage *>(refOutput);
if (!ptr)
{
itkExceptionMacro(<< "Could not cast refOutput to TOutputImage*.");
}
if (ptr->GetRequestedRegion() == ptr->GetLargestPossibleRegion())
{
// set the requested regions for the other outputs to their largest
for (unsigned int nout = 0; nout < this->m_TotalOutputs; ++nout)
{
if (nout == refIndex)
{
continue;
}
if (!this->GetOutput(nout))
{
continue;
}
this->GetOutput(nout)->SetRequestedRegionToLargestPossibleRegion();
}
}
else
{
// compute requested regions for the other outputs based on
// the requested region of the reference output
IndexType outputIndex;
SizeType outputSize;
RegionType outputRegion;
RegionType baseRegion = ptr->GetRequestedRegion();
IndexType baseIndex = baseRegion.GetIndex();
SizeType baseSize = baseRegion.GetSize();
for (unsigned int level = 0; level < this->m_Levels + 1; ++level)
{
int distanceToReferenceLevel = static_cast<int>(refLevel) - static_cast<int>(level);
for (unsigned int idim = 0; idim < TOutputImage::ImageDimension; idim++)
{
outputIndex[idim] =
baseIndex[idim] *
static_cast<IndexValueType>(std::pow(static_cast<double>(this->m_ScaleFactor), distanceToReferenceLevel));
outputSize[idim] =
baseSize[idim] *
static_cast<SizeValueType>(std::pow(static_cast<double>(this->m_ScaleFactor), distanceToReferenceLevel));
if (outputSize[idim] < 1)
{
itkExceptionMacro(
<< "Failure at level: " << level
<< " in forward wavelet, going to negative image size. Too many levels for input image size.");
}
}
outputRegion.SetIndex(outputIndex);
outputRegion.SetSize(outputSize);
// Set low pass output
if (level == this->m_Levels)
{
unsigned int n_output = this->m_TotalOutputs - 1;
if (n_output == refIndex)
{
continue;
}
if (!this->GetOutput(n_output))
{
continue;
}
outputRegion.Crop(this->GetOutput(n_output)->GetLargestPossibleRegion());
this->GetOutput(n_output)->SetRequestedRegion(outputRegion);
}
else // Bands per level
{
for (unsigned int band = 0; band < this->m_HighPassSubBands; ++band)
{
unsigned int n_output = level * this->m_HighPassSubBands + band;
if (n_output == refIndex)
{
continue;
}
if (!this->GetOutput(n_output))
{
continue;
}
outputRegion.Crop(this->GetOutput(n_output)->GetLargestPossibleRegion());
// set the requested region
this->GetOutput(n_output)->SetRequestedRegion(outputRegion);
}
}
}
}
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::
GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput());
if (!inputPtr)
{
itkExceptionMacro(<< "Input has not been set.");
}
// compute baseIndex and baseSize
using SizeType = typename OutputImageType::SizeType;
using IndexType = typename OutputImageType::IndexType;
using RegionType = typename OutputImageType::RegionType;
// The first level has the same size than input.
// At least one band is ensured to exist, so use it.
unsigned int refOutput = 0;
SizeType baseSize = this->GetOutput(refOutput)->GetRequestedRegion().GetSize();
IndexType baseIndex = this->GetOutput(refOutput)->GetRequestedRegion().GetIndex();
RegionType baseRegion;
baseRegion.SetIndex(baseIndex);
baseRegion.SetSize(baseSize);
// make sure the requested region is within the largest possible
baseRegion.Crop(inputPtr->GetLargestPossibleRegion());
// set the input requested region
inputPtr->SetRequestedRegion(baseRegion);
}
template <typename TInputImage, typename TOutputImage, typename TWaveletFilterBank, typename TFrequencyShrinkFilterType>
void
WaveletFrequencyForward<TInputImage, TOutputImage, TWaveletFilterBank, TFrequencyShrinkFilterType>::GenerateData()
{
InputImageConstPointer input = this->GetInput();
this->AllocateOutputs();
// note: clear reduces size to zero, but doesn't change capacity.
m_WaveletFilterBankPyramid.clear();
using CastFilterType = itk::CastImageFilter<InputImageType, OutputImageType>;
auto castFilter = CastFilterType::New();
castFilter->SetInput(input);
castFilter->Update();
OutputImagePointer inputPerLevel = castFilter->GetOutput();
using ChangeInformationFilterType = itk::ChangeInformationImageFilter<OutputImageType>;
auto changeInputInfoFilter = ChangeInformationFilterType::New();
typename InputImageType::PointType origin_old = inputPerLevel->GetOrigin();
typename InputImageType::SpacingType spacing_old = inputPerLevel->GetSpacing();
typename InputImageType::DirectionType direction_old = inputPerLevel->GetDirection();
typename InputImageType::PointType origin_new = origin_old;
origin_new.Fill(0);
typename InputImageType::SpacingType spacing_new = spacing_old;
spacing_new.Fill(1);
typename InputImageType::DirectionType direction_new = direction_old;
direction_new.SetIdentity();
changeInputInfoFilter->SetInput(inputPerLevel);
changeInputInfoFilter->ChangeRegionOff();
changeInputInfoFilter->ChangeDirectionOn();
changeInputInfoFilter->ChangeSpacingOn();
changeInputInfoFilter->ChangeOriginOn();
changeInputInfoFilter->UseReferenceImageOff();
changeInputInfoFilter->SetOutputOrigin(origin_new);
changeInputInfoFilter->SetOutputSpacing(spacing_new);
changeInputInfoFilter->SetOutputDirection(direction_new);
changeInputInfoFilter->Update();
// Generate WaveletFilterBank.
this->m_WaveletFilterBank->SetHighPassSubBands(this->m_HighPassSubBands);
this->m_WaveletFilterBank->SetSize(changeInputInfoFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
this->m_WaveletFilterBank->Update();
OutputsType highPassWavelets = this->m_WaveletFilterBank->GetOutputsHighPassBands();
OutputImagePointer lowPassWavelet = this->m_WaveletFilterBank->GetOutputLowPass();
if (this->m_StoreWaveletFilterBankPyramid)
{
for (unsigned int bankOutput = 0; bankOutput < this->m_HighPassSubBands + 1; ++bankOutput)
{
this->m_WaveletFilterBankPyramid.push_back(this->m_WaveletFilterBank->GetOutput(bankOutput));
}
}
// TODO think about passing the FrequencyShrinker as template parameter to work with different FFT layout, or
// regular images directly in frequency domain.
// using LocalFrequencyShrinkFilterType = itk::FrequencyShrinkViaInverseFFTImageFilter<OutputImageType>;
using LocalFrequencyShrinkFilterType = itk::FrequencyShrinkImageFilter<OutputImageType>;
using ShrinkDecimateFilterType = itk::ShrinkDecimateImageFilter<OutputImageType, OutputImageType>;
using MultiplyFilterType = itk::MultiplyImageFilter<OutputImageType>;
inputPerLevel = changeInputInfoFilter->GetOutput();
auto scaleFactor = static_cast<double>(this->m_ScaleFactor);
for (unsigned int level = 0; level < this->m_Levels; ++level)
{
/******* Set HighPass bands *****/
itkDebugMacro(<< "Number of FilterBank high pass bands: " << highPassWavelets.size());
for (unsigned int band = 0; band < this->m_HighPassSubBands; ++band)
{
unsigned int n_output = level * this->m_HighPassSubBands + band;
/******* Band dilation factor for HighPass bands *****/
// 2^(1/#bands) instead of Dyadic dilations.
auto multiplyByAnalysisBandFactor = MultiplyFilterType::New();
multiplyByAnalysisBandFactor->SetInput1(highPassWavelets[band]);
// double expBandFactor = 0;
// double expBandFactor = - static_cast<double>(level*ImageDimension)/2.0;
double expBandFactor =
(-static_cast<double>(level) + band / static_cast<double>(this->m_HighPassSubBands)) * ImageDimension / 2.0;
multiplyByAnalysisBandFactor->SetConstant(std::pow(scaleFactor, expBandFactor));
// TODO Warning: InPlace here deletes buffered region of input.
// http://public.kitware.com/pipermail/community/2015-April/008819.html
// multiplyByAnalysisBandFactor->InPlaceOn();
multiplyByAnalysisBandFactor->Update();
auto multiplyHighBandFilter = MultiplyFilterType::New();
multiplyHighBandFilter->SetInput1(multiplyByAnalysisBandFactor->GetOutput());
multiplyHighBandFilter->SetInput2(inputPerLevel);
multiplyHighBandFilter->InPlaceOn();
multiplyHighBandFilter->GraftOutput(this->GetOutput(n_output));
multiplyHighBandFilter->Update();
this->UpdateProgress(static_cast<float>(n_output - 1) / static_cast<float>(m_TotalOutputs));
this->GraftNthOutput(n_output, multiplyHighBandFilter->GetOutput());
}
/******* Calculate LowPass band *****/
auto multiplyLowFilter = MultiplyFilterType::New();
multiplyLowFilter->SetInput1(lowPassWavelet);
multiplyLowFilter->SetInput2(inputPerLevel);
// multiplyLowFilter->InPlaceOn();
multiplyLowFilter->Update();
inputPerLevel = multiplyLowFilter->GetOutput();
// Shrink in the frequency domain the stored low band for the next level.
auto freqShrinkFilter = LocalFrequencyShrinkFilterType::New();
freqShrinkFilter->SetInput(inputPerLevel);
freqShrinkFilter->SetShrinkFactors(this->m_ScaleFactor);
if (level == this->m_Levels - 1) // Set low_pass output (index=this->m_TotalOutputs - 1)
{
freqShrinkFilter->GraftOutput(this->GetOutput(this->m_TotalOutputs - 1));
freqShrinkFilter->Update();
this->GraftNthOutput(this->m_TotalOutputs - 1, freqShrinkFilter->GetOutput());
this->UpdateProgress(static_cast<float>(this->m_TotalOutputs - 1) / static_cast<float>(this->m_TotalOutputs));
continue;
}
else // update inputPerLevel
{
freqShrinkFilter->Update();
inputPerLevel = freqShrinkFilter->GetOutput();
/******* DownSample wavelets *****/
auto decimateWaveletFilter = ShrinkDecimateFilterType::New();
decimateWaveletFilter->SetInput(lowPassWavelet);
decimateWaveletFilter->SetShrinkFactors(this->m_ScaleFactor);
decimateWaveletFilter->Update();
auto changeDecimateInfoFilter = ChangeInformationFilterType::New();
changeDecimateInfoFilter->SetInput(decimateWaveletFilter->GetOutput());
changeDecimateInfoFilter->ChangeAll();
changeDecimateInfoFilter->UseReferenceImageOn();
changeDecimateInfoFilter->SetReferenceImage(inputPerLevel);
changeDecimateInfoFilter->Update();
lowPassWavelet = changeDecimateInfoFilter->GetOutput();
lowPassWavelet->DisconnectPipeline();
for (unsigned int band = 0; band < this->m_HighPassSubBands; ++band)
{
auto decimateHPWaveletFilter = ShrinkDecimateFilterType::New();
decimateHPWaveletFilter->SetShrinkFactors(this->m_ScaleFactor);
decimateHPWaveletFilter->SetInput(highPassWavelets[band]);
decimateHPWaveletFilter->Update();
auto changeHPDecimateInfoFilter = ChangeInformationFilterType::New();
changeHPDecimateInfoFilter->ChangeAll();
changeHPDecimateInfoFilter->UseReferenceImageOn();
changeHPDecimateInfoFilter->SetReferenceImage(inputPerLevel);
changeHPDecimateInfoFilter->SetInput(decimateHPWaveletFilter->GetOutput());
changeHPDecimateInfoFilter->Update();
highPassWavelets[band] = changeHPDecimateInfoFilter->GetOutput();
highPassWavelets[band]->DisconnectPipeline();
}
if (this->m_StoreWaveletFilterBankPyramid)
{
m_WaveletFilterBankPyramid.push_back(lowPassWavelet);
for (unsigned int band = 0; band < this->m_HighPassSubBands; ++band)
{
m_WaveletFilterBankPyramid.push_back(highPassWavelets[band]);
}
}
} // end update inputPerLevel
} // end level
}
} // end namespace itk
#endif