简体   繁体   English

如何为glob.glob附加路径+文件

[英]How to append path+file for glob.glob

I have code as follows, it gives me a SimpleITK error 我有如下代码,它给了我一个SimpleITK错误

"ERROR: The file in the series have unsupported 3 dimensions."

The result of print path is 打印路径的结果是

['C:/DataLuna16pred\\subset0\\1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860.mhd'];

How to use it correctly ? 如何正确使用它?

import os
import pandas as pd
import glob
import SimpleITK as sitk
import numpy as np
df = pd.read_csv("C:/DataLuna16pred/CSVFILES/candidates89.csv")
for idx in df.index:
    seriesuid=df.seriesuid[idx]
    path= 'C:/DataLuna16pred/*/'
    path = glob.glob(path+seriesuid+'.mhd')
    ds = sitk.ReadImage(path)

There are two signatures of sitk.ReadImage the first is an interface to the sitk.ImageFileReader which takes a single string for a file name. sitk.ReadImage有两个签名,第一个是sitk.ReadImage的接口,该接口使用一个字符串作为文件名。 That is for reading a single image. 那是为了读取单个图像。

The second one you invoked by passing a list, is to the sitk.ImageSeriesReader which takes an array or list of file names to join the images together into a volume. 您通过传递列表调用的第二个命令是到sitk.ImageSeriesReader,该文件采用数组或文件名列表将图像连接在一起成为一个卷。 This version only takes a list of 2D images to form a 3D image. 此版本仅采用2D图像列表来形成3D图像。 Your argument path is a python list. 您的参数path是python列表。

It is not clear to me what your intentions are with the glob. 对我来说,不清楚您的意图是什么。 Is it to get one file name? 是否获得一个文件名? or multiple? 或多个?

You may need to check the len(path) and if it is one pass path[0] to sitk.ReadImage 您可能需要检查len(path)以及它是否是到sitk.ReadImage [0]的一个传递路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM