From f785ae9da893e948e33d0e1939227b35926f3115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Thu, 16 Sep 2021 15:47:47 -0400 Subject: [PATCH] BUG: filling the buffer was forgotten in CreateImage --- .../ClosingBinaryImage/Code.cxx | 16 ++++++++-------- .../OpeningBinaryImage/Code.cxx | 14 +++++++------- .../PruneBinaryImage/Code.cxx | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx index 5053a9037..ed377b06f 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx @@ -41,12 +41,7 @@ main(int argc, char * argv[]) unsigned int radius = 5; std::string outputFilename = "Output.png"; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -55,6 +50,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image); + } std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; @@ -98,7 +98,7 @@ main(int argc, char * argv[]) void CreateImage(ImageType * const image) { - // Create an image with 2 connected components + // Create an image with a gray square itk::Index<2> corner = { { 0, 0 } }; itk::Size<2> size; @@ -110,7 +110,7 @@ CreateImage(ImageType * const image) itk::ImageRegion<2> region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (unsigned int r = 40; r < 100; r++) diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx index 544893a02..0d9ddbadb 100644 --- a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx @@ -41,12 +41,7 @@ main(int argc, char * argv[]) unsigned int radius = 5; std::string outputFilename = "Output.png"; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -55,6 +50,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image); + } std::cout << "Radius: " << radius << std::endl; using StructuringElementType = itk::BinaryBallStructuringElement; @@ -111,7 +111,7 @@ CreateImage(ImageType * const image) itk::ImageRegion<2> region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (unsigned int r = 40; r < 100; r++) diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx index 7ccfb33e0..a06beaf11 100644 --- a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx @@ -45,12 +45,7 @@ main(int argc, char * argv[]) std::string outputFilename = "Output.png"; unsigned int iteration = 1; - if (argc == 1) - { - image = ImageType::New(); - CreateImage(image.GetPointer()); - } - else if (argc < 4) + if (argc >= 4) { image = itk::ReadImage(argv[1]); @@ -59,6 +54,11 @@ main(int argc, char * argv[]) outputFilename = argv[3]; } + else + { + image = ImageType::New(); + CreateImage(image.GetPointer()); + } std::cout << "Iterations: " << iteration << std::endl; @@ -94,7 +94,7 @@ CreateImage(TImage * const image) typename TImage::RegionType region(corner, size); image->SetRegions(region); - image->Allocate(); + image->Allocate(true); // Make a square for (int r = 40; r < 100; r++)