-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathtubeImageMath.h
332 lines (262 loc) · 11.9 KB
/
tubeImageMath.h
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
/*=========================================================================
Library: TubeTK
Copyright Kitware Inc.
All rights reserved.
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
https://www.apache.org/licenses/LICENSE-2.0
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 __tubeImageMath_h
#define __tubeImageMath_h
// ITK includes
#include "itkProcessObject.h"
#include "itkCastImageFilter.h"
// TubeTK includes
#include "tubeWrappingMacros.h"
#include "tubeImageMathFilters.h"
namespace tube
{
/** \class ImageMath
* \brief Common image processing functions.
*
* \ingroup TubeTK
*/
template< class TInputImage >
class ImageMath:
public itk::ProcessObject
{
public:
/** Standard class typedefs. */
typedef ImageMath Self;
typedef itk::ProcessObject Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
typedef tube::ImageMathFilters< TInputImage::ImageDimension > FilterType;
typedef TInputImage InputImageType;
typedef typename FilterType::ImageType ImageType;
typedef TInputImage OutputImageType;
typedef itk::Image< unsigned char, TInputImage::ImageDimension> ImageTypeUChar;
typedef itk::Image< short, TInputImage::ImageDimension> ImageTypeShort;
/** Method for creation through the object factory. */
itkNewMacro( Self );
/** Run-time type information ( and related methods ). */
itkTypeMacro( ImageMath, ProcessObject );
void SetInput( InputImageType * input )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( input );
castFilter->Update();
typename ImageType::Pointer output = castFilter->GetOutput();
output->Register();
m_Filter.SetInput( output );
this->Modified(); }
/** Get current result */
ImageType * GetInput( void )
{ return m_Filter.GetInput(); }
/** Get current result */
OutputImageType * GetOutput( void )
{ typedef itk::CastImageFilter< ImageType,InputImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( m_Filter.GetOutput() );
castFilter->Update();
typename OutputImageType::Pointer output = castFilter->GetOutput();
output->Register();
return output; }
/** Get current result */
ImageType * GetOutputFloat( void )
{ return m_Filter.GetOutput(); }
/** Get current result */
ImageTypeUChar * GetOutputUChar( void )
{ typedef itk::CastImageFilter< ImageType, ImageTypeUChar > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( m_Filter.GetOutput() );
castFilter->Update();
typename ImageTypeUChar::Pointer output = castFilter->GetOutput();
output->Register();
return output; }
/** Get current result */
ImageTypeShort * GetOutputShort( void )
{ typedef itk::CastImageFilter< ImageType, ImageTypeShort > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( m_Filter.GetOutput() );
castFilter->Update();
typename ImageTypeShort::Pointer output = castFilter->GetOutput();
output->Register();
return output; }
void IntensityWindow( float inValMin, float inValMax,
float outMin, float outMax )
{ m_Filter.ApplyIntensityWindowing( inValMin, inValMax, outMin, outMax );
this->Modified(); };
void IntensityMultiplicativeBiasCorrection(
ImageType * inMeanFieldImage )
{ m_Filter.ApplyIntensityMultiplicativeBiasCorrection( inMeanFieldImage );
this->Modified(); };
void Resample( ImageType * referenceImage )
{ m_Filter.ResampleImage( referenceImage ); this->Modified(); };
void AddUniformNoise( float valMin, float valMax, float noiseMin,
float noiseMax, int seed )
{ m_Filter.AddUniformNoise( valMin, valMax, noiseMin, noiseMax, seed );
this->Modified(); };
void AddGaussianNoise( float valMin, float valMax, float noiseMean,
float noiseRange, int seed )
{ m_Filter.AddGaussianNoise( valMin, valMax, noiseMean, noiseRange, seed );
this->Modified(); };
void AddImages( InputImageType * input2, float weight1, float weight2 )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( input2 );
castFilter->Update();
m_Filter.AddImages( castFilter->GetOutput(), weight1, weight2 );
this->Modified(); };
void MultiplyImages( InputImageType * input2 )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( input2 );
castFilter->Update();
m_Filter.MultiplyImages( castFilter->GetOutput() );
this->Modified(); };
void PadUsingMirroring( int numPadVoxels )
{ m_Filter.MirrorAndPadImage( numPadVoxels ); this->Modified(); };
void NormalizeMeanStdDev()
{ m_Filter.NormalizeImage( 0 ); this->Modified(); };
void NormalizeFWHM()
{ m_Filter.NormalizeImage( 1 ); this->Modified(); };
void NormalizeMeanShift()
{ m_Filter.NormalizeImage( 2 ); this->Modified(); };
void FuseUsingMax( InputImageType * input2, float offset2 )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( input2 );
castFilter->Update();
m_Filter.FuseImages( castFilter->GetOutput(), offset2 );
this->Modified(); };
void MedianFilter( int size )
{ m_Filter.MedianImage( size ); this->Modified(); };
void Threshold( float threshLow, float threshHigh, float valTrue,
float valFalse )
{ m_Filter.ThresholdImage( threshLow, threshHigh, valTrue, valFalse);
this->Modified(); };
double MeanWithinMaskRange( InputImageType * mask, float maskThreshLow,
float maskThreshHigh )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( mask );
castFilter->Update();
return m_Filter.ComputeImageStatisticsWithinMaskRange( castFilter->GetOutput(),
maskThreshLow, maskThreshHigh, 0 ); };
double StdDevWithinMaskRange( InputImageType * mask, float maskThreshLow,
float maskThreshHigh )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( mask );
castFilter->Update();
return m_Filter.ComputeImageStatisticsWithinMaskRange( castFilter->GetOutput(),
maskThreshLow, maskThreshHigh, 1 ); };
void AbsoluteValue()
{ m_Filter.AbsoluteImage(); this->Modified(); };
void ReplaceValuesOutsideMaskRange( InputImageType * mask, float maskThreshLow,
float maskThreshHigh, float valFalse )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( mask );
castFilter->Update();
m_Filter.ReplaceValuesOutsideMaskRange( castFilter->GetOutput(),
maskThreshLow, maskThreshHigh, valFalse ); this->Modified(); };
void Erode( int radius, float fgVal, float bkgVal )
{ m_Filter.MorphImage( 0, radius, fgVal, bkgVal ); this->Modified(); };
void Dilate( int radius, float fgVal, float bkgVal )
{ m_Filter.MorphImage( 1, radius, fgVal, bkgVal ); this->Modified(); };
void ReplaceValueWithinMaskRange( InputImageType * mask, float maskThreshLow,
float maskThreshHigh, float imageVal, float newImageVal )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( mask );
castFilter->Update();
m_Filter.ReplaceValueWithinMaskRange( castFilter->GetOutput(),
maskThreshLow, maskThreshHigh, imageVal, newImageVal ); this->Modified(); };
void Blur( float sigma )
{ m_Filter.BlurImage( sigma ); this->Modified(); };
void BlurOrder( float sigma, int order, int direction )
{ m_Filter.BlurOrderImage( sigma, order, direction ); this->Modified(); };
std::vector<double> Histogram( unsigned int nBins )
{
m_HistogramBinMin = 0;
m_HistogramBinSize = 0;
this->Modified();
return m_Filter.ComputeImageHistogram( nBins, m_HistogramBinMin,
m_HistogramBinSize );
};
float HistogramBinMin( void )
{ return m_HistogramBinMin; }
float HistogramBinSize( void )
{ return m_HistogramBinSize; }
std::vector<double> Histogram( unsigned int nBins, float binMin,
float binSize )
{
m_HistogramBinMin = binMin;
m_HistogramBinSize = binSize;
this->Modified();
return m_Filter.ComputeImageHistogram( nBins, m_HistogramBinMin,
m_HistogramBinSize );
}
void IntensityCorrectionBySlice( unsigned int nBins,
unsigned int nMatchPoints )
{ m_Filter.CorrectIntensitySliceBySliceUsingHistogramMatching(
nBins, nMatchPoints ); this->Modified(); };
void IntensityCorrection( unsigned int nBins, unsigned int nMatchPoints,
InputImageType * referenceImage )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( referenceImage );
castFilter->Update();
m_Filter.CorrectIntensityUsingHistogramMatching( nBins, nMatchPoints,
castFilter->GetOutput() ); this->Modified(); };
void Resize( double factor )
{ m_Filter.Resize( factor ); this->Modified(); };
void Resize( InputImageType * referenceImage )
{ typedef itk::CastImageFilter< InputImageType, ImageType > CastFilterType;
typename CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput( referenceImage );
castFilter->Update();
m_Filter.Resize( castFilter->GetOutput() ); this->Modified(); };
void ExtractSlice( unsigned int dimension, unsigned int slice )
{ m_Filter.ExtractSlice( dimension, slice ); this->Modified(); };
void EnhanceVessels( double scaleMin, double scaleMax, int numScales )
{ m_Filter.EnhanceVessels( scaleMin, scaleMax, numScales );
this->Modified(); };
void ConnectedComponents( float threshLow, float threshHigh, float labelVal,
float x, float y, float z )
{ m_Filter.SegmentUsingConnectedThreshold( threshLow, threshHigh, labelVal,
x, y, z ); this->Modified(); };
std::vector< itk::ContinuousIndex< double, TInputImage::ImageDimension > >
VoronoiTessellation( unsigned int nCentroids, unsigned int nIters,
unsigned int nSamples )
{ this->Modified();
return m_Filter.ComputeVoronoiTessellation( nCentroids, nIters, nSamples ); };
itk::VariableSizeMatrix<double> GetVoronoiTessellationAdjacencyMatrix( void )
{ return m_Filter.GetVoronoiTessellationAdjacencyMatrix(); };
protected:
ImageMath( void );
~ImageMath() {}
void PrintSelf( std::ostream & os, itk::Indent indent ) const;
private:
/** ImageMath parameters **/
ImageMath( const Self & );
void operator=( const Self & );
// To remove warning "was hidden [-Woverloaded-virtual]"
void SetInput( const DataObjectIdentifierType &, itk::DataObject * ) {};
FilterType m_Filter;
float m_HistogramBinMin;
float m_HistogramBinSize;
};
} // End namespace tube
#ifndef ITK_MANUAL_INSTANTIATION
#include "tubeImageMath.hxx"
#endif
#endif // End !defined( __tubeImageMath_h )