Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - Reading a 16 bit grayscale image

Tags:

python

opencv

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?

like image 965
Kkov Avatar asked Jun 10 '12 14:06

Kkov


People also ask

How many grayscale values does a 16 bit image have?

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.

How do I open an image in grayscale in OpenCV?

Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2. cvtcolor() function.

What is cv2 Imread_grayscale?

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.


1 Answers

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.

like image 193
Kkov Avatar answered Sep 20 '22 00:09

Kkov