Skip to content
Ryota MAEDA edited this page Aug 13, 2020 · 14 revisions

How to binarize a grayscale image?

In order to find the corresponding points between the projector and the camera, we need to know the code at each pixel position in the image. Some of the codes (Binary, Gray, XOR, ...) are specified in binary numbers. Therefore, it is necessary to convert the captured grayscale image into binary images.

1. Simple thresholding

The simplest method is to set a threshold value and compare it with the pixel values of a grayscale image.

imgs_code = gray.generate((width, height))
decode    = gray.decode(imgs_code, thresh=127)

This method is effective for uniform reflectivity. However, in the actual scene, it cannot be robustly binarized due to uneven reflectivity and illumination.

2. Per-pixel thresholding

imgs_code = gray.generate((width, height))
img_white = np.full((width, height), 255, dtype=np.uint8)
img_black = np.full((width, height),  0 , dtype=np.uint8)
img_thresh = 0.5*img_white + 0.5*img_black
decode    = gray.decode(imgs_code, thresh=img_thresh)

3. Posi-Nega comparing

Clone this wiki locally