pydicom

Python convert .dcm to .png, images are too bright

做~自己de王妃 提交于 2020-02-24 11:14:45
问题 I have to convert some files which come by default as .dcm to .png , I've found some code samples to achieve that around here but the end results are too bright. Could anybody have a look at this, please? def convert_to_png(file): ds = pydicom.dcmread(file) shape = ds.pixel_array.shape # Convert to float to avoid overflow or underflow losses. image_2d = ds.pixel_array.astype(float) # Rescaling grey scale between 0-255 image_2d_scaled = (np.maximum(image_2d,0) / image_2d.max()) * 255.0 #

Unable to get dicom image for display in python

帅比萌擦擦* 提交于 2020-01-14 16:47:41
问题 I'm trying to display a DICOM image in opencv-python.I am using the pydicom library,And then adding API's to create a full fledged DICOM viewer with DOTNET, that runs python(C# calls python with process instance of course!!). I am unable to convert or see the uncompressed DICOM image. whenever i try to load or modify the pixel_array. I get error messges. import dicom import cv2 import numpy df=dicom.read_file("IM-0001-0002.dcm") df.pixel_array Traceback (most recent call last): File "<pyshell

Unable to get dicom image for display in python

拟墨画扇 提交于 2020-01-14 16:46:12
问题 I'm trying to display a DICOM image in opencv-python.I am using the pydicom library,And then adding API's to create a full fledged DICOM viewer with DOTNET, that runs python(C# calls python with process instance of course!!). I am unable to convert or see the uncompressed DICOM image. whenever i try to load or modify the pixel_array. I get error messges. import dicom import cv2 import numpy df=dicom.read_file("IM-0001-0002.dcm") df.pixel_array Traceback (most recent call last): File "<pyshell

How to extract/view all frames of a multi-frame DICOM file?

纵然是瞬间 提交于 2019-12-13 14:01:02
问题 I know I can view a dicom file using following code: import dicom from dicom.contrib.pydicom_PIL import show_PIL f = "CT-MONO2-8-abdo.dcm" ds = dicom.read_file(f, force=True) show_PIL(ds) However, how can I extract and view all frames from a multi-frame DICOM file? I tried using above code but got following error: File "/home/auser/.local/lib/python3.5/site-packages/dicom/dataset.py", line 399, in _get_pixel_array raise NotImplementedError("Pixel Data is compressed in a format pydicom does

How to divide in half pydicom files (image) using python?

走远了吗. 提交于 2019-12-13 03:49:33
问题 I have a lot of images (pydicom files). I would like to divide in half. From 1 image, I would like 2 images: part left and part right. Input: 1000x1000 Output: 500x1000 (width x height). Currently, I can only read a file. ds = pydicom.read_file(image_fps[0]) # read dicom image from filepath First part, I would like to put half in one folder and the other half to second. This is what I have: enter image description here This is what I want: enter image description here I use Mask-RCNN to

Extract sagittal and coronal cuts from axial view using pydicom

放肆的年华 提交于 2019-12-13 03:45:25
问题 I am trying to read a series of .dcm files which are by default show axial view. Below is the code: import os import numpy as np import pydicom as dicom from matplotlib import pyplot as plt root_dir = 'mydcomDir' def sortDcm(): print('Given Path to the .dcm directory is: {}'.format(root_dir)) slices = [dicom.read_file(root_dir + '/' + s) for s in os.listdir(root_dir)] slices.sort(key = lambda x: float(x.ImagePositionPatient[2])) pos1 = slices[int(len(slices)/2)].ImagePositionPatient[2] pos2 =

pydicom module not found by python

ⅰ亾dé卋堺 提交于 2019-12-13 01:48:02
问题 The error message: In [1]: import pydicom as dicomio --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-1-102814c2908e> in <module>() ----> 1 import pydicom as dicomio ImportError: No module named pydicom To install pydicom I used conda skeleton pypi pydicom conda build pydicom Then uploaded to binstar and used conda install -c to download and install it again. It can now be seen in the anaconda environment.

pydicom 'Dataset' object has no attribute 'TransferSyntaxUID'

☆樱花仙子☆ 提交于 2019-12-11 08:00:41
问题 I'm using pydicom 1.0.0a1, downloaded from here, When I run the following code: ds=pydicom.read_file('./DR/abnormal/abc.dcm',force=True) ds.pixel_array this error occurs: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-d4e81d303439> in <module>() 7 ds=pydicom.read_file('./DR/abnormal/abc.dcm',force=True) 8 ----> 9 ds.pixel_array 10 /Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1

What is the difference between ds.get() and ds.get_item() in pydicom

泪湿孤枕 提交于 2019-12-11 06:16:58
问题 Does anyone know what is the difference in Pydicom between the two methods FileDataset.get() and FileDataset.get_item() ? Thanks! 回答1: Both of these are not used often in user code. Dataset.get is the equivalent of python's dict.get; it allows you to ask for an item in the dictionary, but return a default if that item does not exist in the Dataset. The more usual way to get an item from a Dataset is to use the dot notation, e.g. dataset.PatientName or to get the DataElement object via the tag

How to fix encoding issues of pydicom in python

风流意气都作罢 提交于 2019-12-07 20:31:48
问题 This is the code: import dicom ds = dicom.read_file(FILE_PATH) print(ds) Error: LookupError: unknown encoding: ISO 2022 IR 100 When using pydicom in order to look at data, I got the error above. I found 'ISO 2022 IR 100': 'latin_1' ,according to here. However, I didn't get how to fix this problem. Can you help me to solve this error? 回答1: As indicated in the comments, the culprit was an out-of-date version of pydicom. Upgrading to a more recent version fixed this issue. 来源: https:/