Questions tagged [pydicom]

pydicom is a pure Python package for working with DICOM files such as medical images, reports, and radiotherapy objects.

pydicom is a pure Python package for working with DICOM files. pydicom makes it easy to read these complex files into natural pythonic structures for easy manipulation. Modified datasets can be written again to DICOM format files.

Resources

276 questions
17
votes
2 answers

How to create JPEG compressed DICOM dataset using pydicom?

I am trying to create a JPEG compressed DICOM image using pydicom. A nice source material about colorful DICOM images can be found here, but it's mostly theory and C++. In the code example below I create a pale blue ellipsis inside output-raw.dcm…
mseimys
  • 588
  • 1
  • 7
  • 16
12
votes
8 answers

Create pydicom file from numpy array

I'm trying to create a new dicom image from a standard-sized (512 x 512 or 256 x 256) numpy array. import dicom, dicom.UID from dicom.dataset import Dataset, FileDataset def write_dicom(pixel_array,filename): file_meta = Dataset() ds =…
Michael K
  • 2,196
  • 6
  • 34
  • 52
10
votes
4 answers

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

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 =…
Terchila Marian
  • 2,225
  • 3
  • 25
  • 48
10
votes
1 answer

Getting DICOM structure contours as array in Python

So if I have an image (CT, MRI, etc.) or even a dose from radiation therapy I can pull out the dose or image values into an array through: import dicom ds = dicom.read_file("dicom_file.dcm") print ds.pixel_array This is pretty straightforward,…
Denver Dang
  • 2,433
  • 3
  • 38
  • 68
8
votes
2 answers

Pydicom.read_file is only working with some Dicom images

I am making a python application that can convert a .dcm image to .jpg using the pydicom library. This is my code: import pydicom import cv2 import numpy as np filename = 'testDicom.dcm' #get pixel data from image ds = pydicom.read_file(filename,…
Max Marcus
  • 106
  • 1
  • 1
  • 4
8
votes
3 answers

2D X-ray reconstruction from 3D DICOM images

I need to write a python function or class with the following Input/Output Input : The position of the X-rays source (still not sure why it's needed) The position of the board (still not sure why it's needed) A three dimensional CT-Scan Output :…
AnaRhisT
  • 103
  • 8
8
votes
1 answer

how to add transfer syntax uid to the filemeta of dataset

I use pydicom library to generate .dcm files using the datasets coming from the CT and MRI machines, however in that dataset, the tag (0002,0010) is missing. As I dont have that tag, I am not able to detect the transfer syntax whether it is implicit…
balaji
  • 774
  • 1
  • 16
  • 42
8
votes
1 answer

How to replace pixel data in same DICOM file using pyDicom to read it again with any DICOM viewer?

I want to read some DICOM files, so I'm testing pydicom for my work, which I think is considerably useful. Now I want to load existing DICOM files, replace the pixel data array with another pixel array (e.g. pre-processing or literally another DICOM…
user8697183
  • 123
  • 1
  • 2
  • 6
6
votes
4 answers

How to Install a Package in PyCharm when project interpreter is set to conda, and the package is not provided/listed by conda?

I installed pycharm on my computer. I set the project interpreter to acaconda3/bin/python because that is the python3 interpreter I used on my computer before installing pycharm. I was able to install all packages I need using pycharm's package…
Semihcan Doken
  • 776
  • 3
  • 10
  • 23
6
votes
2 answers

Adding new DICOM tag with pydicom

I'm trying to convert a slew of DTI siemens DICOMs to NifTi using freesurfer's dcm2nii utility but am failing on some files because they are missing the DiffusionGradientDirection tag (0x19,0x100E), which is necessary to generate the .bvec and .bval…
G Warner
  • 1,309
  • 1
  • 15
  • 27
5
votes
1 answer

Pydicom private tags showing up as 'UN'

When I read a dicom file all the private tags show up with VR of 'UN', instead of whatever they should be. import pydicom filename = 'H:\Fuji.dcm' ds = pydicom.dcmread(filename) print(ds) Gives an output of: ... (0009, 0010) Private Creator …
5
votes
3 answers

PyDICOM can't read pixel data and needs GDCM or Pillow

I'm using pydicom and my code is pretty straightforward: image = np.stack([s.pixel_array for s in scans]) But this gives a runtime error: RuntimeError: The following handlers are available to decode the pixel data however they are missing required…
Shamoon
  • 41,293
  • 91
  • 306
  • 570
5
votes
3 answers

map(float for Resampling DICOM images throwing Multivalue error

I am getting "can only concatenate list (not "MultiValue") to list" highlighting map (float portion, while running below resampling, this code is very commonly used throughout image segmentation like lungs etc, I am thinking maybe this is issue with…
1369
  • 61
  • 1
  • 4
5
votes
3 answers

How to access RGB pixel arrays from DICOM files using pydicom?

I try to access a DICOM file's RGB pixel array with unknown compression (maybe none). Extracting grayscale pixel arrays works completely fine. However, using import dicom import numpy as np data_set = dicom.read_file(path) pixel_array =…
Andreas
  • 307
  • 3
  • 14
4
votes
2 answers

How to read all DICOM attributes/tags with pydicom?

I'm trying to get a list of all the attributes (tags) of a given DICOM instance using pydicom. The list should include the attribute key/id, its vr, the value, and also the corresponding name. For example: Tag: (2,0) VR: UL Name: File Meta…
Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
1
2 3
18 19