将 Ultra Sound Dicom 图像从 RGB 转换为单色

问题描述 投票:0回答:1

我有一张 Ultra Sound dicom 图像,每像素采样数为 3,光度解释为 RBG。所以实际上它有 3 个通道。我想将它转换为单通道并保存。有没有办法在 pydicom 中做?

python rgb dicom monochrome
1个回答
0
投票

UltraSound 图像是 RGB 类型,我的要求是将其转换为灰度。 SamplesPerPixel=3 and Photometric Interpretation=RGB

US RGB Dicom before fix

我已经使用下面的代码解决了它。 RGB 图像有 3 个通道,解决方案是从 3 个通道中提取一个通道并将其保存回 dicom

US MONOCHROME Dicom after fix

import pydicom
ds = pydicom.dcmread('US.dcm')
# get the pixel information into a numpy array
npdata = ds.pixel_array
#remove the 3rd dimension
npdata1 = npdata[:,:,0]
#put back the pixels 
ds.PixelData = npdata1.tobytes()
#update rows and cols
ds.Rows, ds.Columns = npdata1.shape
#change RBG to MONOCHROME2
ds.PhotometricInterpretation = "MONOCHROME2"
#change samples per pixel from 3 to 1
ds.SamplesPerPixel = 1
#save the file
ds.save_as('filename.dcm',False)
© www.soinside.com 2019 - 2024. All rights reserved.