Create an RGB Image#
Synopsis#
Create an RGB Image
Results#
Code#
Python#
#!/usr/bin/env python
import itk
Dimension = 2
RGBPixelType = itk.RGBPixel[itk.ctype("unsigned char")]
image = itk.Image[RGBPixelType, Dimension].New()
C++#
#include "itkImage.h"
#include "itkRGBPixel.h"
int
main()
{
constexpr unsigned int Dimension = 2;
using RGBPixelType = itk::RGBPixel<unsigned char>;
using RGBImageType = itk::Image<RGBPixelType, Dimension>;
auto image = RGBImageType::New();
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TComponent = unsigned short>
class RGBPixel : public itk::FixedArray<TComponent, 3> Represent Red, Green and Blue components for color images.
This class is templated over the representation used for each component.
The following syntax for assigning an index is allowed/suggested:
RGBPixel<float> pixel; pixel = 1.0f, 0.0f, .5f; RGBPixel<char> pixelArray[2]; pixelArray[0] = 255, 255, 255; pixelArray[1] = 255, 255, 244;
Since RGBPixel is a subclass of Array, you can access its components as: pixel[0], pixel[1], pixel[2]
- ITK Sphinx Examples: