-
Notifications
You must be signed in to change notification settings - Fork 6
/
pctbackprojections.cxx
94 lines (80 loc) · 3.41 KB
/
pctbackprojections.cxx
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
#include "pctbackprojections_ggo.h"
#include "rtkGgoFunctions.h"
#include "rtkThreeDCircularProjectionGeometryXMLFile.h"
#include "rtkProjectionsReader.h"
#include "pctFDKDDBackProjectionImageFilter.h"
#include "rtkJosephBackProjectionImageFilter.h"
#include <itkRegularExpressionSeriesFileNames.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkTimeProbe.h>
int main(int argc, char * argv[])
{
GGO(pctbackprojections, args_info);
typedef float OutputPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< OutputPixelType, Dimension+1 > ProjectionImageType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
// Geometry
if(args_info.verbose_flag)
std::cout << "Reading geometry information from "
<< args_info.geometry_arg
<< "..."
<< std::flush;
rtk::ThreeDCircularProjectionGeometryXMLFileReader::Pointer geometryReader;
geometryReader = rtk::ThreeDCircularProjectionGeometryXMLFileReader::New();
geometryReader->SetFilename(args_info.geometry_arg);
TRY_AND_EXIT_ON_ITK_EXCEPTION( geometryReader->GenerateOutputInformation() )
if(args_info.verbose_flag)
std::cout << " done." << std::endl;
// Create an empty volume
typedef rtk::ConstantImageSource< OutputImageType > ConstantImageSourceType;
ConstantImageSourceType::Pointer constantImageSource = ConstantImageSourceType::New();
rtk::SetConstantImageSourceFromGgo<ConstantImageSourceType, args_info_pctbackprojections>(constantImageSource, args_info);
// Generate file names
itk::RegularExpressionSeriesFileNames::Pointer names = itk::RegularExpressionSeriesFileNames::New();
names->SetDirectory(args_info.path_arg);
names->SetNumericSort(false);
names->SetRegularExpression(args_info.regexp_arg);
names->SetSubMatch(0);
if(args_info.verbose_flag)
std::cout << "Reading "
<< names->GetFileNames().size()
<< " projection file(s)..."
<< std::flush;
// Projections reader
typedef rtk::ProjectionsReader< ProjectionImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileNames( names->GetFileNames() );
if(args_info.wpc_given)
{
std::vector<double> coeffs;
coeffs.assign(args_info.wpc_arg, args_info.wpc_arg+args_info.wpc_given);
reader->SetWaterPrecorrectionCoefficients(coeffs);
}
TRY_AND_EXIT_ON_ITK_EXCEPTION( reader->Update() );
if(args_info.verbose_flag)
std::cout << " done." << std::endl;
// Create back projection image filter
if(args_info.verbose_flag)
std::cout << "Backprojecting volume..." << std::flush;
typedef pct::FDKDDBackProjectionImageFilter<OutputImageType, OutputImageType> BPType;
BPType::Pointer bp = BPType::New();
bp->SetInput( constantImageSource->GetOutput() );
bp->SetProjectionStack( reader->GetOutput() );
bp->SetGeometry( geometryReader->GetOutputObject() );
TRY_AND_EXIT_ON_ITK_EXCEPTION( bp->Update() )
if(args_info.verbose_flag)
std::cout << " done ." << std::endl;
// Write
if(args_info.verbose_flag)
std::cout << "Writing... " << std::flush;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( args_info.output_arg );
writer->SetInput( bp->GetOutput() );
TRY_AND_EXIT_ON_ITK_EXCEPTION( writer->Update() );
if(args_info.verbose_flag)
std::cout << " done" << std::endl;
return EXIT_SUCCESS;
}