ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/IterateRegionWithAccessToIndexWithWriteAccess/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"
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << "Required: filename" << std::endl;
return EXIT_FAILURE;
}
using ImageType = itk::Image<unsigned char, 2>;
ImageType::Pointer image = itk::ReadImage<ImageType>(argv[1]);
ImageType::SizeType regionSize;
regionSize[0] = 5;
regionSize[1] = 4;
ImageType::IndexType regionIndex;
regionIndex[0] = 0;
regionIndex[1] = 0;
region.SetSize(regionSize);
region.SetIndex(regionIndex);
itk::ImageRegionIteratorWithIndex<ImageType> imageIterator(image, region);
while (!imageIterator.IsAtEnd())
{
std::cout << "Index: " << imageIterator.GetIndex() << " value: " << (int)imageIterator.Get() << std::endl;
// Set the current pixel to white
imageIterator.Set(255);
++imageIterator;
}
#ifdef ENABLE_QUICKVIEW
// Visualize
QuickView viewer;
viewer.AddImage<ImageType>(image);
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkImageFileReader.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::ImageConstIteratorWithIndex::Get
PixelType Get() const
Definition: itkImageConstIteratorWithIndex.h:245
itkImageRegionIteratorWithIndex.h
itk::ImageConstIteratorWithIndex::GetIndex
const IndexType & GetIndex() const
Definition: itkImageConstIteratorWithIndex.h:220
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
QuickView.h
QuickView::AddImage
void AddImage(TImage *, bool FlipVertical=true, std::string Description="")
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageRegionIteratorWithIndex::Set
void Set(const PixelType &value) const
Definition: itkImageRegionIteratorWithIndex.h:109
itk::ImageRegionIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkImageRegionIteratorWithIndex.h:73
itk::ImageConstIteratorWithIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIteratorWithIndex.h:276
QuickView
A convenient class to render itk images with vtk.
Definition: QuickView.h:111
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:202
QuickView::Visualize
void Visualize(bool interact=true)