Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous examples fixes #136

Merged
merged 7 commits into from
Oct 29, 2019
Merged
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: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(NOT ITK_SOURCE_DIR)
else()
# when being built as part of ITK, ITKImageIO and ITKTransformIO
# lists of modules are not yet ready, causing a configure error
find_package(ITK REQUIRED COMPONENTS Montage ITKIOTransformInsightLegacy ITKIOHDF5 ITKTestKernel ${ExampleSpecificComponents})
find_package(ITK REQUIRED COMPONENTS Montage ITKIOTransformInsightLegacy ITKIONRRD ITKIOPNG ITKTestKernel ${ExampleSpecificComponents})
endif()
include(${ITK_USE_FILE})

Expand Down
27 changes: 12 additions & 15 deletions examples/CompleteMontage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ denoiseImage(typename itk::Image<PixelType, Dimension>::Pointer image, double si
{
using ImageType = itk::Image<PixelType, Dimension>;
using DensoingType = itk::BilateralImageFilter<ImageType, ImageType>;
DensoingType::Pointer denoiser = DensoingType::New();
typename DensoingType::Pointer denoiser = DensoingType::New();
denoiser->SetInput(image);
denoiser->SetRangeSigma(itk::NumericTraits<PixelType>::max() / 20.0);
denoiser->SetDomainSigma(sigma);
Expand All @@ -110,9 +110,9 @@ denoiseImage(typename itk::Image<PixelType, Dimension>::Pointer image, double si
using DensoingType = itk::BilateralImageFilter<ScalarImageType, ScalarImageType>;
using ComposeType = itk::ComposeImageFilter<ScalarImageType, ColorImageType>;

ImageAdaptorType::Pointer cAdaptor = ImageAdaptorType::New();
typename ImageAdaptorType::Pointer cAdaptor = ImageAdaptorType::New();
cAdaptor->SetInput(image);
DensoingType::Pointer denoiser = DensoingType::New();
typename DensoingType::Pointer denoiser = DensoingType::New();
denoiser->SetInput(cAdaptor->GetOutput());
denoiser->SetRangeSigma(itk::NumericTraits<ComponentType>::max() / 20.0);
denoiser->SetDomainSigma(sigma);
Expand All @@ -127,7 +127,7 @@ denoiseImage(typename itk::Image<PixelType, Dimension>::Pointer image, double si
}

// compose an RGB(A) image from the filtered component images
ComposeType::Pointer compose = ComposeType::New();
typename ComposeType::Pointer compose = ComposeType::New();
for (unsigned c = 0; c < PixelType::Length; c++)
{
compose->SetInput(c, cImages[c]);
Expand All @@ -152,7 +152,7 @@ class CommandIterationUpdate : public itk::Command
void
Execute(itk::Object * caller, const itk::EventObject & event) override
{
Execute((const itk::Object *)caller, event);
Execute(static_cast<const itk::Object *>(caller), event);
}

void
Expand All @@ -165,7 +165,7 @@ class CommandIterationUpdate : public itk::Command
return;
}

std::cout << '.' << std::flush; // minimal progress feedback
std::cout << ' ' << filter->GetElapsedIterations() << std::flush;
}
};

Expand All @@ -190,9 +190,9 @@ GetLogBiasField(typename itk::Image<PixelType, Dimension>::Pointer scalarImage,
using CorrecterType = itk::N4BiasFieldCorrectionImageFilter<RealImageType>;
typename CorrecterType::Pointer correcter = CorrecterType::New();
correcter->SetSplineOrder(splineOrder);
correcter->SetWienerFilterNoise(0.01);
correcter->SetBiasFieldFullWidthAtHalfMaximum(0.15);
correcter->SetConvergenceThreshold(0.00001);
correcter->SetWienerFilterNoise(0.01f);
correcter->SetBiasFieldFullWidthAtHalfMaximum(0.15f);
correcter->SetConvergenceThreshold(0.00001f);

typename CorrecterType::VariableSizeArrayType maximumNumberOfIterations(
static_cast<typename CorrecterType::VariableSizeArrayType::SizeValueType>(iterations.size()));
Expand All @@ -203,8 +203,7 @@ GetLogBiasField(typename itk::Image<PixelType, Dimension>::Pointer scalarImage,
correcter->SetMaximumNumberOfIterations(maximumNumberOfIterations);

typename CorrecterType::ArrayType numberOfFittingLevels;
numberOfFittingLevels.Fill(
static_cast<typename CorrecterType::VariableSizeArrayType::SizeValueType>(iterations.size()));
numberOfFittingLevels.Fill(iterations.size());
correcter->SetNumberOfFittingLevels(numberOfFittingLevels);

typename CorrecterType::ArrayType numberOfControlPoints;
Expand Down Expand Up @@ -323,8 +322,6 @@ CorrectBias(typename itk::Image<PixelType, Dimension>::Pointer image,
mt->ParallelizeImageRegion<Dimension>(
region,
[mulField, diff](const typename ImageType::RegionType & subRegion) {
double threadSum = 0.0;

itk::ImageRegionIterator<RealImageType> ItM(mulField, subRegion);
for (ItM.GoToBegin(); !ItM.IsAtEnd(); ++ItM)
{
Expand Down Expand Up @@ -471,8 +468,8 @@ completeMontage(const itk::TileConfiguration<Dimension> & stageTiles,
std::cout << "Writing transform for each input tile...";
for (size_t t = 0; t < stageTiles.LinearSize(); t++)
{
typename MontageType::TileIndexType ind = stageTiles.LinearIndexToNDIndex(t);
const TransformType * regTr = montage->GetOutputTransform(ind);
ind = stageTiles.LinearIndexToNDIndex(t);
const TransformType * regTr = montage->GetOutputTransform(ind);
WriteTransform(regTr, outputPath + stageTiles.Tiles[t].FileName + ".tfm");

// set inputs to resampler class
Expand Down
5 changes: 2 additions & 3 deletions include/itkTileConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ struct ITK_TEMPLATE_EXPORT TileConfiguration
// check consistency with previously established size
for (unsigned d = 0; d < maxAxis; d++)
{
SizeValueType axisSize = (d == maxAxis - 1) ? AxisSizes[d] : AxisSizes[d] - 1;
itkAssertOrThrowMacro(cInd[d] == AxisSizes[d] - 1,
"Axis sizes: " << AxisSizes << " current index: " << cInd
<< ". We have reached the end along axis " << maxAxis
Expand Down Expand Up @@ -220,8 +219,8 @@ struct ITK_TEMPLATE_EXPORT TileConfiguration

tileFile << "# Tile coordinates are in index space, not physical space\n";
tileFile << "dim = " << Dimension << "\n\n";
char buffer[20];
double_conversion::StringBuilder conversionResult(buffer, 20);
char buffer[25];
double_conversion::StringBuilder conversionResult(buffer, 25);

size_t totalTiles = this->LinearSize();
for (SizeValueType linearIndex = 0; linearIndex < totalTiles; linearIndex++)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ endfunction()

GroundTruthTest2D(10-129 DATA{Input/10-129-C_2/10-129-C_2_p00.jpg} 6 4 15 25)
GroundTruthTest2D(run2 DATA{Input/05MAR09_run2_64-Raw/05MAR09_run2_64-Raw_p0.bmp} 4 5 15 10)
GroundTruthTest2D(MediumCarbonSteel DATA{Input/MediumCarbonSteel/1701701_000000_Fused.bmp} 11 3 20 20)
GroundTruthTest2D(MediumCarbonSteel DATA{Input/MediumCarbonSteel/1701701_000000_Fused.tif} 11 3 20 20)

itk_add_test(NAME itkMontage-10-129-C_2
COMMAND MontageTestDriver
Expand Down
36 changes: 26 additions & 10 deletions test/itkMontageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,33 @@ itkMontageTest(int argc, char * argv[])
inputPath += '/';
}

unsigned dim;
itk::TileConfiguration<2>::TryParse(inputPath + "TileConfiguration.txt", dim);
try
{
unsigned dim;
itk::TileConfiguration<2>::TryParse(inputPath + "TileConfiguration.txt", dim);

switch (dim)
switch (dim)
{
case 2:
return itkMontageTestHelper<2>(argc, argv, inputPath);
case 3:
return itkMontageTestHelper<3>(argc, argv, inputPath);
default:
std::cerr << "Only dimensions 2 and 3 are supported. You are attempting to montage dimension " << dim;
return EXIT_FAILURE;
}
}
catch (itk::ExceptionObject & exc)
{
std::cerr << exc;
}
catch (std::runtime_error & exc)
{
std::cerr << exc.what();
}
catch (...)
{
case 2:
return itkMontageTestHelper<2>(argc, argv, inputPath);
case 3:
return itkMontageTestHelper<3>(argc, argv, inputPath);
default:
std::cerr << "Only dimensions 2 and 3 are supported. You are attempting to montage dimension " << dim;
return EXIT_FAILURE;
std::cerr << "Unknown error has occurred" << std::endl;
}
return EXIT_FAILURE;
}
47 changes: 31 additions & 16 deletions test/itkMontageTruthCreator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -196,28 +196,43 @@ itkMontageTruthCreator(int argc, char * argv[])
return EXIT_FAILURE;
}

itk::ImageIOBase::Pointer imageIO =
itk::ImageIOFactory::CreateImageIO(argv[1], itk::ImageIOFactory::FileModeType::ReadMode);
imageIO->SetFileName(argv[1]);
imageIO->ReadImageInformation();
unsigned dim = imageIO->GetNumberOfDimensions();
const itk::ImageIOBase::IOComponentType cType = imageIO->GetComponentType();

if (cType == itk::ImageIOBase::IOComponentType::UCHAR)
try
{
return CreateGroundTruth<unsigned char>(argc, argv, dim, imageIO->GetPixelType());
itk::ImageIOBase::Pointer imageIO =
itk::ImageIOFactory::CreateImageIO(argv[1], itk::ImageIOFactory::FileModeType::ReadMode);
imageIO->SetFileName(argv[1]);
imageIO->ReadImageInformation();
unsigned dim = imageIO->GetNumberOfDimensions();
const itk::ImageIOBase::IOComponentType cType = imageIO->GetComponentType();

if (cType == itk::ImageIOBase::IOComponentType::UCHAR)
{
return CreateGroundTruth<unsigned char>(argc, argv, dim, imageIO->GetPixelType());
}
else if (cType == itk::ImageIOBase::IOComponentType::USHORT)
{
return CreateGroundTruth<unsigned short>(argc, argv, dim, imageIO->GetPixelType());
}
else if (cType == itk::ImageIOBase::IOComponentType::SHORT)
{
return CreateGroundTruth<short>(argc, argv, dim, imageIO->GetPixelType());
}
else
{
std::cerr << "Unsupported component type: " << itk::ImageIOBase::GetComponentTypeAsString(cType) << std::endl;
}
}
else if (cType == itk::ImageIOBase::IOComponentType::USHORT)
catch (itk::ExceptionObject & exc)
{
return CreateGroundTruth<unsigned short>(argc, argv, dim, imageIO->GetPixelType());
std::cerr << exc;
}
else if (cType == itk::ImageIOBase::IOComponentType::SHORT)
catch (std::runtime_error & exc)
{
return CreateGroundTruth<short>(argc, argv, dim, imageIO->GetPixelType());
std::cerr << exc.what();
}
else
catch (...)
{
std::cerr << "Unsupported component type: " << itk::ImageIOBase::GetComponentTypeAsString(cType) << std::endl;
return EXIT_FAILURE;
std::cerr << "Unknown error has occurred" << std::endl;
}
return EXIT_FAILURE;
}