Python Forum
Trying to invert DICOM image with Python 3.6
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to invert DICOM image with Python 3.6
#1
I'm trying to INVERT a DICOM image in Python 3.6. I've tried this (and many others) pieces of code:

#from PIL import Image
import matplotlib.pyplot as plt
import PIL.ImageOps    
import os
import pydicom
os.chdir('C:\\Users\\franc\\Desktop\\ILD Swiss\\ILD_DB_lungMasks\\3\\lung_mask')
image=pydicom.dcmread("lung_mask_7358_10.dcm")
#image = image.open("lung_mask_7358_10.dcm")


plt.imshow(image.pixel_array, cmap=plt.cm.gray) 

inverted_image = PIL.ImageOps.invert(image)

#inverted_image.save('invert3.dicom')
I get this error:

Error:
File "<ipython-input-54-55e84423ace0>", line 1, in <module> runfile('C:/Users/franc/.spyder-py3/invert3.py', wdir='C:/Users/franc/.spyder-py3') File "C:\Users\franc\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace) File "C:\Users\franc\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/franc/.spyder-py3/invert3.py", line 20, in <module> inverted_image = PIL.ImageOps.invert(image) File "C:\Users\franc\Anaconda3\lib\site-packages\PIL\ImageOps.py", line 392, in invert return _lut(image, lut) File "C:\Users\franc\Anaconda3\lib\site-packages\PIL\ImageOps.py", line 49, in _lut if image.mode == "P": File "C:\Users\franc\Anaconda3\lib\site-packages\pydicom\dataset.py", line 476, in __getattr__ return super(Dataset, self).__getattribute__(name) AttributeError: 'FileDataset' object has no attribute 'mode'
The image displays because of:

plt.imshow(image.pixel_array, cmap=plt.cm.gray)
I've tried seemingly everything. Some lines of code have been commented out to try to diagnose the problem.
Reply


Messages In This Thread
Trying to invert DICOM image with Python 3.6 - by newmanf - Feb-28-2018, 08:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Upload image to Instagram using python/selenium using image URL failed, need help greenpine 5 5,544 Feb-22-2022, 09:42 PM
Last Post: snippsat
  Dicom Files spillai 2 2,047 Oct-12-2021, 06:00 PM
Last Post: menator01
  How to invert scatter plot axis Mark17 3 2,585 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  5 variants to invert dictionaries with non-unique values Drakax1 2 2,642 Aug-31-2020, 11:40 AM
Last Post: snippsat
  PIL Image / python-resize-image AttributeError sallyjc81 1 5,051 Aug-02-2020, 12:06 AM
Last Post: scidam
  Invert Pillow image colours chesschaser 5 3,916 Jul-11-2020, 02:59 PM
Last Post: chesschaser
  Dicom image reading smitha 2 3,253 Feb-09-2020, 03:12 AM
Last Post: Larz60+
  How to invert pixel numbers of MNIST data set squillam 1 3,472 Oct-16-2019, 11:18 AM
Last Post: scidam
  DICOM Structure Files jcozzi1 1 2,281 Jul-20-2019, 07:40 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020