如何将调色板图像读为具有ITK标量图像
How to read a palette image as a scalar image with ITK?
当我读取图像时,在此处实现的 itk::ImageIOBase
时,我认为该图像具有RGB像素类型。图像的格式是tiff,但也可以是png或gif。
itk::ImageIOBase::Pointer imageIO =
itk::ImageIOFactory::CreateImageIO(
fileName, itk::ImageIOFactory::ReadMode);
如何知道,通过itk ,图像实际上是调色板图像,标量图像以及调色板,并将图像读为标量图像 调色板?我需要检测文件中存储的索引以及文件中使用的调色板。
目前,我唯一的解决方案是使用FreeImagePlus识别和读取此类图像。我在类ImageIOBase
中没有找到任何可能与此相关的功能。
任何帮助都将不胜感激,我在互联网上没有找到太多信息!
您是否尝试将其读为灰度图像?该读者在不明确设置IO的情况下会产生什么结果?
typedef itk::Image<unsigned char, 2> uc2Type;
typedef itk::ImageFileReader<uc2Type> ReaderType;
除非您需要某物的颜色pallette,否则这可能就足够了。
要回答我自己的问题,该功能现在在itk,主分支中实现,并提供PNG TIF和BMP Images的Palette的支持
在这里为那些有兴趣的人提供一个工作示例:
#include "itkImage.h"
#include <iostream>
#include <string>
#include "itkPNGImageIOFactory.h"
#include "itkImageFileReader.h"
#include "itkPNGImageIO.h"
int main()
{
std::string filename("testImage_palette.png");
auto io = itk::PNGImageIO::New();
// tell the reader not to expand palette to RGB, if possible
io->SetExpandRGBPalette(false);
typedef unsigned short PixelType;
typedef itk::Image<PixelType, 2> imageType;
typedef itk::ImageFileReader<imageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->SetImageIO(io);
try {
reader->Update();
} catch (itk::ExceptionObject &err) {
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
std::cout<< std::endl << "IsReadAsScalarPlusPalette:" <<io->GetIsReadAsScalarPlusPalette() << std::endl;
if (io->GetIsReadAsScalarPlusPalette()) {
auto palette(io->GetColorPalette());
std::cout<< "palette (size="<< palette.size()<<"):"<< std::endl;
auto m(std::min(static_cast<size_t>(10),palette.size()));
for (size_t i=0; i<m;++i) {
std::cout << "["<<palette[i]<< "]"<< std::endl;
}
if (m< palette.size())
std::cout<< "[...]"<< std::endl;
}
// if io->GetIsReadAsScalarPlusPalette() im will be the index of the palette image
auto im(reader->GetOutput());
}
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 使用 ITK 计算图像的中值
- ITK - 如何合并两个图像
- 如何在Visual Studio中使用ITK配置的C 读取图像
- FloatType图像ITK上的分割故障
- 如何将调色板图像读为具有ITK标量图像
- 读取 *.mhd/*.raw 在 ITK 中格式化 3D 图像
- 如何在Python中实现ITK映像和SimpleItk图像之间的转换
- ITK-图像处理,计算3D图像的形状特征
- ITK 中具有稀疏和连续坐标的图像
- 如何使用vtk和itk创建可变维图像查看器
- 更新itk图像在Qt用户界面