Hi !
The DICOM data seems to be in integer format. At least not 0-255. Some of the functions in
OpenCV die with a bad format message when a python pixel_array created from the DICOM
data is passed to a function.
I think it is because the image pixel depth is too big for the functions as I call them.
Is there a switch to throw that would tell the OpenCV function the pixel_data is integer ?
Information would be lost if the data was converted to 0-255 grey-scale.
Best regards,
Phil
Created by Phillip Neal PhilNeal The vast majority of the 640k images have a maximum pixel value set to 4095. Then come ~2k images that have a maximum pixel value equal to 1023. A few occurrences have a maximum pixel value set to different values. The type of the pixel values in the DICOM images is uint16 (0 to 65,535) and not uint8 (0 to 255) as you have figured out.
Here is how to convert an image to uint8 using OpenCV:
```
import numpy as np
import dicom as di
import cv2
base_file = "test.dcm"
ds = di.read_file(base_file)
image = ds.pixel_array
imUint8 = cv2.convertScaleAbs(image, alpha=(255.0/image.max()))
print "IMAGE MAX VALUE: ",imUint8.max() # 255
``` Here is some code :
```
import numpy as np
import dicom as di
#base_file is a dcm file from the pilot data
base_file = "test.dcm"
ds = di.read_file(base_file)
#load the pixel part of ds into an np array
image = ds.pixel_array
#this says uint16
print "DATA TYPE: ",image.dtype
#this says 4095
print "IMAGE MAX VALUE: ",image.max()
```
In any case, I have a python Anaconda install on my Mac. When I tried to install opencv
```
Phillip-Neals-MacBook-Pro:~ pneal$ conda install opencv
Fetching package metadata .......
Solving package specifications: ....
The following specifications were found to be in conflict:
- bottleneck -> numpy 1.10*|1.11*|1.9*
- bottleneck -> python 3.4*|3.5*
- opencv
```
So I think I will stick with 'scikit-image' and shift everything into the 0-255 range.
Welcome to the DM DREAM Challenge Phil!
Do you have some code that you can share to illustrate your issue?