Issue with writing

I’ve tryied tu use SimpleITK library for filling hole in a 3D image but when I’m trying to write the image on disk, the code gives me this type of error. Can someone help me to solve this problem or know how what does it mean?

I attached the line of code:

def filling_hole_sitk(input_im_path: Path, output_path: Path):
image_sitk = sitk.ReadImage(str(input_im_path))

filt_1 = sitk.GrayscaleFillholeImageFilter()
output_1 = filt_1.Execute(image_sitk)
filt_2 = sitk.GrayscaleMorphologicalClosingImageFilter()
output_2 = filt_2.Execute(output_1)

sitk.WriteImage(output_2, str(output_path))

The image in input path is a .mha file

Hello @EneaP,

What error are you getting? Using the current version of SimpleITK 2.2.1, the code works without a problem.

Some comments on the code:

  1. In the current version of SimpleITK there is no need to explicitly convert the pathlib.Path object to str.
  2. The way the object oriented interface is used, creating objects and then calling the Execute method for a single use is less appropriate. Use the object oriented interface when you intend to call the same filter multiple times, otherwise use the procedural interface (i.e. output_1 = sitk.GrayscaleFillhole(image_sitk)).