5

I am trying to apply CannyEdgeDetectionImageFilter on a .bmp image using Simple-itk managed dll.

here is my code:

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);

I got this exception while executing CannyEdgeDetectionImageFilter.

sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byclass itk::simple::CannyEdgeDetectionImageFilter

How can I cast this unsupported thing into supported for simpleitk?

here is some aadition to my code.I tried to cast vector of 8-bit unsigned integer into supported one,But here I fail to do this.

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

sitk::ERROR: Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float

Is there anything else I could do to work this code?

Any help is appreciated.

Shikha
  • 339
  • 2
  • 14

2 Answers2

2

For the error of 8-bit unsigned integer not supported in 2D byclass, you may need to change a way when you read the image like:

image = sitk.ReadImage("input.jpg", sitk.sitkInt8)

Now sitk.CurvatureFlow and imgWhiteMatter = sitk.ConnectedThreshold would work.

Hope it helps.

Cloud Cho
  • 1,594
  • 19
  • 22
1

There are a couple ways to apply a Canny filter to an RGB image. (I assume it's an RGB image?)

There are many ways to convert a multi-component image into a scalar image. A simple cast is not well defined. It could mean Luminance, a vector magnitude etc...

One option is to run the algorithm independently on each channel of the image and get a Red edge image, a Blue edge image and a Green edge image. Here is some pseudo code:

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)

Alternatively, you may want a scalar edge image. You could derive the Luminance, Brightness or Lightness from the RGB channels and then run the Canny filter just once.

blowekamp
  • 1,401
  • 7
  • 7