forked from RTKConsortium/RTK
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: First simple test for iteration reporting
- Loading branch information
Showing
6 changed files
with
154 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
WRAP_GGO(rtkcheckimagequality_GGO_C rtkcheckimagequality.ggo ${RTK_BINARY_DIR}/rtkVersion.ggo) | ||
add_executable(rtkcheckimagequality rtkcheckimagequality.cxx ${rtkcheckimagequality_GGO_C}) | ||
target_link_libraries(rtkcheckimagequality RTK) | ||
|
||
# Installation code | ||
if(NOT RTK_INSTALL_NO_EXECUTABLES) | ||
foreach(EXE_NAME rtkcheckimagequality) | ||
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() | ||
|
117 changes: 117 additions & 0 deletions
117
applications/rtkcheckimagequality/rtkcheckimagequality.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "rtkcheckimagequality_ggo.h" | ||
#include "rtkConfiguration.h" | ||
#include "rtkMacro.h" | ||
#include "itkImage.h" | ||
#include "itkImageFileReader.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
/** | ||
* \file rtkcheckimagequality.cxx | ||
* | ||
* \brief Checks that an image has a satisfactory MSE against a reference. | ||
* | ||
* \author Aurélien Coussat | ||
*/ | ||
|
||
template <class TImage> | ||
double | ||
MSE(typename TImage::Pointer reference, typename TImage::Pointer reconstruction) | ||
{ | ||
using ImageIteratorType = itk::ImageRegionConstIterator<TImage>; | ||
ImageIteratorType itTest(reconstruction, reconstruction->GetBufferedRegion()); | ||
ImageIteratorType itRef(reference, reference->GetBufferedRegion()); | ||
|
||
using ErrorType = double; | ||
ErrorType EnerError = 0.; | ||
|
||
itTest.GoToBegin(); | ||
itRef.GoToBegin(); | ||
|
||
while (!itRef.IsAtEnd()) | ||
{ | ||
typename TImage::PixelType TestVal = itTest.Get(); | ||
typename TImage::PixelType RefVal = itRef.Get(); | ||
EnerError += std::pow(ErrorType(RefVal - TestVal), 2.); | ||
++itTest; | ||
++itRef; | ||
} | ||
|
||
return EnerError; | ||
} | ||
|
||
int | ||
main(int argc, char ** argv) | ||
{ | ||
|
||
args_info_rtkcheckimagequality args_info; | ||
cmdline_parser_rtkcheckimagequality_params args_params; | ||
cmdline_parser_rtkcheckimagequality_params_init(&args_params); | ||
args_params.print_errors = 1; | ||
args_params.check_required = 1; | ||
args_params.override = 1; | ||
args_params.initialize = 1; | ||
if (0 != cmdline_parser_rtkcheckimagequality_ext(argc, argv, &args_info, &args_params)) | ||
{ | ||
std::cerr << "Error in cmdline_parser_rtkcheckimagequality_ext" << std::endl; | ||
exit(1); | ||
} | ||
|
||
constexpr unsigned int Dimension = 3; | ||
using PixelType = float; | ||
using ImageType = itk::Image<PixelType, Dimension>; | ||
|
||
using ReaderType = itk::ImageFileReader<ImageType>; | ||
ReaderType::Pointer reader; | ||
|
||
// Maximum number of comparisons to perform (depends on the number of inputs) | ||
unsigned int n_max = | ||
std::max({ args_info.reference_given, args_info.reconstruction_given, args_info.threshold_given }); | ||
|
||
for (unsigned int i = 0; i < n_max; i++) | ||
{ | ||
unsigned int reference_index = std::min(args_info.reference_given - 1, i); | ||
unsigned int reconstruction_index = std::min(args_info.reconstruction_given - 1, i); | ||
unsigned int threshold_index = std::min(args_info.threshold_given - 1, i); | ||
|
||
reader = ReaderType::New(); | ||
reader->SetFileName(args_info.reference_arg[reference_index]); | ||
|
||
try | ||
{ | ||
reader->Update(); | ||
} | ||
catch (::itk::ExceptionObject & e) | ||
{ | ||
std::cerr << e.GetDescription(); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ImageType::Pointer reference = reader->GetOutput(); | ||
|
||
reader = ReaderType::New(); | ||
reader->SetFileName(args_info.reconstruction_arg[reconstruction_index]); | ||
|
||
try | ||
{ | ||
reader->Update(); | ||
} | ||
catch (::itk::ExceptionObject & e) | ||
{ | ||
std::cerr << e.GetDescription(); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ImageType::Pointer reconstruction = reader->GetOutput(); | ||
|
||
double mse = MSE<ImageType>(reference, reconstruction); | ||
|
||
if (mse > args_info.threshold_arg[threshold_index]) | ||
{ | ||
std::cerr << "Error comparing " << args_info.reference_arg[reference_index] << " and " | ||
<< args_info.reconstruction_arg[reconstruction_index] << ":" << std::endl | ||
<< "MSE " << mse << " above given threshold " << args_info.threshold_arg[threshold_index] << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package "rtkcheckimagequality" | ||
purpose "Checks the MSE of a reconstructed image against a reference." | ||
|
||
option "reference" i "Reference volume" string multiple yes | ||
option "reconstruction" j "Reconstructed volume" string multiple yes | ||
option "threshold" t "MSE threshold" int multiple yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.