不支持8位无符号整数的向量

Shi*_*kha 5 c# c++ image-formats itk

我正在尝试使用Simple-itk托管的dll在.bmp图像上应用CannyEdgeDetectionImageFilter.

这是我的代码:

itk.simple.Image image1= SimpleITK.ReadImage("Input.bmp");

ImageFileReader read = new ImageFileReader();
read.SetFileName("Input.bmp");
read.Execute();

CannyEdgeDetectionImageFilter canny = new CannyEdgeDetectionImageFilter();
itk.simple.Image image2= canny.Execute(image1);//I got below exception here.

ImageFileWriter write = new ImageFileWriter();
write.SetFileName("Output.bmp");
write.Execute(image2,"Output.bmp", true);
Run Code Online (Sandbox Code Playgroud)

我在执行CannyEdgeDetectionImageFilter时遇到了这个异常.

sitk ::错误:像素类型:2D byclass itk :: simple :: CannyEdgeDetectionImageFilter不支持8位无符号整数向量

如何将这个不受支持的东西投射到simpleitk支持的东西?

这是对我的代码的一些补充.我试图将8位无符号整数的向量转换为支持的整数,但是在这里我没有做到这一点.

CastImageFilter cast = new CastImageFilter();
PixelIDValueEnum p= cast.GetOutputPixelType();
image1= SimpleITK.Cast(image1, p);//I got below exception here.
Run Code Online (Sandbox Code Playgroud)

sitk ::错误:过滤器不支持从8位无符号整数的转换向量转换为32位浮点数

我还能做些什么来处理这段代码吗?

任何帮助表示赞赏.

blo*_*amp 1

有多种方法可以将 Canny 滤镜应用于 RGB 图像。(我认为它是 RGB 图像?)

有很多方法可以将多分量图像转换为标量图像。简单的演员阵容没有明确定义。它可能意味着亮度、矢量幅度等......

一种选择是在图像的每个通道上独立运行算法并获得红边图像、蓝边图像和绿边图像。这是一些伪代码:

for i in range(rgbimage.GetNumberOfComponentsPerPixel()):
   component_image = sitk.VectorIndexSelectionCast(rgbimage, i, sitk.sitkFloat32)
   edge_images[i] = sitk.CanneyEdgeDetection(component_image)

edge_image = sitk.Compose(edge_images)
Run Code Online (Sandbox Code Playgroud)

或者,您可能需要标量边缘图像。您可以从 RGB 通道导出亮度、亮度或亮度,然后仅运行一次 Canny 滤镜。