Hello Michal,
I think I know the cause of your errors.
The first error is indeed the mismatch (image is 3D, mask is 2D). This also caused the resampleMask script to fail, because that still assumes the image and mask to have the same dimensionality.
As to your last error, that is caused because the JoinSeries filter doesn't like the unsigned char datatype, why this is I don't know.
I can help you to fix it though. You can use the JoinSeries by first using "sitk.Cast(<Image>, sitk.sitkUInt16)", where <Image> is the simpleITK image object of your mask.
However, I saw that your image's dimension are differently ordered: x, y, z sizes are 3, 420, 420. Therefore, you want your mask to end up as 1, 420,420.
This is possible, but pay attention, as this will load the mask on THE FIRST SLICE OF THE IMAGE. I simply do not have the information to determine which slice the mask corresponds to.
Is there a specific reason your image has 3 slices?
anyway, this is a possible way to get your mask to correspond to your images' first slide (or any other slide, see comments in the script). All code lines below are run inside a python interpreter
import SimpleITK as sitk
import numpy as np
im = sitk.ReadImage(r'<path/to/image.nrrd>')
ma = sitk.ReadImage(r'<path/to/mask.nrrd>')
ma_arr = sitk.GetArrayFromImage(ma)
new_arr = np.zeros((ma_arr.shape[0], ma_arr.shape[1], 3), dtype='uint16') # should be the same shape as the array from your image, in z, x, y (reversed from the dimensions you see printed, those are x, y, z)
slice_num = 0 # this indicates on which slice the mask should be situated
new_arr[:, :, slice_num] = ma_arr
# optional, ensure mask is on all slices:
new_arr[:, :, :] = ma_arr[:, :, None] # IMPORTANT, don't forget the [:, :, :] behind new_arr, otherwise your dimension will be incorrect!
new_ma = sitk.GetImageFromArray(new_arr)
new_ma.CopyInformation(im)
sitk.WriteImage(new_ma, r'<path/to/new/mask.nrrd>', True)
Regards,
Joost