SimpleITK.Image

SimpleITK.Image  

  By: zhixiongzh on July 12, 2021, 9:33 a.m.

  1. SimpleITK.Image. In process.py, the input image is in the format of SimpleITK.Image, basically the competition assumes that everyone knows what SimpleITK.Image is and how to process it. But it is not the case? I use the following code to process the image as a numpy array:

    img = nib.load(image_path) img = np.asarray(img.get_fdata(),np.float32)

and basically my output would be also numpy.array. Can I get some help on how to transform the SimpleITK.Image to numpy.array and inversely?

  1. get error information"Expected output was not found..." when I run ./test_save_pred.sh Because I am not sure about the format of SimpleITK.Image, I planed to print it to see what it is. so here is what I did in the process.py:
def predict(self, *, input_images: List[SimpleITK.Image]) -> List[SimpleITK.Image]:
    print("==> Running prediction")

    # TODO add code to apply method to input image and output a prediction (and an uncertainty map for task 3 lac)

    for img in input_images:
            print(img)
            break
    print("==> Prediction done")

    # TODO Return a list with a prediction (and an uncertainty map for task 3 lac, the order is important!)
    return img
 Last edited by: zhixiongzh on Aug. 15, 2023, 12:55 p.m., edited 1 time in total.

Re: SimpleITK.Image  

  By: kvanwijnen on July 17, 2021, 9:50 a.m.

Thank you for your message and great to hear you are participating in our challenge!

1.

On the Preparing Docker page of our website we refer to this template repo, and the branch "example_valdo". Here we show an example method, which includes code how to convert a SimpleITK image to a numpy array and back. Please take a look at this example and let us know if you have any other questions! Below also the relevant code from the example, we will add it in the preparing docker page as well.

Important notes about converting a SimpleITK image to numpy. - The order of dimensions is different in SimpleITK and numpy, so don't forget to reorder the axes from (z,y,x) to (x,y,z) (and back when you convert it back to a SimpleITK image) - When converting back to SimpleITK, don't forget to copy the image header information from the input image (includes e.g. voxel spacing etc).

SimpleITK to numpy: image = SimpleITK.GetArrayFromImage(img) image = np.moveaxis(image, [0, 2], [2, 0])

Numpy to SimpleITK: outimg = np.moveaxis(outimg, [0, 2], [2, 0]) outitk = SimpleITK.GetImageFromArray(outimg) outitk.CopyInformation(inputimages[0])

2.

The error message "Expected output was not found..." indicates either the output was not saved, or you need to adapt the "expected_output.json" file so it indicates the filenames that should be saved (you need to adapt to the subject ids you are using to test your docker). This is used as a check to know if the output was saved and if it was saved as the correct filename(s).