pydicom讀取dicom文件報錯


之前采用pydicom讀取dicom文件一切都很正常,不過最近讀取一批數據的時候,會報錯

讀取代碼

file = pydicom.read_file(filepath)
data = file.pixel_array

問題就出在pixel_array這個屬性上,報錯如下

OSError                                   Traceback (most recent call last)
c:\python35\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(dicom_dataset)
    196                 fio = io.BytesIO(pixel_data)
--> 197                 decompressed_image = Image.open(fio)
    198             except IOError as e:

c:\python35\lib\site-packages\PIL\Image.py in open(fp, mode)
   2571     raise IOError("cannot identify image file %r"
-> 2572                   % (filename if filename else fp))
   2573 

OSError: cannot identify image file <_io.BytesIO object at 0x000002418FC85CA8>

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-55-c00f3f09682d> in <module>()
----> 1 file.pixel_array

c:\python35\lib\site-packages\pydicom\dataset.py in pixel_array(self)
    899             The Pixel Data (7FE0,0010) as a NumPy ndarray.
    900         """
--> 901         self.convert_pixel_data()
    902         return self._pixel_array
    903 

c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
    845         )
    846 
--> 847         raise last_exception
    848 
    849     def decompress(self):

c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
    813             try:
    814                 # Use the handler to get a 1D numpy array of the pixel data
--> 815                 arr = handler.get_pixeldata(self)
    816                 self._pixel_array = reshape_pixel_array(self, arr)
    817 

c:\python35\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(dicom_dataset)
    197                 decompressed_image = Image.open(fio)
    198             except IOError as e:
--> 199                 raise NotImplementedError(e.strerror)
    200             UncompressedPixelData.extend(decompressed_image.tobytes())
    201     except Exception:

NotImplementedError: None

看到一篇博客https://blog.csdn.net/inter_peng/article/details/74370306與我的問題類似,都出在dicom文件格式上面,這種壓縮格式用pydicom讀取不出來,采用SimpleITK可以解決

file = sitk.ReadImage(filepath)
data = sitk.GetArrayFromImage(file)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM