python - NotImplementedError:此传输语法 JPEG 2000 图像压缩,无法读取,因为 Pillow 缺少 jpeg 2000 解码器插件
问题描述
我正在运行代码以在 Python 中可视化和分析 DICOM 图像。当我运行代码为每个切片位置提取 DICOM 像素并显示单个切片时,我收到以下错误:NotImplementedError: this transfer syntax JPEG 2000 Image Compression, can not be read because Pillow lacks the jpeg 2000 decoder plugin
这是我正在关注的教程的链接:链接到教程
我的代码如下:
# set path and load files
path = 'C:\\Users\\MyName\\Desktop\\DICOM\\series-00000\\'
patient_dicom = load_scan(path)
patient_pixels = get_pixels_hu(patient_dicom)
#sanity check
plt.imshow(patient_pixels[326], cmap=plt.cm.bone)
错误是:
NotImplementedError Traceback (most recent call last)
<ipython-input-29-c775fc5d5328> in <module>
2 path = 'C:\\Users\\MyName\\Desktop\\DICOM\\series-00000\\'
3 patient_dicom = load_scan(path)
----> 4 patient_pixels = get_pixels_hu(patient_dicom)
5 #sanity check
6 plt.imshow(patient_pixels[326], cmap=plt.cm.bone)
<ipython-input-28-1f0488edc728> in get_pixels_hu(scans)
1 def get_pixels_hu(scans):
----> 2 image = np.stack([s.pixel_array for s in scans])
3 image = image.astype(np.int16)
4 # Set outside-of-scan pixels to 0
5 # The intercept is usually -1024, so air is approximately 0
<ipython-input-28-1f0488edc728> in <listcomp>(.0)
1 def get_pixels_hu(scans):
----> 2 image = np.stack([s.pixel_array for s in scans])
3 image = image.astype(np.int16)
4 # Set outside-of-scan pixels to 0
5 # The intercept is usually -1024, so air is approximately 0
~\Anaconda3\64X-Install\lib\site-packages\pydicom\dataset.py in pixel_array(self)
1613 :class:`numpy.ndarray`.
1614 """
-> 1615 self.convert_pixel_data()
1616 return self._pixel_array
1617
~\Anaconda3\64X-Install\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self, handler_name)
1322 self._convert_pixel_data_using_handler(handler_name)
1323 else:
-> 1324 self._convert_pixel_data_without_handler()
1325
1326 def _convert_pixel_data_using_handler(self, name):
~\Anaconda3\64X-Install\lib\site-packages\pydicom\dataset.py in _convert_pixel_data_without_handler(self)
1432 .format(", ".join([str(hh) for hh in available_handlers]))
1433 )
-> 1434 raise last_exception
1435
1436 def _do_pixel_data_conversion(self, handler):
~\Anaconda3\64X-Install\lib\site-packages\pydicom\dataset.py in _convert_pixel_data_without_handler(self)
1412 for handler in available_handlers:
1413 try:
-> 1414 self._do_pixel_data_conversion(handler)
1415 return
1416 except Exception as exc:
~\Anaconda3\64X-Install\lib\site-packages\pydicom\dataset.py in _do_pixel_data_conversion(self, handler)
1439 # Use the handler to get a 1D numpy array of the pixel data
1440 # Will raise an exception if no pixel data element
-> 1441 arr = handler.get_pixeldata(self)
1442 self._pixel_array = reshape_pixel_array(self, arr)
1443
~\Anaconda3\64X-Install\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(ds)
132 "Pillow lacks the jpeg 2000 decoder plugin"
133 .format(transfer_syntax.name))
--> 134 raise NotImplementedError(msg)
135
136 if transfer_syntax == pydicom.uid.JPEGExtended and ds.BitsAllocated != 8:
NotImplementedError: this transfer syntax JPEG 2000 Image Compression, can not be read because Pillow lacks the jpeg 2000 decoder plugin
我安装了所有推荐的包,包括 Pillow,我的 Python 版本是 3.7。我通过运行以下命令通过 anaconda 提示安装了 openJPEG,conda install -c conda-forge openjpeg
但仍然给我同样的错误。
我哪里做错了?
解决方案
似乎某些库和包不适用于 python 3.7 及更高版本。我不得不从我的计算机中完全删除 Anaconda 并重新安装它。然后通过 Anaconda Prompt 降级到 python 3.6.10,因为 Jubyter Notebook 的默认值是 3.7。然后我安装了所需的库和包,但是,它不能与 Jubyter Notebook 一起使用,而是与 JubyterLab 完美配合。
推荐阅读
- c# - 自行从面板中删除用户控件
- python - macOS Big Sur 上的 PyInstaller 应用程序黑窗
- javascript - 网站一页上的 Javascript Uncaught TypeError
- angular - Express Server + Angular 深层链接
- pytest - 使用 pytest 针对已知输出测试处理后的输出
- r - 如何删除ggplot中多余的图例(标题)?
- javascript - 在 paginateScan、aws-sdk-vv3 中使用 AbortSignal 在 http-request-handler 中接收类型错误
- microsoft-reporting - 在 MS Report Builder 中计算中位数和百分位数
- python - 删除项目 Gitlab 内目录中存在的子目录
- powerquery - 用另一列中的值覆盖一列中的值,除非为空 PowerQuery