forked from SimonRit/PCT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pctfdk.cxx
102 lines (84 loc) · 3.83 KB
/
pctfdk.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
95
96
97
98
99
100
101
102
#include "pctfdk_ggo.h"
#include "rtkGgoFunctions.h"
#include "rtkThreeDCircularProjectionGeometryXMLFile.h"
#include "rtkProjectionsReader.h"
#include "pctDDParkerShortScanImageFilter.h"
#include "pctFDKDDConeBeamReconstructionFilter.h"
#include <itkRegularExpressionSeriesFileNames.h>
#include <itkImageFileWriter.h>
int main(int argc, char * argv[])
{
GGO(pctfdk, args_info);
typedef float OutputPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads( std::min<double>(8, itk::MultiThreaderBase::GetGlobalMaximumNumberOfThreads() ) );
// 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 << "Regular expression matches "
<< names->GetFileNames().size()
<< " file(s)..."
<< std::endl;
// Projections reader
typedef itk::Image< OutputPixelType, Dimension+1 > ProjectionImageType;
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);
}
// Geometry
if(args_info.verbose_flag)
std::cout << "Reading geometry information from "
<< args_info.geometry_arg
<< "..."
<< std::endl;
rtk::ThreeDCircularProjectionGeometryXMLFileReader::Pointer geometryReader;
geometryReader = rtk::ThreeDCircularProjectionGeometryXMLFileReader::New();
geometryReader->SetFilename(args_info.geometry_arg);
TRY_AND_EXIT_ON_ITK_EXCEPTION( geometryReader->GenerateOutputInformation() )
// Short scan image filter
typedef pct::DDParkerShortScanImageFilter< ProjectionImageType > PSSFType;
PSSFType::Pointer pssf = PSSFType::New();
pssf->SetInput( reader->GetOutput() );
pssf->SetGeometry( geometryReader->GetOutputObject() );
pssf->InPlaceOff();
// Create reconstructed image
typedef rtk::ConstantImageSource< OutputImageType > ConstantImageSourceType;
ConstantImageSourceType::Pointer constantImageSource = ConstantImageSourceType::New();
rtk::SetConstantImageSourceFromGgo<ConstantImageSourceType, args_info_pctfdk>(constantImageSource, args_info);
// FDK reconstruction filtering
typedef pct::FDKDDConeBeamReconstructionFilter< OutputImageType > FDKCPUType;
FDKCPUType::Pointer feldkamp = FDKCPUType::New();
feldkamp->SetInput( 0, constantImageSource->GetOutput() );
feldkamp->SetProjectionStack( pssf->GetOutput() );
feldkamp->SetGeometry( geometryReader->GetOutputObject() );
feldkamp->GetRampFilter()->SetTruncationCorrection(args_info.pad_arg);
feldkamp->GetRampFilter()->SetHannCutFrequency(args_info.hann_arg);
feldkamp->GetRampFilter()->SetHannCutFrequencyY(args_info.hannY_arg); \
// Write
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( args_info.output_arg );
writer->SetInput( feldkamp->GetOutput() );
if(args_info.verbose_flag)
std::cout << "Reconstructing and writing... " << std::flush;
itk::TimeProbe writerProbe;
writerProbe.Start();
TRY_AND_EXIT_ON_ITK_EXCEPTION( writer->Update() );
writerProbe.Stop();
if(args_info.verbose_flag)
{
std::cout << "It took " << writerProbe.GetMean() << ' ' << writerProbe.GetUnit() << std::endl;
feldkamp->PrintTiming(std::cout);
}
return EXIT_SUCCESS;
}