ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/IterateImageStartingAtSeed/Code.cxx
/*=========================================================================
*
* 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 "itkImage.h"
using ImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(ImageType::Pointer image);
int
main(int /*argc*/, char * /*argv*/[])
{
auto image = ImageType::New();
CreateImage(image);
auto function = FunctionType::New();
function->SetInputImage(image);
function->ThresholdAbove(100); // we are looking to capture 255
seed[0] = 25;
seed[1] = 25;
std::vector<itk::Index<2>> seeds;
seeds.push_back(seed);
IteratorType it(image, function, seeds);
it.GoToBegin();
while (!it.IsAtEnd())
{
std::cout << it.GetIndex() << std::endl;
++it;
}
return EXIT_SUCCESS;
}
void
CreateImage(ImageType::Pointer image)
{
start.Fill(0);
size.Fill(100);
itk::ImageRegion<2> region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// The line doesn't work at the moment, because it needs 8-connectivity.
// Make a line
for (unsigned int i = 20; i < 50; ++i)
{
itk::Index<2> pixelIndex;
pixelIndex.Fill(i);
image->SetPixel(pixelIndex, 255);
}
// Make a square
// for(unsigned int r = 20; r < 50; r++)
// {
// for(unsigned int c = 20; c < 50; c++)
// {
// itk::Index<2> pixelIndex;
// pixelIndex[0] = r;
// pixelIndex[1] = c;
//
// image->SetPixel(pixelIndex, 255);
// }
// }
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Size< 2 >
itkBinaryThresholdImageFunction.h
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itkImage.h
itk::FloodFilledImageFunctionConditionalIterator
Iterates over a flood-filled image function with write access to pixels.
Definition: itkFloodFilledImageFunctionConditionalIterator.h:38
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:272
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itk::BinaryThresholdImageFunction
Returns true is the value of an image lies within a range of thresholds This ImageFunction returns tr...
Definition: itkBinaryThresholdImageFunction.h:44
itkFloodFilledImageFunctionConditionalIterator.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()