58 using ImageType =
typename TConstantImageSourceType::OutputImageType;
60 const unsigned int Dimension = ImageType::GetImageDimension();
62 typename ImageType::SizeType imageSize;
63 if (args_info.dimension_given)
65 itkGenericOutputMacro(
66 "Warning: --dimension is deprecated and will be removed in a future release. Use --size instead.");
67 imageSize.Fill(args_info.dimension_arg[0]);
68 for (
unsigned int i = 0; i < std::min(args_info.dimension_given, Dimension); i++)
70 imageSize[i] = args_info.dimension_arg[i];
75 imageSize.Fill(args_info.size_arg[0]);
76 for (
unsigned int i = 0; i < std::min(args_info.size_given, Dimension); i++)
77 imageSize[i] = args_info.size_arg[i];
80 typename ImageType::SpacingType imageSpacing;
81 imageSpacing.Fill(args_info.spacing_arg[0]);
82 for (
unsigned int i = 0; i < std::min(args_info.spacing_given, Dimension); i++)
83 imageSpacing[i] = args_info.spacing_arg[i];
85 typename ImageType::PointType imageOrigin;
86 for (
unsigned int i = 0; i < Dimension; i++)
87 imageOrigin[i] = imageSpacing[i] * (imageSize[i] - 1) * -0.5;
88 for (
unsigned int i = 0; i < std::min(args_info.origin_given, Dimension); i++)
89 imageOrigin[i] = args_info.origin_arg[i];
91 typename ImageType::DirectionType imageDirection;
92 if (args_info.direction_given)
93 for (
unsigned int i = 0; i < Dimension; i++)
94 for (
unsigned int j = 0; j < Dimension; j++)
95 imageDirection[i][j] = args_info.direction_arg[i * Dimension + j];
97 imageDirection.SetIdentity();
99 source->SetOrigin(imageOrigin);
100 source->SetSpacing(imageSpacing);
101 source->SetDirection(imageDirection);
102 source->SetSize(imageSize);
103 source->SetConstant({});
107 if (args_info.like_given)
110 auto likeReader = LikeReaderType::New();
111 likeReader->SetFileName(args_info.like_arg);
113 source->SetInformationFromImage(likeReader->GetOutput());
140 names->SetDirectory(args_info.path_arg);
141 names->SetNumericSort(args_info.nsort_flag);
142 names->SetRegularExpression(args_info.regexp_arg);
143 names->SetSubMatch(args_info.submatch_arg);
145 if (!names->GetFileNames().size())
146 itkGenericExceptionMacro(<<
"The regular expression matches 0 file");
148 if (args_info.verbose_flag)
149 std::cout <<
"Regular expression matches " << names->GetFileNames().size() <<
" file(s)..." << std::endl;
152 if (args_info.submatch_given)
155 itksys::RegularExpression reg;
156 if (!reg.compile(args_info.regexp_arg))
158 itkGenericExceptionMacro(<<
"Error compiling regular expression " << args_info.regexp_arg);
162 for (
const std::string & name : names->GetFileNames())
165 if (reg.match(args_info.submatch_arg) == std::string(
""))
167 itkGenericExceptionMacro(<<
"Cannot find submatch " << args_info.submatch_arg <<
" in " << name
168 <<
" from regular expression " << args_info.regexp_arg);
173 std::vector<std::string> fileNames = names->GetFileNames();
175 std::vector<size_t> idxtopop;
177 for (
const auto & fn : fileNames)
184 std::cerr <<
"Ignoring file: " << fn <<
"\n";
185 idxtopop.push_back(i);
189 std::reverse(idxtopop.begin(), idxtopop.end());
190 for (
const auto &
id : idxtopop)
192 fileNames.erase(fileNames.begin() +
id);
195 if (fileNames.empty())
196 itkGenericExceptionMacro(<<
"All file names matched by the regular expression could not be read");
208 if (args_info.component_given)
210 reader->SetVectorComponent(args_info.component_arg);
214 const unsigned int Dimension = TProjectionsReaderType::OutputImageType::GetImageDimension();
215 typename TProjectionsReaderType::OutputImageDirectionType direction;
216 if (args_info.newdirection_given)
218 direction.Fill(args_info.newdirection_arg[0]);
219 for (
unsigned int i = 0; i < args_info.newdirection_given; i++)
220 direction[i / Dimension][i % Dimension] = args_info.newdirection_arg[i];
221 reader->SetDirection(direction);
223 typename TProjectionsReaderType::OutputImageSpacingType spacing;
224 if (args_info.newspacing_given)
226 spacing.Fill(args_info.newspacing_arg[0]);
227 for (
unsigned int i = 0; i < args_info.newspacing_given; i++)
228 spacing[i] = args_info.newspacing_arg[i];
229 reader->SetSpacing(spacing);
231 typename TProjectionsReaderType::OutputImagePointType origin;
232 if (args_info.neworigin_given)
234 origin.Fill(args_info.neworigin_arg[0]);
235 for (
unsigned int i = 0; i < args_info.neworigin_given; i++)
236 origin[i] = args_info.neworigin_arg[i];
237 reader->SetOrigin(origin);
242 for (
unsigned int i = 0; i < args_info.lowercrop_given; i++)
243 lowerCrop[i] = args_info.lowercrop_arg[i];
244 if (args_info.lowercrop_given)
245 reader->SetLowerBoundaryCropSize(lowerCrop);
248 for (
unsigned int i = 0; i < args_info.uppercrop_given; i++)
249 upperCrop[i] = args_info.uppercrop_arg[i];
250 if (args_info.uppercrop_given)
251 reader->SetUpperBoundaryCropSize(upperCrop);
254 typename TProjectionsReaderType::MedianRadiusType medianRadius{};
255 for (
unsigned int i = 0; i < args_info.radius_given; i++)
256 medianRadius[i] = args_info.radius_arg[i];
257 reader->SetMedianRadius(medianRadius);
258 if (args_info.multiplier_given)
259 reader->SetConditionalMedianThresholdMultiplier(args_info.multiplier_arg);
262 typename TProjectionsReaderType::ShrinkFactorsType binFactors;
264 for (
unsigned int i = 0; i < args_info.binning_given; i++)
265 binFactors[i] = args_info.binning_arg[i];
266 reader->SetShrinkFactors(binFactors);
269 if (args_info.spr_given)
270 reader->SetScatterToPrimaryRatio(args_info.spr_arg);
271 if (args_info.nonneg_given)
272 reader->SetNonNegativityConstraintThreshold(args_info.nonneg_arg);
273 if (args_info.airthres_given)
274 reader->SetAirThreshold(args_info.airthres_arg);
277 if (args_info.i0_given)
278 reader->SetI0(args_info.i0_arg);
279 reader->SetIDark(args_info.idark_arg);
282 if (args_info.nolineint_flag)
283 reader->ComputeLineIntegralOff();
286 if (args_info.wpc_given)
288 std::vector<double> coeffs;
289 coeffs.assign(args_info.wpc_arg, args_info.wpc_arg + args_info.wpc_given);
290 reader->SetWaterPrecorrectionCoefficients(coeffs);
294 reader->SetFileNames(fileNames);
303 using ImageType = TImageType;
304 typename TImageType::Pointer newproj = projections;
307 if (args_info.poisson_given)
309 const double I0{ args_info.poisson_arg[0] };
310 double muref{ 0.01879 };
311 if (args_info.poisson_given > 1)
312 muref = args_info.poisson_arg[1];
315 multiply->SetInput(newproj);
316 multiply->SetConstant(-muref);
319 expf->SetInput(multiply->GetOutput());
322 multiply2->SetInput(expf->GetOutput());
323 multiply2->SetConstant(I0);
326 poisson->SetInput(multiply2->GetOutput());
329 threshold->SetInput(poisson->GetOutput());
330 threshold->SetLower(1.);
331 threshold->SetOutsideValue(1.);
336 if (args_info.gaussian_given)
338 gaussian->SetInput(threshold->GetOutput());
339 gaussian->SetStandardDeviation(args_info.gaussian_arg);
340 multiply3->SetInput(gaussian->GetOutput());
343 multiply3->SetInput(threshold->GetOutput());
344 multiply3->SetConstant(1. / I0);
347 logf->SetInput(multiply3->GetOutput());
350 multiply4->SetInput(logf->GetOutput());
351 multiply4->SetConstant(-1. / muref);
354 newproj = multiply4->GetOutput();
356 else if (args_info.gaussian_given)
359 gaussian->SetInput(newproj);
360 gaussian->SetStandardDeviation(args_info.gaussian_arg);
363 newproj = gaussian->GetOutput();
381 typename TIterativeReconstructionFilter::VolumeType::Pointer attenuationMap;
382 using VolumeType =
typename TIterativeReconstructionFilter::VolumeType;
383 if (args_info.attenuationmap_given)
389 switch (args_info.bp_arg)
394 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_VOXELBASED);
397 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_JOSEPH);
400 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_CUDAVOXELBASED);
403 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_CUDARAYCAST);
404 if (args_info.step_given)
405 recon->SetStepSize(args_info.step_arg);
408 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_JOSEPHATTENUATED);
409 if (args_info.attenuationmap_given)
410 recon->SetAttenuationMap(attenuationMap);
413 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_ZENG);
414 if (args_info.sigmazero_given)
415 recon->SetSigmaZero(args_info.sigmazero_arg);
416 if (args_info.alphapsf_given)
417 recon->SetAlphaPSF(args_info.alphapsf_arg);
418 if (args_info.attenuationmap_given)
419 recon->SetAttenuationMap(attenuationMap);
422 recon->SetBackProjectionFilter(TIterativeReconstructionFilter::BP_CUDAZENG);
423 if (args_info.sigmazero_given)
424 recon->SetSigmaZero(args_info.sigmazero_arg);
425 if (args_info.alphapsf_given)
426 recon->SetAlphaPSF(args_info.alphapsf_arg);
427 if (args_info.attenuationmap_given)
428 recon->SetAttenuationMap(attenuationMap);
445 typename TIterativeReconstructionFilter::VolumeType::Pointer attenuationMap;
446 using VolumeType =
typename TIterativeReconstructionFilter::VolumeType;
447 if (args_info.attenuationmap_given)
453 typename ClipImageType::Pointer inferiorClipImage, superiorClipImage;
454 if (args_info.inferiorclipimage_given)
459 if (args_info.superiorclipimage_given)
465 switch (args_info.fp_arg)
470 recon->SetForwardProjectionFilter(TIterativeReconstructionFilter::FP_JOSEPH);
471 if (args_info.superiorclipimage_given)
472 recon->SetSuperiorClipImage(superiorClipImage);
473 if (args_info.inferiorclipimage_given)
474 recon->SetInferiorClipImage(inferiorClipImage);
477 recon->SetForwardProjectionFilter(TIterativeReconstructionFilter::FP_CUDARAYCAST);
478 if (args_info.step_given)
479 recon->SetStepSize(args_info.step_arg);
482 recon->SetForwardProjectionFilter(TIterativeReconstructionFilter::FP_JOSEPHATTENUATED);
483 if (args_info.superiorclipimage_given)
484 recon->SetSuperiorClipImage(superiorClipImage);
485 if (args_info.inferiorclipimage_given)
486 recon->SetInferiorClipImage(inferiorClipImage);
487 if (args_info.attenuationmap_given)
488 recon->SetAttenuationMap(attenuationMap);
491 recon->SetForwardProjectionFilter(TIterativeReconstructionFilter::FP_ZENG);
492 if (args_info.sigmazero_given)
493 recon->SetSigmaZero(args_info.sigmazero_arg);
494 if (args_info.alphapsf_given)
495 recon->SetAlphaPSF(args_info.alphapsf_arg);
496 if (args_info.attenuationmap_given)
497 recon->SetAttenuationMap(attenuationMap);
500 recon->SetForwardProjectionFilter(TIterativeReconstructionFilter::FP_CUDAZENG);
501 if (args_info.sigmazero_given)
502 recon->SetSigmaZero(args_info.sigmazero_arg);
503 if (args_info.alphapsf_given)
504 recon->SetAlphaPSF(args_info.alphapsf_arg);
505 if (args_info.attenuationmap_given)
506 recon->SetAttenuationMap(attenuationMap);