I have a dicom file from which I read images. The images I read, however, has incorrect colormap. Ideally, the image should look like:
However, the following code only gives me
If I only take the red component, I get the image below, which is not correct and cannot be adjusted to the ideal result in any colormap I tried.
or
root = tk.Tk()
root.withdraw()
path = filedialog.askopenfilename()
ds = dicom.dcmread(path, force = True) # reads a file data set
video = ds.pixel_array #reads a sequence of RGB images
plt.imsave(some_path, video[0], format='png') #gives image [2]
What have I done wrong?
CodePudding user response:
This really looks like YCbCr data, is the Photometric Interpretation something like YBR_FULL
? If so then as mentioned in the documentation you need to apply a colour space conversion, which in pydicom is:
from pydicom import dcmread
from pydicom.pixel_data_handlers import convert_color_space
ds = dcmread(...)
rgb = convert_color_space(ds.pixel_array, "YBR_FULL", "RGB")