DIAGNijmegen / rse-panimg

Conversion of medical images to MHA and TIFF.
Apache License 2.0
13 stars 5 forks source link

Unknown colour space exception #90

Closed jmsmkn closed 1 year ago

jmsmkn commented 2 years ago

We do not have any source images for this but on Grand Challenge we often see this error:

File "/opt/poetry/.venv/lib/python3.8/site-packages/panimg/panimg.py", line 40, in convert
_convert_directory(
File "/opt/poetry/.venv/lib/python3.8/site-packages/panimg/panimg.py", line 116, in _convert_directory
builder_result = _build_files(
File "/opt/poetry/.venv/lib/python3.8/site-packages/panimg/panimg.py", line 148, in _build_files
for result in builder(files=files):
File "/opt/poetry/.venv/lib/python3.8/site-packages/panimg/image_builders/metaio_mhd_mha.py", line 110, in image_builder_mhd
yield SimpleITKImage(
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for SimpleITKImage
image
Unknown color space for MetaIO image: 112 (type=value_error)
jmsmkn commented 2 years ago

I have emailed the user who created this file to try and find out more information.

chrisvanrun commented 2 years ago

I suspect it is a red herring for a multi-component image that has more than 3 components for a voxel. This is generally the case if a format has coded TIME in the components instead of dimensions.

jmsmkn commented 2 years ago

Maybe! The user has not got back to me so we're none the wiser.

Luoxd1996 commented 1 year ago

Hi, I met this problem when I save the output as a 4D mha (the shape is [D, W, H, C], C =45) file, where I want to save the segmentation of 45 organs of a patient into a 4D file but some organs have overlap. I can use SimleITK, ITK-SNAP, 3D Slicer to read or visualize the 4D mha file, but this package throughout an error about color space. I wonder if this package just supports C=1/3/4, according to this line. I think the 4D datatype can deal with the overlap segmentation problem well, but I don't know how to deal with the color space error! Could you give us some advice? Best, Xiangde Luo.

chrisvanrun commented 1 year ago

@Luoxd1996 , reference a quick solution on this gist.

The likely cause of seeing this error is because the naive way of creating 4D images would be something along the lines of:

    output_arr = np.ones((100, 200, 300, 45), dtype=np.uint8)
    image = SimpleITK.GetImageFromArray(output_arr)
    SimpleITK.WriteImage(image, "output.mha", True)

However, this will create a 3D vector image and not a 4D image. Subtle difference. Adding isVector=False as keyword arg to GetImageFromArray() does produce a 4D image but for some unclear reason, it reverses the x, y, z, t order.

chrisvanrun commented 1 year ago

To clarify the difference between a 3D vector image and a 4D image, this is getting the first voxel value:

three_d_vector_image[0, 0, 0][0]
four_d_image[0, 0, 0, 0]
Luoxd1996 commented 1 year ago

@chrisvanrun, thanks a lot! I got it!!! Best.

jmsmkn commented 1 year ago

@Luoxd1996 It is not acceptable to multi-channel requests, you already had a support thread going which I told you at 11am I was working on. Do not create extra work for my team like this, it slows everyone down.