回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我需要用下面的输入/输出编写一个python函数或类</p>
<p><strong>输入:</strong></p>
<ul>
<li>X射线源的位置(仍然不确定为什么需要它)</li>
<li>董事会的位置(仍不确定为什么需要)</li>
<li>三维CT扫描</li>
</ul>
<p><strong>输出:</strong></p>
<p>二维X射线扫描(模拟X射线扫描,即扫描整个身体)</p>
<p>关于我要实现的目标,我要说几句重要的话:</p>
<ul>
<li>你不需要来自真实世界的额外信息或任何先进的知识。在</li>
<li>您可以添加任何您认为合适的输入参数。在</li>
<li>如果您的方法产生了工件,那么您必须修复它们。在</li>
<li>请解释你方法的每一步。在</li>
</ul>
<p>到目前为止我所做的事情:(.py文件已添加)</p>
<p>我已经阅读了.dicom文件,它们位于“Case2”文件夹中。在</p>
<p>这些.dicom文件可以从我的谷歌硬盘下载:
<code>https://drive.google.com/file/d/1lHoMJgj_8Dt62JaR2mMlK9FDnfkesH5F/view?usp=sharing</code></p>
<p>我把文件按位置分类了。在</p>
<p>最后,我创建了一个3D阵列,并将所有图像添加到该阵列中,以便绘制结果(您可以在添加的图像中看到它们)-这些结果是CT扫描的切片。(参考文献:<a href="https://pydicom.github.io/pydicom/stable/auto_examples/image_processing/reslice.html#sphx-glr-auto-examples-image-processing-reslice-py" rel="noreferrer">https://pydicom.github.io/pydicom/stable/auto_examples/image_processing/reslice.html#sphx-glr-auto-examples-image-processing-reslice-py</a>)</p>
<p>以下是完整代码:</p>
<pre><code>import pydicom as dicom
import os
import matplotlib.pyplot as plt
import sys
import glob
import numpy as np
path = "./Case2"
ct_images = os.listdir(path)
slices = [dicom.read_file(path + '/' + s, force=True) for s in ct_images]
slices[0].ImagePositionPatient[2]
slices = sorted(slices, key = lambda x: x.ImagePositionPatient[2])
#print(slices)
# Read a dicom file with a ctx manager
with dicom.dcmread(path + '/' + ct_images[0]) as ds:
# plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
print(ds)
#plt.show()
fig = plt.figure()
for num, each_slice in enumerate(slices[:12]):
y= fig.add_subplot(3,4,num+1)
#print(each_slice)
y.imshow(each_slice.pixel_array)
plt.show()
for i in range(len(ct_images)):
with dicom.dcmread(path + '/' + ct_images[i], force=True) as ds:
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
plt.show()
# pixel aspects, assuming all slices are the same
ps = slices[0].PixelSpacing
ss = slices[0].SliceThickness
ax_aspect = ps[1]/ps[0]
sag_aspect = ps[1]/ss
cor_aspect = ss/ps[0]
# create 3D array
img_shape = list(slices[0].pixel_array.shape)
img_shape.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(len(slices))
img3d = np.zeros(img_shape)
# fill 3D array with the images from the files
for i, s in enumerate(slices):
img2d = s.pixel_array
img3d[:, :, i] = img2d
# plot 3 orthogonal slices
a1 = plt.subplot(2, 2, 1)
plt.imshow(img3d[:, :, img_shape[2]//2])
a1.set_aspect(ax_aspect)
a2 = plt.subplot(2, 2, 2)
plt.imshow(img3d[:, img_shape[1]//2, :])
a2.set_aspect(sag_aspect)
a3 = plt.subplot(2, 2, 3)
plt.imshow(img3d[img_shape[0]//2, :, :].T)
a3.set_aspect(cor_aspect)
plt.show()
</code></pre>
<p>结果不是我想要的,因为:</p>
<p>这些是CT扫描的切片。我需要模拟一个X射线扫描,它是一个贯穿全身的扫描。在</p>
<p>希望你能帮我模拟一个穿过身体的X光扫描。在</p>
<p>我读过这样的书:“一个普通的2dx射线图像是通过体积的和投影。把平行光穿过体积,再把密度加起来。”我不知道这是如何用代码实现的。在</p>
<p>可能有帮助的引用:<a href="https://pydicom.github.io/pydicom/stable/index.html" rel="noreferrer">https://pydicom.github.io/pydicom/stable/index.html</a></p>