I am running codes to visualizing and analyzing DICOM images in Python. The time I run the code to extract DICOM pixels for each slice location and display a single slice, I am getting the following error: NotImplementedError: this transfer syntax JPEG 2000 Image Compression, can not be read because Pillow lacks the jpeg 2000 decoder plugin
Here is a link to a tutorial that I am following: Link to the tutorial
My code as below:
# 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)
And the error is:
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
I installed all the recommended pakages including Pillow and my Python version is 3.7.
I installed openJPEG via anaconda prompt by running the following command conda install -c conda-forge openjpeg
and is still giving me the same error.
Where did I go wrong?
It seems that some libs and packages doesn't work with python 3.7 and above. I had to remove Anaconda from my computer completely and installed it again. Then downgraded to python 3.6.10 since the default for Jubyter Notebook is 3.7 through Anaconda Prompt. Then I installed the required libs and packages, however, it did not work with Jubyter Notebook instead worked perfectly with JubyterLab.