欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RGB Images

程序员文章站 2024-03-15 08:26:17
...
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRGBPixel.h"

int
main(int, char* argv[])
{

    using PixelType = itk::RGBPixel<unsigned char>;
    using ImageType = itk::Image<PixelType, 3>;
    using ReaderType = itk::ImageFileReader<ImageType>;

    ReaderType::Pointer reader = ReaderType::New();
    const char* const  filename = argv[1];
    reader->SetFileName(filename);
    reader->Update();

    ImageType::Pointer         image = reader->GetOutput();
    const ImageType::IndexType pixelIndex = { { 25, 35, 0 } };

    PixelType onePixel = image->GetPixel(pixelIndex);

    PixelType::ValueType red = onePixel.GetRed();
    PixelType::ValueType green = onePixel.GetGreen();
    PixelType::ValueType blue = onePixel.GetBlue();
    // Software Guide : EndCodeSnippet

    std::cout << "Pixel values from GetRed,GetGreen,GetBlue:" << std::endl;
    std::cout << "Red = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(red)
        << std::endl;
    std::cout << "Green = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(green)
        << std::endl;
    std::cout << "Blue = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
        << std::endl;

    red = onePixel[0];   // extract Red   component
    green = onePixel[1]; // extract Green component
    blue = onePixel[2];  // extract Blue  component

    std::cout << "Pixel values:" << std::endl;
    std::cout << "Red = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(red)
        << std::endl;
    std::cout << "Green = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(green)
        << std::endl;
    std::cout << "Blue = "
        << itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
        << std::endl;
    return EXIT_SUCCESS;
}

 

相关标签: itk