简体   繁体   中英

How to append path+file for glob.glob

I have code as follows, it gives me a SimpleITK error

"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. 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. This version only takes a list of 2D images to form a 3D image. Your argument path is a python list.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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