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

How to binarize a grayscale image

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 binary numbers. Therefore, it is necessary to convert the captured grayscale image into the binary image.

1. Simple thresholding

The simplest method is to set a threshold value and compare it with the pixel values of a grayscale image. This method is effective for uniform reflectivity. However, in the actual scene, it cannot be robustly binarized due to non-uniform reflectivity and illumination.

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

2. Per-pixel thresholding

Two images are prepared in advance: an image taken with an all-black pattern (including ambient light and the leaked light from the projector) and an image taken with an all-white pattern (including the intensity of reflected light from the projector). The average image of these two images is used as the threshold for each pixel. This method is robustly binaries for non-uniform reflectance and illumination.

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

3. Posi-Nega comparing

For each light pattern, positive and negative patterns are projected, and images are taken. Each pixel is binarized by comparing the value of the positive image with the value of the negative image. This method requires a larger number of projections, but it is the most robust for binarization.

imlist_posi = gray.generate((width, height))
imlist_nega = [ 255-img for img in imlist_posi ]
img_index = gray.decode(imlist_posi, imlist_nega)