-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gbe_3DRegistration.h
323 lines (267 loc) · 11.2 KB
/
_gbe_3DRegistration.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
#pragma once
#include "itkTimeProbesCollectorBase.h"
//#include "itkFileOutputWindow.h"
#include "itkImageRegistrationMethodv4.h"
#include "itkImageToImageMetricv4.h"//metric base we include for the pointer
#include "itkMeanSquaresImageToImageMetricv4.h"
#include "itkMattesMutualInformationImageToImageMetricv4.h"
//#include "itkCorrelationImageToImageMetricv4.h"
#include "itkVersorRigid3DTransform.h"
#include "itkEuler3DTransform.h"
#include "itkCenteredTransformInitializer.h"
#include "itkRegularStepGradientDescentOptimizerv4.h"
#include "itkConjugateGradientLineSearchOptimizerv4.h"
#include "itkPowellOptimizerv4.h"
#include "itkLBFGSOptimizerv4.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkBSplineResampleImageFunction.h"
#include "itkCastImageFilter.h"
#include "itkSubtractImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkExtractImageFilter.h"
#include "itkCropImageFilter.h"
#include "itkRegionOfInterestImageFilter.h"
#include "itkSpatialOrientationAdapter.h"
#include "itkImageMaskSpatialObject.h"
//#include "DicomImageReadPrintTags.h"
#include "gdcmReader.h"
#include "gdcmGlobal.h"
#include "gdcmDicts.h"
#include "gdcmDict.h"
#include "gdcmAttribute.h"
#include "gdcmStringFilter.h"
#include "gdcmItem.h"
#include "gdcmSequenceOfItems.h"
/***************************/
#define Reg33GetMacro(name, type) \
virtual type Get##name () \
{ \
return this->##name; \
}
#define Reg33SetMacro(name, type) \
virtual void Set##name (const type _arg) \
{ \
if ( this->##name != _arg ) \
{ \
this->##name = _arg; \
} \
}
#define Reg33SetCharMacro(name, type) \
virtual void Set##name (type _arg) \
{ \
if ( this->##name != _arg ) \
{ \
this->##name = _arg; \
} \
}
class _3DRegistration
{
private:
/* Static variables */
static const unsigned int Dimension = 3;
public:
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > FixedImageType;
typedef itk::Image< PixelType, Dimension > MovingImageType;
typedef itk::ImageMaskSpatialObject<Dimension>::ImageType ImageMaskType;
//typedef itk::VersorRigid3DTransform< double > TransformType;
typedef itk::Euler3DTransform< double> TransformType;
FixedImageType::Pointer fixedImage;
MovingImageType::Pointer movingImage;
typedef FixedImageType::SpacingType SpacingType;
typedef FixedImageType::PointType OriginType;
typedef FixedImageType::RegionType RegionType;
typedef FixedImageType::SizeType SizeType;
TransformType::TranslationType translation;
/*Output Dimensions*/
SpacingType FinalMovingSpacing;
OriginType FinalMovingOrigin;
SizeType FinalMovingSize;
SpacingType OriginalMovingSpacing;
OriginType OriginalMovingOrigin;
SizeType OriginalMovingSize;
SpacingType OriginalFixedSpacing;
OriginType OriginalFixedOrigin;
SizeType OriginalFixedSize;
/*Enum types*/
enum MetricSelection
{
MMI,
MSE,
};
typedef itk::ObjectToObjectOptimizerBaseTemplate<double> OptimizerBaseType;
//typedef itk::LBFGSOptimizerv4 LBFGSOptimizerType;
typedef itk::LBFGSOptimizerv4 OptimizerType;
//typedef itk::RegularStepGradientDescentOptimizerv4<double> OptimizerType;
//typedef itk::PowellOptimizerv4<double> OptimizerType;
typedef itk::PowellOptimizerv4<double> PowellOptimizerType;
//typedef itk::ConjugateGradientLineSearchOptimizerv4Template<double> OptimizerType;
typedef itk::ImageToImageMetricv4< FixedImageType, MovingImageType > MetricType;
typedef itk::MeanSquaresImageToImageMetricv4< FixedImageType, MovingImageType > MeanSquaresMetricType;
typedef itk::MattesMutualInformationImageToImageMetricv4< FixedImageType, MovingImageType > MIMetricType;
typedef itk::ImageRegistrationMethodv4<
FixedImageType,
MovingImageType,
TransformType > RegistrationType;
MetricType::Pointer metric;
OptimizerType::Pointer optimizer = OptimizerType::New();
RegistrationType::Pointer registration = RegistrationType::New();
/*Private functions*/
private:
/* Timers */
itk::TimeProbesCollectorBase timer;
/* flags */
bool verbose = false;
bool ok = false;
bool customized_iso = false;
bool moving_mask = false;
bool fixed_mask = false;
bool debug = false;
bool fixed_resample = false;
bool moving_resample = false;
bool resolution = false;
bool shrinking = false;
bool RTplan = false;
bool like = false;
bool real = false;
bool autocrop = false; //enhances speed (is overriden by RTPlan)
/* enumerators */
MetricSelection RegistrationMetric = MMI;
/* operators */
const double dtr = (atan(1.0) * 4.0) / 180.0;
double cx = 0;
double cy = -234;
double cz = 70;
TransformType::InputPointType Isocenter;
/* Registration parameters */
const unsigned int numberOfLevels = 1;//2;
double shrinkFactor = 1;
//FixedImageType::SpacingType ResampleSpacing;
FixedImageType::SpacingType FixedImageResampleSpacing;
FixedImageType::SpacingType MovingImageResampleSpacing;
float DefaultPixelValue = -1024;
typedef OptimizerType::ScalesType OptimizerScalesType;
const double translationScale = 1.0;
const double rotationScale = 1.0 / dtr;
RegistrationType::ShrinkFactorsArrayType shrinkFactorsPerLevel;
uint64_t ShrinkFactorInput[2] = {2,1};
RegistrationType::SmoothingSigmasArrayType smoothingSigmasPerLevel;
uint64_t SmoothingSigmaInput[2] = {2,0};
/* filenames */
std::string Outputfilename = "CBCT_registered.mha";
std::string OutputTransformfilename = "3DRigidRegistrationTransform.txt";
//std::string Iterationfilename = "3DRigidRegistrationIt.txt";
//char* fixedImagefilename = NULL;
//char* movingImagefilename = NULL;
//char* movingMaskfilename = NULL;
//char* fixedMaskfilename = NULL;
//char* Orientation = "RAI";
//char* RTplanFilename = NULL;
std::string fixedImagefilename = std::string();
std::string movingImagefilename = std::string();
std::string movingMaskfilename = std::string();
std::string fixedMaskfilename = std::string();
std::string Orientation = "RAI";
std::string RTplanFilename = std::string();
/* Types */
TransformType::Pointer initialTransform = TransformType::New();
typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
typedef itk::ImageFileReader< ImageMaskType > MaskReaderType;
typedef itk::ImageMaskSpatialObject < Dimension > MaskType;
FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
MaskReaderType::Pointer movingMaskReader = MaskReaderType::New();
MaskReaderType::Pointer fixedMaskReader = MaskReaderType::New();
MaskType::Pointer spatialObjectMovingMask = MaskType::New();
MaskType::Pointer spatialObjectFixedMask = MaskType::New();
//typedef itk::CenteredTransformInitializer<
// TransformType,
// FixedImageType,
// MovingImageType > TransformInitializerType;
//TransformInitializerType::Pointer initializer =
// TransformInitializerType::New();
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
//typedef itk::CastImageFilter< FixedImageType, OutputImageType > CastFilterType;
typedef itk::ImageFileWriter< FixedImageType > WriterType;
typedef itk::ResampleImageFilter<
MovingImageType,
FixedImageType > ResampleFilterType;
ResampleFilterType::Pointer IsoAlignment = ResampleFilterType::New();
//typedef itk::ExtractImageFilter<FixedImageType, FixedImageType> CropFixedFilterType;
typedef itk::CropImageFilter<FixedImageType, FixedImageType> CropFixedFilterType;
typedef itk::RegionOfInterestImageFilter<FixedImageType, FixedImageType> ROIFilterType;
private:
//bool Initialize(FixedImageType::Pointer &fixedImage, MovingImageType::Pointer &movingImage);
//bool Resample(FixedImageType::Pointer InputImage, double shrinkfactor, FixedImageType::Pointer &OutputImage);
bool IsocenterSearch(std::string argv, unsigned int &count, double Isocenter[][3]);
bool Resample(FixedImageType::Pointer InputImage, FixedImageType::SpacingType OutputSpacing, FixedImageType::Pointer &OutputImage);
bool Crop(FixedImageType::Pointer Image2Crop, FixedImageType::Pointer ReferenceImage, FixedImageType::Pointer &OutputImage);
bool ROICrop(FixedImageType::Pointer Image2Crop, FixedImageType::Pointer ReferenceImage, FixedImageType::Pointer & OutputImage);
public:
_3DRegistration();
_3DRegistration(int argc, char * argv[]);
virtual ~_3DRegistration();
template<typename TMetricType>
bool Initialize();
bool StartRegistration();
bool SetLevels();
bool ReadIsocenter();
/*Set/Get Methods*/
Reg33GetMacro(verbose, bool);
Reg33SetMacro(verbose, bool);
Reg33GetMacro(debug, bool);
Reg33SetMacro(debug, bool);
Reg33GetMacro(moving_mask, bool);
Reg33SetMacro(moving_mask, bool);
Reg33GetMacro(fixed_mask, bool);
Reg33SetMacro(fixed_mask, bool);
Reg33GetMacro(RTplan, bool);
Reg33SetMacro(RTplan, bool);
Reg33GetMacro(moving_resample, bool);
Reg33SetMacro(moving_resample, bool);
Reg33GetMacro(fixed_resample, bool);
Reg33SetMacro(fixed_resample, bool);
Reg33GetMacro(autocrop, bool);
Reg33SetMacro(autocrop, bool);
Reg33GetMacro(real, bool);
Reg33SetMacro(real, bool);
Reg33GetMacro(like, bool);
Reg33SetMacro(like, bool);
Reg33GetMacro(RegistrationMetric, MetricSelection);
Reg33SetMacro(RegistrationMetric, MetricSelection);
Reg33GetMacro(fixedImagefilename, std::string);
Reg33SetMacro(fixedImagefilename, std::string);
Reg33GetMacro(movingImagefilename, std::string);
Reg33SetMacro(movingImagefilename, std::string);
Reg33GetMacro(fixedMaskfilename, std::string);
Reg33SetMacro(fixedMaskfilename, std::string);
Reg33GetMacro(movingMaskfilename, std::string);
Reg33SetMacro(movingMaskfilename, std::string);
Reg33GetMacro(RTplanFilename, std::string);
Reg33SetMacro(RTplanFilename, std::string);
Reg33GetMacro(Outputfilename, std::string);
Reg33SetMacro(Outputfilename, std::string);
Reg33GetMacro(DefaultPixelValue, float);
Reg33SetMacro(DefaultPixelValue, float);
/*char* fixedImagefilename = NULL;
char* movingImagefilename = NULL;
char* movingMaskfilename = NULL;
char* fixedMaskfilename = NULL;
char* Orientation = "RAI";
char* RTplanFilename = NULL;
*/
itkBooleanMacro(verbose);
itkBooleanMacro(debug);
itkBooleanMacro(moving_mask);
itkBooleanMacro(fixed_mask);
itkBooleanMacro(RTplan);
itkBooleanMacro(autocrop);
itkBooleanMacro(moving_resample);
itkBooleanMacro(fixed_resample);
itkBooleanMacro(real);
itkBooleanMacro(like);
};