Skip to content

Commit

Permalink
Merge pull request InsightSoftwareConsortium#5205 from jhlegarreta/Mi…
Browse files Browse the repository at this point in the history
…scImageComposeTestStyleEnh

STYLE: Miscellaneous `ImageCompose` test style enhancements
  • Loading branch information
jhlegarreta authored Feb 2, 2025
2 parents 68c0581 + 5042dc9 commit ed1eaec
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkComposeImageFilter.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int
itkCompose2DCovariantVectorImageFilterTest(int, char *[])
Expand Down Expand Up @@ -63,17 +64,7 @@ itkCompose2DCovariantVectorImageFilterTest(int, char *[])
filter->SetInput1(zeroImage);
filter->SetInput2(oneImage);

try
{
filter->Update();
}

catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

using OutputImageType = FilterType::OutputImageType;

Expand Down Expand Up @@ -112,7 +103,6 @@ itkCompose2DCovariantVectorImageFilterTest(int, char *[])
++i1;
}

std::cout << "Test Passed !" << std::endl;

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkComposeImageFilter.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int
itkCompose2DVectorImageFilterTest(int, char *[])
Expand Down Expand Up @@ -63,16 +64,7 @@ itkCompose2DVectorImageFilterTest(int, char *[])
filter->SetInput1(zeroImage);
filter->SetInput2(oneImage);

try
{
filter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

using OutputImageType = FilterType::OutputImageType;

Expand Down Expand Up @@ -111,7 +103,6 @@ itkCompose2DVectorImageFilterTest(int, char *[])
++i1;
}

std::cout << "Test Passed !" << std::endl;

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkComposeImageFilter.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int
itkCompose3DCovariantVectorImageFilterTest(int, char *[])
Expand Down Expand Up @@ -69,17 +70,7 @@ itkCompose3DCovariantVectorImageFilterTest(int, char *[])
filter->SetInput2(oneImage);
filter->SetInput3(twoImage);

try
{
filter->Update();
}

catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

using OutputImageType = FilterType::OutputImageType;

Expand Down Expand Up @@ -126,7 +117,6 @@ itkCompose3DCovariantVectorImageFilterTest(int, char *[])
++i2;
}

std::cout << "Test Passed !" << std::endl;

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkComposeImageFilter.h"
#include "itkMath.h"
#include "itkTestingMacros.h"

int
itkCompose3DVectorImageFilterTest(int, char *[])
Expand Down Expand Up @@ -68,16 +69,7 @@ itkCompose3DVectorImageFilterTest(int, char *[])
filter->SetInput2(oneImage);
filter->SetInput3(twoImage);

try
{
filter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

using OutputImageType = FilterType::OutputImageType;

Expand Down Expand Up @@ -124,7 +116,6 @@ itkCompose3DVectorImageFilterTest(int, char *[])
++i2;
}

std::cout << "Test Passed !" << std::endl;

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
106 changes: 45 additions & 61 deletions Modules/Filtering/ImageCompose/test/itkComposeRGBAImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,80 +31,64 @@ itkComposeRGBAImageFilterTest(int argc, char * argv[])

if (argc < 6)
{
std::cerr << "Error: missing arguments" << std::endl;
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << itkNameOfTestExecutableMacro(argv) << " outputFile inputFileR inputFileG inputFileB inputFileA"
<< std::endl;
}

try
{
// ARGUMENTS:
// argv[0] = Executable name
// argv[1] = Output file name and path
// argv[2] = Input 1 file name and path
// argv[2] = Input 2 file name and path
// argv[2] = Input 3 file name and path
// argv[2] = Input 4 file name and path
// Get arguments
char * OutputFilename = argv[1];
char * Input1Filename = argv[2];
char * Input2Filename = argv[3];
char * Input3Filename = argv[4];
char * Input4Filename = argv[5];

// Get arguments
char * OutputFilename = argv[1];
char * Input1Filename = argv[2];
char * Input2Filename = argv[3];
char * Input3Filename = argv[4];
char * Input4Filename = argv[5];
// Typedefs
using ScalarPixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using RGBAPixelType = itk::RGBAPixel<ScalarPixelType>;
using ScalarImageType = itk::Image<ScalarPixelType, Dimension>;
using RGBAImageType = itk::Image<RGBAPixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ScalarImageType>;
using WriterType = itk::ImageFileWriter<RGBAImageType>;
using ComposeFilterType = itk::ComposeImageFilter<ScalarImageType, RGBAImageType>;

// Typedefs
using ScalarPixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using RGBAPixelType = itk::RGBAPixel<ScalarPixelType>;
using ScalarImageType = itk::Image<ScalarPixelType, Dimension>;
using RGBAImageType = itk::Image<RGBAPixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ScalarImageType>;
using WriterType = itk::ImageFileWriter<RGBAImageType>;
using ComposeFilterType = itk::ComposeImageFilter<ScalarImageType, RGBAImageType>;
// Read input1
auto reader1 = ReaderType::New();
reader1->SetFileName(Input1Filename);
reader1->Update();

// Read input1
auto reader1 = ReaderType::New();
reader1->SetFileName(Input1Filename);
reader1->Update();
// Read input2
auto reader2 = ReaderType::New();
reader2->SetFileName(Input2Filename);
reader2->Update();

// Read input2
auto reader2 = ReaderType::New();
reader2->SetFileName(Input2Filename);
reader2->Update();
// Read input3
auto reader3 = ReaderType::New();
reader3->SetFileName(Input3Filename);
reader3->Update();

// Read input3
auto reader3 = ReaderType::New();
reader3->SetFileName(Input3Filename);
reader3->Update();
// Read input4
auto reader4 = ReaderType::New();
reader4->SetFileName(Input4Filename);
reader4->Update();

// Read input4
auto reader4 = ReaderType::New();
reader4->SetFileName(Input4Filename);
reader4->Update();
// Test ComposeRGBA filter
auto filterCompose = ComposeFilterType::New();
filterCompose->SetInput(0, reader1->GetOutput());
filterCompose->SetInput(1, reader2->GetOutput());
filterCompose->SetInput(2, reader3->GetOutput());
filterCompose->SetInput(3, reader4->GetOutput());

// Test ComposeRGBA filter
auto filterCompose = ComposeFilterType::New();
filterCompose->SetInput(0, reader1->GetOutput());
filterCompose->SetInput(1, reader2->GetOutput());
filterCompose->SetInput(2, reader3->GetOutput());
filterCompose->SetInput(3, reader4->GetOutput());
filterCompose->Update();
ITK_TRY_EXPECT_NO_EXCEPTION(filterCompose->Update());

// Write output
auto writer = WriterType::New();
writer->SetFileName(OutputFilename);
writer->SetInput(filterCompose->GetOutput());
writer->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
// Write output
auto writer = WriterType::New();
writer->SetFileName(OutputFilename);
writer->SetInput(filterCompose->GetOutput());
writer->Update();

// Return
std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include "itkRGBPixel.h"
#include "itkComposeImageFilter.h"
#include "itkTestingMacros.h"

int
itkComposeRGBImageFilterTest(int, char *[])
Expand Down Expand Up @@ -69,17 +70,7 @@ itkComposeRGBImageFilterTest(int, char *[])
filter->SetInput2(greenImage);
filter->SetInput3(blueImage);

try
{
filter->Update();
}

catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

const OutputImageType::Pointer rgbImage = filter->GetOutput();

Expand Down Expand Up @@ -124,7 +115,6 @@ itkComposeRGBImageFilterTest(int, char *[])
++ib;
}

std::cout << "Test Passed !" << std::endl;

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ itkImageReadRealAndImaginaryWriteComplexTest(int argc, char * argv[])
{
if (argc != 4)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " inputReal inputImaginary outputComplex"
<< std::endl;
return EXIT_FAILURE;
Expand All @@ -60,7 +61,7 @@ itkImageReadRealAndImaginaryWriteComplexTest(int argc, char * argv[])
auto readerImag = ReaderType::New();
auto writer = WriterType::New();

auto RealAndImaginary2Complex = RealAndImaginary2ComplexFilterType::New();
auto realAndImaginary2Complex = RealAndImaginary2ComplexFilterType::New();

readerReal->SetFileName(argv[1]);
readerImag->SetFileName(argv[2]);
Expand All @@ -70,21 +71,13 @@ itkImageReadRealAndImaginaryWriteComplexTest(int argc, char * argv[])
readerReal->Update();
readerImag->Update();

RealAndImaginary2Complex->SetInput1(readerReal->GetOutput());
RealAndImaginary2Complex->SetInput2(readerImag->GetOutput());
realAndImaginary2Complex->SetInput1(readerReal->GetOutput());
realAndImaginary2Complex->SetInput2(readerImag->GetOutput());

writer->SetInput(RealAndImaginary2Complex->GetOutput());
ITK_TRY_EXPECT_NO_EXCEPTION(realAndImaginary2Complex->Update());

try
{
writer->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error writing the magnitude image: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
writer->SetInput(realAndImaginary2Complex->GetOutput());
writer->Update();

// check that the default template parameters work
using DefaultParametersFilterType = itk::ComposeImageFilter<InputImageType>;
Expand All @@ -93,5 +86,7 @@ itkImageReadRealAndImaginaryWriteComplexTest(int argc, char * argv[])
{
return EXIT_FAILURE;
}

std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Loading

0 comments on commit ed1eaec

Please sign in to comment.