I'm trying to read a 16 bit grayscale image using OpenCV 2.4 in Python, but it seems to be loading it as 8 bit.
I'm doing:
im = cv2.imread(path,0) print im [[25 25 28 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] ...,
How do I get it as 16 bit?
When you scan in black and white or grayscale, Colortrac wide format scanners scan in 16-bit grayscale. This means that they capture over 65,000 shades of gray. The 65,000 shades of gray are then reduced down to two to create a black and white image (called 1-bit) or to 256 to create an 8-bit grayscale image.
Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2. cvtcolor() function.
It is the default flag. Alternatively, we can pass integer value 1 for this flag. cv2. IMREAD_GRAYSCALE: It specifies to load an image in grayscale mode. Alternatively, we can pass integer value 0 for this flag.
Figured it out. In case anyone else runs into this problem:
im = cv2.imread(path,-1)
Setting the flag to 0, to load as grayscale, seems to default to 8 bit. Setting the flag to -1 loads the image as is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With