我有一个大小为422的列表。在索引0中,有.dcm图像的135个文件路径。例如'〜/ 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)
答案 0 :(得分:1)
你似乎在努力解决两个问题:
为了获胜,最好将这两项任务分开,下面的示例代码
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]