Is Pixel Inside Region#
Synopsis#
Determine if a pixel is inside of a region
Results#
Output:
[1, 1] Inside
[6, 6] Outside
Code#
Python#
#!/usr/bin/env python
import itk
Dimension = 2
SizeType = itk.Size[Dimension]
size = SizeType()
size.Fill(3)
IndexType = itk.Index[Dimension]
start = IndexType()
start.Fill(0)
RegionType = itk.ImageRegion[Dimension]
region = RegionType(start, size)
testPixel1 = IndexType()
testPixel1[0] = 1
testPixel1[1] = 1
testPixel2 = IndexType()
testPixel2[0] = 6
testPixel2[1] = 6
print(testPixel1, end=" ")
if region.IsInside(testPixel1):
print("Inside")
else:
print("Outside")
print(testPixel2, end=" ")
if region.IsInside(testPixel2):
print("Inside")
else:
print("Outside")
C++#
#include "itkImageRegion.h"
#include "itkIndex.h"
#include "itkSize.h"
int
main()
{
constexpr unsigned int Dimension = 2;
using RegionType = itk::ImageRegion<Dimension>;
using SizeType = RegionType::SizeType;
using IndexType = RegionType::IndexType;
auto size = SizeType::Filled(3);
IndexType start{};
RegionType region(start, size);
IndexType testPixel1;
testPixel1[0] = 1;
testPixel1[1] = 1;
IndexType testPixel2;
testPixel2[0] = 6;
testPixel2[1] = 6;
std::cout << testPixel1 << " ";
if (region.IsInside(testPixel1))
{
std::cout << "Inside";
}
else
{
std::cout << "Outside";
return EXIT_FAILURE;
}
std::cout << std::endl;
std::cout << testPixel2 << " ";
if (region.IsInside(testPixel2))
{
std::cout << "Inside";
return EXIT_FAILURE;
}
else
{
std::cout << "Outside";
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<unsigned int VImageDimension>
class ImageRegion An image region represents a structured region of data.
ImageRegion is an class that represents some structured portion or piece of an Image. The ImageRegion is represented with an index and a size in each of the n-dimensions of the image. (The index is the corner of the image, the size is the lengths of the image in each of the topological directions.)
See also
Region
See also
Index
See also
Size
See also
MeshRegion
