No available image handler could decode this transfer syntax JPEG Lossless when read DICOM and ploting using matplotlib

喜欢而已 提交于 2020-05-17 07:05:52

问题


When i use pydicom in python3.6, there are some problem:

import pydicom
import matplotlib.pyplot as plt
import os
import pylab

filePath = "/Users/zhuangrui/Documents/Python/Dicom/dicoms/zhang_bo/0001.dcm"
dataSet_1 = pydicom.dcmread(filePath)
plt.imshow(dataSet_1.pixel_array)
plt.show()

here is the problem:

How can this problem be solved? Thank you very much!


回答1:


I've faced with the same problem, after doing some research on the suggested link above. I've managed to solve it by updating to the latest pydicom module "1.2.0" and installing gdcm. You can update the pydicom with pip install -U git+https://github.com/pydicom/pydicom.git

You can find the latest gdcm here and this link explains the installation.


I use anaconda and it's easier to install the gdcm package and solve the problem. If you use anaconda just type inside from your environment: conda install pydicom --channel conda-forge to get pydicom's latest and

conda install -c conda-forge gdcm

to get the gdcm. This resolves the problem. Hope these will help.




回答2:


With pydicom, you need an appropriate image handler also installed to handle compressed image types.

For JPEG lossless, in theory the following should work: jpeg_ls, gdcm, or Pillow with jpeg plugin. All of these also require Numpy to be installed. See the discussion at https://github.com/pydicom/pydicom/issues/532.

There is also a pull request in progress to add more descriptive error messages for what image handlers are needed for different images.




回答3:


Problem:

I was trying to read medical images with .dcm extension. But was getting an error on Windows as well as on Ubuntu. I find a solution which will work on both the machined.

The error I got on Ubuntu is: NotImplementedError: this transfer syntax JPEG 2000 Image Compression (Lossless Only), can not be read because Pillow lacks the jpeg 2000 decoder plugin

(Note for Windows I was getting a different error but I am sure it's because of the same issue i.e. Pillow does not support JPEG 2000 format)

Platforma Information:

  1. I am using: Python 3.6, Anaconda and Ubuntu, 15 GB RAM

RAM is important:

The solution I applied is the same as Ali explained above. But I want to add this installation may take time (depending on RAM you are using). On ubuntu where I am using 15 GB RAM on Cloud platform taken less time and on Windows on a local machine having 4 GB RAM taken a lot of time.

Solution

  1. Anaconda is necessary. Why? Please check the official doc of pydicom (https://pydicom.github.io/pydicom/dev/getting_started.html) its mentioned "To install pydicom along with image handlers for compressed pixel data, we encourage you to use Miniconda or Anaconda" (Note for Windows I was getting a different error)

  2. If you are using Ubuntu directly open Terminal. If you are using Windows then on Anaconda Navigator go to Environment from here start terminal. Execute the following commands on it:

    pip install -U git+https://github.com/pydicom/pydicom.git

    conda install pydicom --channel conda-forge

    conda install -c conda-forge gdcm

Cross Check:

Now use .dcm file for which we got the Error. Try to use the following code in Python notebook

filename = 'FileName.dcm'
ds = pydicom.dcmread(filename)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone) 

It should print the output. Also try this code:

ds.pixel_array

This will give you the array containing values.



来源:https://stackoverflow.com/questions/50725792/no-available-image-handler-could-decode-this-transfer-syntax-jpeg-lossless-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!