【发布时间】:2020-06-17 12:32:24
【问题描述】:
我正在运行代码以在 Python 中可视化和分析 DICOM 图像。当我运行代码为每个切片位置提取 DICOM 像素并显示单个切片时,我收到以下错误:NotImplementedError: this transfer syntax JPEG 2000 Image Compression, can not be read because Pillow lacks the jpeg 2000 decoder plugin
这是我正在关注的教程的链接:Link to the tutorial
我的代码如下:
# 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。
我通过运行以下命令 conda install -c conda-forge openjpeg 通过 anaconda 提示安装了 openJPEG,但仍然给我同样的错误。
我哪里做错了?
【问题讨论】:
-
安装openjpeg后是否重新安装了枕头?
-
似乎某些库和包不适用于 python 3.7 及更高版本。我不得不从我的计算机中完全删除 Anaconda 并重新安装它。然后通过 Anaconda Prompt 降级到 python 3.6.10,因为 Jubyter Notebook 的默认值是 3.7。然后我安装了所需的库和包,但是,它不能与 Jubyter Notebook 一起使用,而是与 JubyterLab 完美配合。