Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ include(${ITK_USE_FILE})

#-----------------------------------------------------------------------------
# Executables
add_subdirectory(rtkaddgaussiannoise)
add_subdirectory(rtkaddpoissonnoise)
add_subdirectory(rtkamsterdamshroud)
add_subdirectory(rtkbackprojections)
add_subdirectory(rtkfdk)
Expand Down
13 changes: 13 additions & 0 deletions applications/rtkaddgaussiannoise/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WRAP_GGO(rtkaddgaussiannoise_GGO_C rtkaddgaussiannoise.ggo ${RTK_BINARY_DIR}/rtkVersion.ggo)
add_executable(rtkaddgaussiannoise rtkaddgaussiannoise.cxx ${rtkaddgaussiannoise_GGO_C})
target_link_libraries(rtkaddgaussiannoise RTK)

# Installation code
if(NOT RTK_INSTALL_NO_EXECUTABLES)
foreach(EXE_NAME rtkaddgaussiannoise)
install(TARGETS ${EXE_NAME}
RUNTIME DESTINATION ${RTK_INSTALL_RUNTIME_DIR} COMPONENT Runtime
LIBRARY DESTINATION ${RTK_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${RTK_INSTALL_ARCHIVE_DIR} COMPONENT Development)
endforeach()
endif()
Empty file.
58 changes: 58 additions & 0 deletions applications/rtkaddgaussiannoise/rtkaddgaussiannoise.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*=========================================================================
*
* Copyright RTK Consortium
*
* 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.txt
*
* 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.
*
*=========================================================================*/

#include "rtkaddgaussiannoise_ggo.h"
#include "rtkGgoFunctions.h"
#include "rtkConfiguration.h"

#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>

#include "rtkProjectionsReader.h"
#include "rtkConstantImageSource.h"
#include "rtkAdditiveGaussianNoiseImageFilter.h"

int
main(int argc, char * argv[])
{
GGO(rtkaddgaussiannoise, args_info);

using OutputPixelType = float;
constexpr unsigned int Dimension = 3;

#ifdef RTK_USE_CUDA
using ImageType = itk::CudaImage<OutputPixelType, Dimension>;
#else
using ImageType = itk::Image<OutputPixelType, Dimension>;
#endif

auto reader = itk::ImageFileReader<ImageType>::New();
reader->SetFileName(args_info.input_arg);

// Add noise
auto noisy = rtk::AdditiveGaussianNoiseImageFilter<ImageType>::New();
noisy->SetInput(reader->GetOutput());
noisy->SetMean(args_info.mean_arg);
noisy->SetStandardDeviation(args_info.sigma_arg);
TRY_AND_EXIT_ON_ITK_EXCEPTION(noisy->Update())

// Write
TRY_AND_EXIT_ON_ITK_EXCEPTION(itk::WriteImage(noisy->GetOutput(), args_info.output_arg))

return EXIT_SUCCESS;
}
7 changes: 7 additions & 0 deletions applications/rtkaddgaussiannoise/rtkaddgaussiannoise.ggo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
purpose "Add Gaussian noise to analytic projections. By default, mean=0., std=1."

option "verbose" v "Verbose execution" flag off
option "input" i "Input file name" string yes
option "output" o "Output file name" string
option "mean" m "Noise level (mean)" float no default="0.0"
option "sigma" s "Noise standard deviation (std)" float no default="1.0"
13 changes: 13 additions & 0 deletions applications/rtkaddpoissonnoise/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WRAP_GGO(rtkaddpoissonnoise_GGO_C rtkaddpoissonnoise.ggo ${RTK_BINARY_DIR}/rtkVersion.ggo)
add_executable(rtkaddpoissonnoise rtkaddpoissonnoise.cxx ${rtkaddpoissonnoise_GGO_C})
target_link_libraries(rtkaddpoissonnoise RTK)

# Installation code
if(NOT RTK_INSTALL_NO_EXECUTABLES)
foreach(EXE_NAME rtkaddpoissonnoise)
install(TARGETS ${EXE_NAME}
RUNTIME DESTINATION ${RTK_INSTALL_RUNTIME_DIR} COMPONENT Runtime
LIBRARY DESTINATION ${RTK_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${RTK_INSTALL_ARCHIVE_DIR} COMPONENT Development)
endforeach()
endif()
Empty file.
81 changes: 81 additions & 0 deletions applications/rtkaddpoissonnoise/rtkaddpoissonnoise.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*=========================================================================
*
* Copyright RTK Consortium
*
* 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.txt
*
* 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.
*
*=========================================================================*/
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkMultiplyImageFilter.h>
#include <itkExpImageFilter.h>
#include <itkShotNoiseImageFilter.h>
#include <itkThresholdImageFilter.h>
#include <itkLogImageFilter.h>

#include "rtkaddpoissonnoise_ggo.h"
#include "rtkGgoFunctions.h"
#include "rtkConfiguration.h"

int
main(int argc, char * argv[])
{
GGO(rtkaddpoissonnoise, args_info);

using OutputPixelType = float;
constexpr unsigned int Dimension = 3;

#ifdef RTK_USE_CUDA
using ImageType = itk::CudaImage<OutputPixelType, Dimension>;
#else
using ImageType = itk::Image<OutputPixelType, Dimension>;
#endif

auto reader = itk::ImageFileReader<ImageType>::New();
reader->SetFileName(args_info.input_arg);

// Use ITK to add pre-log Poisson noise
auto multiply = itk::MultiplyImageFilter<ImageType>::New();
multiply->SetInput(reader->GetOutput());
multiply->SetConstant(-args_info.muref_arg);

auto exp = itk::ExpImageFilter<ImageType, ImageType>::New();
exp->SetInput(multiply->GetOutput());

auto multiply2 = itk::MultiplyImageFilter<ImageType>::New();
multiply2->SetInput(exp->GetOutput());
multiply2->SetConstant(args_info.I0_arg);

auto poisson = itk::ShotNoiseImageFilter<ImageType>::New();
poisson->SetInput(multiply2->GetOutput());

auto threshold = itk::ThresholdImageFilter<ImageType>::New();
threshold->SetInput(poisson->GetOutput());
threshold->SetLower(1.);
threshold->SetOutsideValue(1.);

auto multiply3 = itk::MultiplyImageFilter<ImageType>::New();
multiply3->SetInput(threshold->GetOutput());
multiply3->SetConstant(1. / args_info.I0_arg);

auto log = itk::LogImageFilter<ImageType, ImageType>::New();
log->SetInput(multiply3->GetOutput());

auto multiply4 = itk::MultiplyImageFilter<ImageType>::New();
multiply4->SetInput(log->GetOutput());
multiply4->SetConstant(-1. / args_info.muref_arg);

itk::WriteImage(multiply4->GetOutput(), args_info.output_arg);

return EXIT_SUCCESS;
}
7 changes: 7 additions & 0 deletions applications/rtkaddpoissonnoise/rtkaddpoissonnoise.ggo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
purpose "Add Poisson noise to analytic projections. It estimates the number of photons by applying Beer-Lambert law with the linear attenuation coefficient of Liquid Water at 75keV and then apply a Poisson distribution on that."

option "verbose" v "Verbose execution" flag off
option "input" i "Input file name" string yes
option "output" o "Output file name" string yes
option "I0" - "Number of impinging photons per pixel." int no
option "muref" - "Reference Linear attenuation coeff. Default: 0.01879" float no default="0.01879"
Loading