I have a dicom image thats shape is (1136, 852, 1) and PixelID is ‘vector of 8-bit unsigned integer’ . I want to cast this to float32 but as I can not cast vector type to simple float, following online advice I tried:
The meaning of the original pixel type ‘vector of 8-bit unsigned integer’ is that for every pixel you have multiple values (likely a three channel image). This can mean that the image is a color image in RGB color space or that it is a scalar/grayscale image masquerading as a color one, a single channel repeated three times.
Given your desire to convert this image type to float32 and not a vector of float32 you are likely assuming this is a scalar image. To extract the first channel and cast to float, then convert to a 2D image from a 3D slice:
To characterize data before working with it, take a look at the characterize_data.py script in the SimpleITK notebooks repository. The data may surprise you, content is not what it visually looks like, vector images that visually look like a scalar, color images that should be scalar/grayscale etc.
The concepts in SimpleITK/ITK are a little different than in numpy. In SimpleITK/ITK an Image has a size (x,y,z…) and the number of components ( defaults to 1 for scalars). So in (1136, 852,1), the 1 is the size in the z dimension not the number of components. Based on the information provided, we don’t know how many channels are in the sitk_scan image.
You should display all the details of your original sitk_scan image with print(sitk_scale.ToString()). If the image of a vector pixel type, it will say “VectorImage”, and later say “VectorLength: 3” or similar. This can be accessed via the sitk::Image interface with GetNumberOfComponentsPerPixel.
The 3D image of vectors can becopied to a 4D image of scalar with sitk_scan4d = sitk_scan.ToVector(inPlace=false) which may be want you are expecting.