RuntimeError: Exception thrown in SimpleITK ReadImage。File cannot be read请问这要怎么解决啊?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
你知我知皆知 2024-08-08 07:00关注以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
这个问题是由于尝试打开一个不存在的图像文件导致的。在Python中,你可以使用
os.path.exists()函数来检查文件是否存在。if not os.path.exists('C:/Users/thinkpad/Desktop/test/1/0.mhd'): print("File does not exist")如果文件存在,那么
ReadImage()方法应该正常工作。如果没有找到文件,它会抛出RuntimeError异常,你可以在错误消息中看到详细的错误信息。如果你想要避免这个错误,可以考虑将文件路径保存为相对路径(例如
'C:/Users/thinkpad/Desktop/test/1/'),这样就不需要处理绝对路径了。解决 无用评论 打赏 举报
