python - 修改大量 DICOM (.dcm) 文件。
问题描述
也许是一个简单的问题,但我没有取得进展,希望能得到帮助。
我有一个大小为 422 的列表。在索引 0 中有 135 个文件路径指向 .dcm 图像。例如 '~/images/0001.dcm','~/images/0135.dcm' 在索引 1 内有 112 个图像路径,索引 2 有 110 个等。
所有图像的大小均为 512 x 512。我希望将它们重新调整为 64 x 64。
这是我第一次同时使用图像和 .dcm 数据,所以我非常不确定如何调整大小。如果您愿意,我也不确定如何访问和修改“内部”列表中的文件。
这样的事情是不是很离谱?
IMG_PX_SIZE = 64
result = []
for i in test_list:
result_inner_list = []
for image in i:
# resize all images at index position i and store in list
new_img = cv2.resize(np.array(image.pixel_array (IMG_PX_SIZE,IMG_PX_SIZE))
result_inner_list.append(new_img)
# Once all images at index point i are modified, append them these to a master list.
result.append(result_inner_list)
解决方案
您似乎在两个问题上苦苦挣扎:
- 访问文件路径
- 调整大小
为了你赢,最好把这两个任务分开,下面的示例代码
IMG_PX_SIZE = 64
def resize(image):
# your resize code here similar to:
# return v2.resize(np.array(image.pixel_array(IMG_PX_SIZE,IMG_PX_SIZE))
pass
def read(path):
# your file read operation here
pass
big_list = [['~/images/0001.dcm','~/images/0135.dcm'],
['~/images/0002.dcm','~/images/0136.dcm']]
resized_images = [[resize(read(path)) for path in paths] for paths in big_list]
推荐阅读
- excel - Excel:根据ID合并列中的内容
- java - NoResponse Received - Smack MUC Presence(进入房间)
- web-scraping - 带有 Scrapy 的 Celery 不解析 CSV 文件
- c# - 为什么我不能在方法之外创建实例
- chess - 有没有办法在 Stockfish 中查看失误、错误、错过的将死
- typescript - 如何编写具有强制属性的通用接口以及 T 中的任何可能属性?
- postgresql - 如何仅返回 to_jsonb 调用中的选定列?
- sql - 如何从oracle数据库中获取电子邮件地址
- spring-boot - “检测到不明确的搜索映射。” 在 Spring Boot 2.3.6 中实现 springfox-boot-starter 3.0.0 时抛出异常
- html - 试图用 PUT 覆盖 POST 方法,但方法覆盖不起作用