//RGB图像
#include "itkRGBPixel.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
int main(int,char *argv[])
{
//RGB pixel class 模板化在一个用于表示每个红、绿、蓝像素组件的类型上
using PixelType = itk::RGBPixel<unsigned char>;
//然后使用类型PixelType作为图形的像素的像素模板参数
using ImageType = itk::Image<PixelType,3>;
//图像类型可用于实例化其他过滤器,例如,将从文件中读取图像的itk::ImageFileReader对象
//定义图像文件读取器
using ReaderType = itk::ImageFileReader<ImageType>;
//类似于生成一个reader指针对象
ReaderType::Pointer reader = ReaderType::New();
const char * filename ="E:\ITK_examples\duolaAmeng.jpg";
//设置文件读取路径,SetFileName()方法指定要读取的文件,它被转发给IO实例
reader->SetFileName(filename);
reader->Update();
//GetOutput()方法获取该进程对象的输出数据,这个函数的输出只有在适当的Update()出现后才有效
ImageType::Pointer image = reader->GetOutput();
//定义像素在坐标上的范围
//const ImageType::IndexType pixelIndex = { {25,35,0} };
ImageType::IndexType pixelIndex;
pixelIndex[0] = 25;
pixelIndex[1] = 35;
pixelIndex[2] = 0;
//现在可以使用RGBPixel类提供的方法来访问像素的颜色组件
PixelType onePixel = image->GetPixel(pixelIndex);
PixelType::ValueType red = onePixel.GetRed();
PixelType::ValueType green = onePixel.GetGreen();
PixelType::ValueType blue = onePixel.GetBlue();
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;
//还可以使用子索引表示法,因为itk::RGBPixel从itk::FixedArray类继承了[]操作符。
red = onePixel[0]; // 提取红色组件
green = onePixel[1]; // 提取绿色组件
blue = onePixel[2]; // 提取蓝色组件
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;
}
代码是没错误的,但是运行时出现解析错误什么的