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

ENH: Check for initialization after image allocation. #1702

Merged
merged 1 commit into from
Mar 19, 2024
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/ComputeSimilarityMetric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ComputeSimilarityMetric(int argc, char * argv[])
field->SetLargestPossibleRegion( image1->GetLargestPossibleRegion() );
field->SetBufferedRegion( image1->GetLargestPossibleRegion() );
field->SetLargestPossibleRegion( image1->GetLargestPossibleRegion() );
field->Allocate();
field->AllocateInitialized();
field->SetSpacing(image1->GetSpacing());
field->SetOrigin(image1->GetOrigin());
VectorType zero;
Expand Down
2 changes: 1 addition & 1 deletion Examples/ConformalMapping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ typename ImageType::Pointer outimage = ImageType::New();
outimage->SetSpacing( bspliner->GetOutput()->GetSpacing() );
outimage->SetOrigin( bspliner->GetOutput()->GetOrigin() );
outimage->SetRegions( bspliner->GetOutput()->GetLargestPossibleRegion() );
outimage->Allocate();
outimage->AllocateInitialized();

*/
/*
Expand Down
7 changes: 1 addition & 6 deletions Examples/ConvertImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ ConvertImage(int argc, char * argv[])
{
displacementField->CopyInformation(inputImage);
displacementField->SetRegions(inputImage->GetRequestedRegion());
displacementField->Allocate();

VectorType V;
V.Fill(0.0);

displacementField->FillBuffer(V);
displacementField->AllocateInitialized();
}

itk::ImageRegionConstIterator<ComponentImageType> It(inputImage, inputImage->GetLargestPossibleRegion());
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateTiledMosaic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CreateMosaic(itk::ants::CommandLineParser * parser)
maskImage->CopyInformation(rgbImage);
maskImage->SetRegions(rgbImage->GetRequestedRegion());
maskImage->Allocate();
maskImage->FillBuffer(1);
maskImage->FillBuffer(itk::NumericTraits<typename ImageType::PixelType>::OneValue());

using ShortImageType = itk::Image<unsigned short, ImageDimension>;
using CasterType = itk::CastImageFilter<ImageType, ShortImageType>;
Expand Down
2 changes: 1 addition & 1 deletion Examples/DeNrrd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ DeNrrd(std::vector<std::string> args, std::ostream * /*out_stream = nullptr */)
OutputImageType::RegionType outRegion;
outRegion.SetSize( outSize );
outImage->SetRegions( outRegion );
outImage->Allocate();
outImage->AllocateInitialized();

OutputImageType::SpacingType spacing;
spacing[0] = reader->GetOutput()->GetSpacing()[0];
Expand Down
3 changes: 1 addition & 2 deletions Examples/ExtractSliceFromImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ ExtractSliceFromImage(int argc, char * argv[])
typename ImageType::Pointer outImage = ImageType::New();
outImage->CopyInformation(inputImage);
outImage->SetRegions(inputImage->GetLargestPossibleRegion());
outImage->Allocate();
outImage->FillBuffer(0);
outImage->AllocateInitialized();

// paste image slice to higher dimensionl image
using PasteFilterType = itk::PasteImageFilter<ImageType>;
Expand Down
3 changes: 1 addition & 2 deletions Examples/GetConnectedComponentsFeatureImages.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ GetConnectedComponentsFeatureImages(int itkNotUsed(argc), char * argv[])
typename RealImageType::Pointer output = RealImageType::New();
output->CopyInformation(inputImage);
output->SetRegions(inputImage->GetRequestedRegion());
output->Allocate();
output->FillBuffer(0.0);
output->AllocateInitialized();

outputImages.push_back(output);
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/ImageIntensityStatistics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ImageIntensityStatistics(int argc, char * argv[])
labelImage->CopyInformation(intensityImage);
labelImage->SetRegions(intensityImage->GetLargestPossibleRegion());
labelImage->Allocate();
labelImage->FillBuffer(1);
labelImage->FillBuffer(itk::NumericTraits<LabelType>::One);
}

std::vector<LabelType> labels;
Expand Down
67 changes: 25 additions & 42 deletions Examples/ImageMath_Templates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ CoordinateComponentImages(int argc, char * argv[])
coordinateImages[d] = ImageType::New();
coordinateImages[d]->CopyInformation(domainImage);
coordinateImages[d]->SetRegions(domainImage->GetRequestedRegion());
coordinateImages[d]->Allocate();
coordinateImages[d]->AllocateInitialized();
}

itk::ImageRegionIteratorWithIndex<ImageType> It(domainImage, domainImage->GetRequestedRegion());
Expand Down Expand Up @@ -2541,7 +2541,7 @@ TimeSeriesAssemble(int argc, char * argv[])
outimage->SetSpacing(outSpacing);
outimage->SetOrigin(outOrigin);
outimage->SetDirection(outDirection);
outimage->Allocate();
outimage->AllocateInitialized();
}

ImageIt it(image1, image1->GetLargestPossibleRegion());
Expand Down Expand Up @@ -3082,8 +3082,7 @@ TimeSeriesRegionSCCA(int argc, char * argv[])
region.SetSize(0, nLabels);
region.SetSize(1, nLabels);
connmat->SetRegions(region);
connmat->Allocate();
connmat->FillBuffer(0);
connmat->AllocateInitialized();

// Coorelation parameters
bool robust = false;
Expand Down Expand Up @@ -3251,7 +3250,7 @@ TimeSeriesRegionCorr(int argc, char * argv[])
region.SetSize(1, nLabels);
connmat->SetRegions(region);
connmat->Allocate();
connmat->FillBuffer(-1);
connmat->FillBuffer(-itk::NumericTraits<typename InputImageType::PixelType>::OneValue());

MatrixType timeSig(nLabels, nTimes, 0.0);
for (unsigned int i = 0; i < nLabels; i++)
Expand Down Expand Up @@ -5035,7 +5034,7 @@ StackImage(int argc, char * argv[])
stackImage->SetDirection(refDirection);
stackImage->SetOrigin(refOrigin);
stackImage->SetSpacing(refSpacing);
stackImage->Allocate();
stackImage->AllocateInitialized();

unsigned int offset = 0;
while (argc > argct)
Expand Down Expand Up @@ -6884,7 +6883,7 @@ CompareHeadersAndImages(int argc, char * argv[])
// varimage->SetLargestPossibleRegion( image->GetLargestPossibleRegion() );
// varimage->SetBufferedRegion( image->GetLargestPossibleRegion() );
// varimage->SetLargestPossibleRegion( image->GetLargestPossibleRegion() );
// varimage->Allocate();
// varimage->AllocateInitialized();
// varimage->SetSpacing(image->GetSpacing());
// varimage->SetOrigin(image->GetOrigin());
// varimage->SetDirection(image->GetDirection());
Expand Down Expand Up @@ -6981,7 +6980,7 @@ CompareHeadersAndImages(int argc, char * argv[])
// varimage->SetSpacing(image->GetSpacing());
// varimage->SetOrigin(image->GetOrigin());
// varimage->SetDirection(image->GetDirection());
// varimage->Allocate();
// varimage->AllocateInitialized();
//
// std::vector<double> estimatedVar(nclasses,0);
// std::vector<double> estimatedCounts(nclasses,0);
Expand Down Expand Up @@ -7026,13 +7025,13 @@ CompareHeadersAndImages(int argc, char * argv[])
// InputImageType,LabelType,
// PosteriorType,PriorType > ClassifierFilterType;
//
// typename InputImageType::Pointer vecImage = InputImageType::New();
// typename InputImageType::Pointer vecImage = InputImageType::New();A
// typedef typename InputImageType::PixelType VecPixelType;
// vecImage->SetSpacing(image->GetSpacing());
// vecImage->SetOrigin(image->GetOrigin());
// vecImage->SetRegions( image->GetLargestPossibleRegion() );
// vecImage->SetVectorLength(nclasses);
// vecImage->Allocate();
// vecImage->AllocateInitialized();
// VecPixelType vvv(nclasses);
// vvv.Fill(0);
// vecImage->FillBuffer(vvv);
Expand Down Expand Up @@ -7107,7 +7106,7 @@ CompareHeadersAndImages(int argc, char * argv[])
// priors->SetDirection(image->GetDirection());
// priors->SetRegions( image->GetLargestPossibleRegion() );
// priors->SetVectorLength(nclasses);
// priors->Allocate();
// priors->AllocateInitialized();
// // std::cout <<" Allocated " << std::endl;
//
// for( vfIter2.GoToBegin(); !vfIter2.IsAtEnd(); ++vfIter2 )
Expand Down Expand Up @@ -7312,10 +7311,7 @@ NegativeImage(int /*argc */, char * argv[])
// vecImage->SetOrigin(image->GetOrigin());
// vecImage->SetLargestPossibleRegion( image->GetLargestPossibleRegion() );
// vecImage->SetBufferedRegion( image->GetLargestPossibleRegion() );
// vecImage->Allocate();
// VecPixelType vvv;
// vvv.Fill(0);
// vecImage->FillBuffer(vvv);
// vecImage->AllocateInitialized();
//
// // setup the iterators
// // typedef VecImageType::PixelType::VectorType VecPixelType;
Expand Down Expand Up @@ -7657,10 +7653,7 @@ itkMRIBiasFieldCorrectionFilter(typename TImage::Pointer image,
// vecImage->SetOrigin(image->GetOrigin());
// vecImage->SetLargestPossibleRegion( image->GetLargestPossibleRegion() );
// vecImage->SetBufferedRegion( image->GetLargestPossibleRegion() );
// vecImage->Allocate();
// VecPixelType vvv;
// vvv.Fill(0);
// vecImage->FillBuffer(vvv);
// vecImage->AllocateInitialized();
//
// // setup the iterators
// // typedef VecImageType::PixelType::VectorType VecPixelType;
Expand Down Expand Up @@ -9324,8 +9317,7 @@ ReplaceVoxelValue(int argc, char * argv[])
typename ImageType::Pointer outputImage = ImageType::New();
outputImage->CopyInformation(inputImage);
outputImage->SetRegions(inputImage->GetRequestedRegion());
outputImage->Allocate();
outputImage->FillBuffer(0);
outputImage->AllocateInitialized();

typename itk::ImageRegionIterator<ImageType> ItI(inputImage, inputImage->GetRequestedRegion());
typename itk::ImageRegionIterator<ImageType> ItO(outputImage, outputImage->GetRequestedRegion());
Expand Down Expand Up @@ -10353,14 +10345,12 @@ ReplicateDisplacement(int argc, char * argv[])
outputImage->SetSpacing(outSpacing);
outputImage->SetOrigin(outOrigin);
outputImage->SetDirection(outDirection);
outputImage->Allocate();
VectorRType vec;
vec.Fill(0);
outputImage->FillBuffer(vec);
outputImage->AllocateInitialized();
// perform the replication
typename VectorImageType::IndexType ind;
typename VectorRImageType::IndexType indp1;
Iterator It1(vecimage1, vecimage1->GetLargestPossibleRegion());
typename VectorRImageType::PixelType vec;
for (It1.GoToBegin(); !It1.IsAtEnd(); ++It1)
{
ind = It1.GetIndex();
Expand Down Expand Up @@ -10487,8 +10477,7 @@ ReplicateImage(int argc, char * argv[])
outputImage->SetSpacing(outSpacing);
outputImage->SetOrigin(outOrigin);
outputImage->SetDirection(outDirection);
outputImage->Allocate();
outputImage->FillBuffer(0);
outputImage->AllocateInitialized();
// perform the replication
typename ImageType::IndexType ind;
typename RImageType::IndexType indp1;
Expand Down Expand Up @@ -10856,8 +10845,7 @@ LabelThickness2(int argc, char * argv[])
typename RealImageType::Pointer thicknessPriorImage = RealImageType::New();
thicknessPriorImage->CopyInformation(labelImage);
thicknessPriorImage->SetRegions(labelImage->GetLargestPossibleRegion());
thicknessPriorImage->Allocate();
thicknessPriorImage->FillBuffer(0);
thicknessPriorImage->AllocateInitialized();

itk::ImageRegionIteratorWithIndex<LabelImageType> It(labelImage, labelImage->GetLargestPossibleRegion());
for (It.GoToBegin(); !It.IsAtEnd(); ++It)
Expand Down Expand Up @@ -12127,15 +12115,13 @@ MostLikely(int argc, char * argv[])
output->SetSpacing(iLabel->GetSpacing());
output->SetOrigin(iLabel->GetOrigin());
output->SetDirection(iLabel->GetDirection());
output->Allocate();
output->FillBuffer(0);
output->AllocateInitialized();

prob->SetRegions(iLabel->GetLargestPossibleRegion());
prob->SetSpacing(iLabel->GetSpacing());
prob->SetOrigin(iLabel->GetOrigin());
prob->SetDirection(iLabel->GetDirection());
prob->Allocate();
prob->FillBuffer(0);
prob->AllocateInitialized();
}

IteratorType it(output, output->GetLargestPossibleRegion());
Expand Down Expand Up @@ -12273,8 +12259,7 @@ AverageLabels(int argc, char * argv[])
img->SetDirection(images[0]->GetDirection());
img->SetOrigin(images[0]->GetOrigin());
img->SetSpacing(images[0]->GetSpacing());
img->Allocate();
outimages.push_back(img);
img->AllocateInitialized();
}
for (unsigned int i = 0; i < images.size(); i++)
{
Expand Down Expand Up @@ -13048,8 +13033,7 @@ PureTissueN4WeightMask(int argc, char * argv[])
typename ImageType::Pointer output = ImageType::New();
output->CopyInformation(images[0]);
output->SetRegions(images[0]->GetLargestPossibleRegion());
output->Allocate();
output->FillBuffer(0);
output->AllocateInitialized();

itk::ImageRegionIteratorWithIndex<ImageType> ItO(output, output->GetLargestPossibleRegion());
for (ItO.GoToBegin(); !ItO.IsAtEnd(); ++ItO)
Expand Down Expand Up @@ -13217,7 +13201,7 @@ InPaint(int argc, char * argv[])
region.SetSize(size);
region.SetIndex(start);
kernel->SetRegions(region);
kernel->Allocate();
kernel->AllocateInitialized();
kernel->SetSpacing(image1->GetSpacing());
unsigned long kernelsize = region.GetNumberOfPixels();
itk::ImageRegionIterator<ImageType> imageIterator(kernel, region);
Expand Down Expand Up @@ -13341,7 +13325,7 @@ InPaint2(int argc, char * argv[])
region.SetSize(size);
region.SetIndex(start);
kernel->SetRegions(region);
kernel->Allocate();
kernel->AllocateInitialized();
kernel->SetSpacing(image1->GetSpacing());
unsigned long kernelsize = region.GetNumberOfPixels();
itk::ImageRegionIterator<ImageType> imageIterator(kernel, region);
Expand Down Expand Up @@ -13457,8 +13441,7 @@ Check3TissueLabeling(int argc, char * argv[])
typename LabelImageType::Pointer maxPriorLabelImage = LabelImageType::New();
maxPriorLabelImage->CopyInformation(labelImage);
maxPriorLabelImage->SetRegions(labelImage->GetRequestedRegion());
maxPriorLabelImage->Allocate();
maxPriorLabelImage->FillBuffer(0);
maxPriorLabelImage->AllocateInitialized();

itk::ImageRegionIteratorWithIndex<LabelImageType> ItL(labelImage, labelImage->GetRequestedRegion());
itk::ImageRegionIterator<LabelImageType> ItM(maxPriorLabelImage, maxPriorLabelImage->GetRequestedRegion());
Expand Down Expand Up @@ -14366,7 +14349,7 @@ KinematicTensor(int argc, char * argv[])
typename TensorImageType::Pointer strain = TensorImageType::New();
strain->CopyInformation(reader->GetOutput());
strain->SetRegions(reader->GetOutput()->GetLargestPossibleRegion());
strain->Allocate();
strain->AllocateInitialized();

itk::ImageRegionIteratorWithIndex<TensorImageType> It(strain, strain->GetLargestPossibleRegion());

Expand Down
5 changes: 2 additions & 3 deletions Examples/MeasureImageSimilarity.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ MeasureImageSimilarity(itk::ants::CommandLineParser * parser)
typename DisplacementFieldType::Pointer identityField = DisplacementFieldType::New();
identityField->CopyInformation(fixedImage);
identityField->SetRegions(fixedImage->GetLargestPossibleRegion());
identityField->Allocate();
identityField->FillBuffer(zeroVector);
identityField->AllocateInitialized();

typename DisplacementFieldTransformType::Pointer identityDisplacementFieldTransform =
DisplacementFieldTransformType::New();
Expand All @@ -446,7 +445,7 @@ MeasureImageSimilarity(itk::ants::CommandLineParser * parser)
typename DisplacementFieldType::Pointer gradientField = DisplacementFieldType::New();
gradientField->CopyInformation(fixedImage);
gradientField->SetRegions(fixedImage->GetLargestPossibleRegion());
gradientField->Allocate();
gradientField->AllocateInitialized();

itk::ImageRegionIterator<DisplacementFieldType> ItG(gradientField, gradientField->GetRequestedRegion());

Expand Down
3 changes: 1 addition & 2 deletions Examples/SmoothDisplacementField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ SmoothDisplacementField(int argc, char * argv[])
rmseImage->SetDirection(field->GetDirection());
rmseImage->SetSpacing(field->GetSpacing());
rmseImage->SetRegions(field->GetLargestPossibleRegion());
rmseImage->Allocate();
rmseImage->FillBuffer(0.0);
rmseImage->AllocateInitialized();

itk::ImageRegionConstIterator<DisplacementFieldType> fieldIt(field, field->GetLargestPossibleRegion());
itk::ImageRegionConstIterator<DisplacementFieldType> smoothedFieldIt(smoothField,
Expand Down
3 changes: 1 addition & 2 deletions Examples/ThresholdImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ OtsuThreshold(int NumberOfThresholds, typename TImage::Pointer input, typename T
typename ImageType::Pointer output = ImageType::New();
output->CopyInformation(maskImage);
output->SetRegions(maskImage->GetLargestPossibleRegion());
output->Allocate();
output->FillBuffer(0);
output->AllocateInitialized();

itk::ImageRegionIterator<ImageType> ItO(output, output->GetLargestPossibleRegion());
for (unsigned int i = 0; i < thresholds.size(); i++)
Expand Down
6 changes: 2 additions & 4 deletions Examples/TimeSCCAN.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ RegionSCCA(typename NetworkType::Pointer network,
size[1] = N;
region.SetSize(size);
network->SetRegions(region);
network->Allocate();
network->FillBuffer(0.0);
network->AllocateInitialized();

unsigned int nVoxels = labels->GetLargestPossibleRegion().GetSize()[0];
unsigned int nTimes = time->GetLargestPossibleRegion().GetSize()[0];
Expand Down Expand Up @@ -311,8 +310,7 @@ RegionAveraging(typename NetworkType::Pointer network,
size[1] = N;
region.SetSize(size);
network->SetRegions(region);
network->Allocate();
network->FillBuffer(0.0);
network->AllocateInitialized();

unsigned int nVoxels = labels->GetLargestPossibleRegion().GetSize()[0];
unsigned int nTimes = time->GetLargestPossibleRegion().GetSize()[0];
Expand Down
Loading