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

BUG: GenerateImageSource sets Size from ReferenceImage #5088

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ GenerateImageSource<TOutputImage>::GenerateOutputInformation()
outputPtr->SetSpacing(referenceImage->GetSpacing());
outputPtr->SetOrigin(referenceImage->GetOrigin());
outputPtr->SetDirection(referenceImage->GetDirection());
this->m_Direction = referenceImage->GetDirection();
this->m_StartIndex = referenceImage->GetLargestPossibleRegion().GetIndex();
this->m_Size = referenceImage->GetLargestPossibleRegion().GetSize();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bafkreidpb356aruiokudkoxyo47ol4nyesw3hywpfd4dbvigbixmcebmwe
13 changes: 13 additions & 0 deletions Modules/Filtering/ImageSources/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(ITKImageSourcesTests
itkGaborImageSourceTest.cxx
itkGaussianImageSourceTest.cxx
itkGridImageSourceTest.cxx
itkGridImageSourceTest2.cxx
itkPhysicalPointImageSourceTest.cxx)

createtestdriver(ITKImageSources "${ITKImageSources-Test_LIBRARIES}" "${ITKImageSourcesTests}")
Expand Down Expand Up @@ -138,6 +139,18 @@ itk_add_test(
0
0
0)
itk_add_test(
NAME
itkGridImageSourceTest5
COMMAND
ITKImageSourcesTestDriver
--compare
DATA{Baseline/itkGridImageSourceTest5.mha}
${ITK_TEST_OUTPUT_DIR}/itkGridImageSourceTest5.mha
itkGridImageSourceTest2
DATA{${ITK_DATA_ROOT}/Input/cthead1.png}
${ITK_TEST_OUTPUT_DIR}/itkGridImageSourceTest5.mha
)
itk_add_test(
NAME
itkPhysicalPointImageSourceTest0
Expand Down
68 changes: 68 additions & 0 deletions Modules/Filtering/ImageSources/test/itkGridImageSourceTest2.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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 "itkGridImageSource.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"


int
itkGridImageSourceTest2(int argc, char * argv[])
{
if (argc != 3)
{
std::cout << "Usage: " << itkNameOfTestExecutableMacro(argv)
<< " inputImage"
<< " outputImage" << std::endl;
return EXIT_FAILURE;
}
const char * inputImageFile = argv[1];
const char * outputImageFile = argv[2];


constexpr unsigned int ImageDimension = 3;
using PixelType = uint8_t;

using ImageType = itk::Image<PixelType, ImageDimension>;

// Instantiate the filter
using GridSourceType = itk::GridImageSource<ImageType>;
auto gridImage = GridSourceType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(gridImage, GridImageSource, GenerateImageSource);

ImageType::Pointer inputImage = itk::ReadImage<ImageType>(inputImageFile);

gridImage->SetReferenceImage(inputImage);
gridImage->UseReferenceImageOn();

itk::SimpleFilterWatcher watcher(gridImage, "GridImageSource");

ITK_TRY_EXPECT_NO_EXCEPTION(gridImage->Update());

using WriterType = itk::ImageFileWriter<ImageType>;
auto writer = WriterType::New();
writer->SetFileName(outputImageFile);
writer->SetInput(gridImage->GetOutput());

ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update());

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