dicom saved can't match the plt.show #2017
Replies: 5 comments 10 replies
-
Please post the group 0x0028 element values: Does your |
Beta Was this translation helpful? Give feedback.
-
yes, ds[0x0028, 0x0100].value is 16, So I converted pred to match it if ds[0x0028, 0x0100].value == 16: # 如果dicom文件矩阵是16位格式
newimg = newimg.astype(np.int16) # newimg 是图像矩阵 ds是dcm uint16
elif ds[0x0028, 0x0100].value == 8:
newimg = newimg.astype(np.int8)
else:
raise Exception("unknow Bits Allocated value in dicom header") |
Beta Was this translation helpful? Give feedback.
-
the values of the group 0x0028 elements:
the code example as follow: import pydicom
import numpy as np
import os
from matplotlib import pyplot as plt
import lpips
from matplotlib import pyplot
ds = pydicom.dcmread("data/CTA-GAN/PA1/SE1/IM0.IMA", force=True) # 读取头文件
dsa = pydicom.uid.generate_uid()
ds.SeriesInstanceUID = dsa
# The newimg generated by my network
newimg = np.ones((512, 512))
# newimg[newimg == 0] = -2000
if ds[0x0028, 0x0100].value == 16: # 如果dicom文件矩阵是16位格式
newimg = newimg.astype(np.int16)
print("newimg 是图像矩阵 ds是dcm uint16")
elif ds[0x0028, 0x0100].value == 8:
newimg = newimg.astype(np.int8)
else:
raise Exception("unknow Bits Allocated value in dicom header")
ds.PixelData = newimg.tobytes() # 替换矩阵
print("test1=", ds.pixel_array.shape, len(ds.PixelData)) # test1= (368, 310) 524288
ds.Rows, ds.Columns = newimg.shape
print("test2=", ds.pixel_array.shape, len(ds.PixelData)) # test2= (512, 512) 524288
ds.save_as('test.IMA')
pyplot.imshow(ds.pixel_array, cmap=plt.cm.gray) # cmap=pyplot.cm.bone
pyplot.show()` |
Beta Was this translation helpful? Give feedback.
-
Also , I want know how the resample the dicom file 0.67 × 0.67 × 1.25-mm3 volumes and consisted of 75–490 sections with a matrix size of 512 × 512 pixels, Or a fixed space and size ` for i in range(1, 11):
print(pixelspace1) the orig info is: [[0.48913043737412, 0.48913043737412], [0.48913043737412, 0.48913043737412], [0.48913043737412, 0.48913043737412], [0.48913046717644, 0.48913046717644], [0.48913043737412, 0.48913043737412], [0.48913043737412, 0.48913043737412], [0.48913043737412, 0.48913043737412], [0.48913043737412, 0.48913043737412], [0.48913046717644, 0.48913046717644], [0.48913043737412, 0.48913043737412]] |
Beta Was this translation helpful? Give feedback.
-
okk thanks, i will change it according to my need~hhh
…---Original---
From: ***@***.***>
Date: Mon, Feb 26, 2024 16:18 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [pydicom/pydicom] dicom saved can't match the plt.show(Discussion #2017)
I have no idea what the appropriate conversion process is, it depends on how newimg is being created and what it represents.
Generally though, you'll want to rescale newimg to a suitable range such as (0.0 to 1.0), then convert that to the value range of uint8 or int16 or whatever it is you want, then use numpy.clip() and finally ndarray.astype().
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello, I want generated new dicom and to save, But what is saved is not the same as what is displayed with plt.show
the plt.show is
, the saved dicom is
how to solve the problem?
pydicom 2.4.4
Python 3.7.16
@pdurbin @volrath @yarikoptic @cancan101
Beta Was this translation helpful? Give feedback.
All reactions