0

I am using pydicom for extracting image data out of a dicom file. Unfortunately pydicom fails to directly extract a numpy array of data I can directly use, but I get a data string containing all values in hex (i.e. f.eks. \x03\x80\x01\x0c\xa0\x00\x02P\x00\x04@\x00\t\x80\x00\x03.... I know that the image data is encoded in a JPEG2000-format. Is there a way to reconstruct an image out of these data? I already tried via

img = Image.fromstring('RGB', len(pixelData), pixelData)

but there I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2064, in fromstring
    return frombytes(*args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2049, in frombytes
    im = new(mode, size)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2015, in new
    return Image()._new(core.fill(mode, size, color))
TypeError: must be 2-item sequence, not int

Is there another way to create an image out of these data?

Suever
  • 64,497
  • 14
  • 82
  • 101
arc_lupus
  • 3,942
  • 5
  • 45
  • 81
  • I think the second argument to `Image.fromstring` should be the width/height size, not the length. Try `Image.fromstring('RGB', (100,100), pixelData)` – Kedar Mar 08 '15 at 15:09

2 Answers2

1

Second parameter (size) to Image.fromstring should be 2-tuple with height and width:

  :param size: A 2-tuple, containing (width, height) in pixels.
ndpu
  • 22,225
  • 6
  • 54
  • 69
0

Unfortunately pydiacom has issues with JPEG compression. Is there no way of making the images TIFF or some other uncompressed format? Is it scan data?

DrBwts
  • 3,470
  • 6
  • 38
  • 62