I was playing around with PIL to get an appropriate palette for image display. I discovered that if I
create a LUT (based on the DICOM spec Part 3: Section C.11.2.1.2) and map the array pixel values
to this LUT via a Numpy piecewise function; then pass that array to PIL as an array instead of a
buffer, I was able to get the correct palette.
This requires the DICOM image to have the Window Width and Window Center attributes present in
the dataset. Unfortunately, the only problem is that I cannot make "image_dfl.dcm" work with this
method. I tried implementing a fallback with the existing code, but it seems this image does have
the Window Width/Center attributes so it uses the new code.
I attached a diff of the changes and also an image comparing the PIL version to what OsiriX shows
using Quick Look.
I tested this on Python 2.5.4 (32-bit) on Mac OS X 10.6 using numpy 1.3.0 and PIL 1.1.7b1.
From dicompy...@gmail.com on September 14, 2009 01:12:50
I was playing around with PIL to get an appropriate palette for image display. I discovered that if I create a LUT (based on the DICOM spec Part 3: Section C.11.2.1.2) and map the array pixel values to this LUT via a Numpy piecewise function; then pass that array to PIL as an array instead of a buffer, I was able to get the correct palette.
This requires the DICOM image to have the Window Width and Window Center attributes present in the dataset. Unfortunately, the only problem is that I cannot make "image_dfl.dcm" work with this method. I tried implementing a fallback with the existing code, but it seems this image does have the Window Width/Center attributes so it uses the new code.
I attached a diff of the changes and also an image comparing the PIL version to what OsiriX shows using Quick Look.
I tested this on Python 2.5.4 (32-bit) on Mac OS X 10.6 using numpy 1.3.0 and PIL 1.1.7b1.
Attachment: image.diff Screen shot 2009-09-13 at 11.44.50 PM.png
Original issue: http://code.google.com/p/pydicom/issues/detail?id=56