ivoflipse / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 1 forks source link

NumPy support enhancement/bugfixes #79

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I suggest the following improvements in dataset.py:
(related bugfix: with the current implementation, a DICOM file based on a
16-bit unsigned data array will be converted into a 16-bits *signed* array)

* deprecated code (lines 76-78):
    # Map image_dataset.BitsAllocated to NumPy typecode
    if have_numpy:
        NumpyPixelFormats = {8: numpy.uint8, 16:numpy.int16, 32:numpy.int32}

* deprecated code (lines 320-322):
            if self.BitsAllocated not in self.NumpyPixelFormats:
                raise NotImplementedError, "Do not have NumPy dtype for
BitsAllocated=%d, please update Dataset.NumpyPixelFormats" % self.BitsAllocated
            format = self.NumpyPixelFormats[self.BitsAllocated]

* new suggested code (from line 320):
            format_str = '%sint%s' % (('u', '')[self.PixelRepresentation],
                                      self.BitsAllocated)
            try:
                format = numpy.dtype(format_str)
            except TypeError:
                raise TypeError("Data type not understood by NumPy: "
                                "PixelRepresentation=%d, BitsAllocated=%d" % (
                                self.PixelRepresentation, self.BitsAllocated))

That's more generic and it works for most of the available data types (at
least a lot more than the current implementation).

Thanks!

Original issue reported on code.google.com by pierre.raybaut on 1 Mar 2010 at 1:20

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 5f0c9d743b.

Original comment by darcymason@gmail.com on 6 Mar 2010 at 2:29