Image.stereo_simple#

Image.stereo_simple(right: Image, hw: int, drange: tuple[int, int] | list[int] | int) → tuple[Self, Self, np.ndarray][source]#

Simple stereo matching

Parameters:
  • right (Image) – right image

  • hw (int) – window half width

  • drange (array_like(2) or int) – disparity range (minimum, maximum), or a single integer n which means (0, n)

Returns:

disparity image, similarity image, disparity space image

Return type:

Image, Image, ndarray(H,W,D)

This is a simple stereo matching implementation for pedagogical purposes. It returns:

  • the disparity image, same size as input images, whose elements give the integer disparity (in pixels) of the corresponding point in the left image.

  • the similarity image, same size as input images, whose elements give the strength of the stereo match. This is a ZNCC measure where 1 is a perfect match, greater than 0.8 is a decent match.

  • the disparity space image, a 3D array, whose first two dimensions are the same size as the input images and whose third dimension is the number of disparities. Each fibre DSI[v,u,:] is window similarity versus disparity.

Examples

rocks_l = Image.Read("rocks2-l.png", reduce=2)
rocks_r = Image.Read("rocks2-r.png", reduce=2)
disparity, similarity, DSI = rocks_l.stereo_simple(rocks_r, hw=3, drange=[40, 90])

Note

The images are assumed to be epipolar aligned.

Note

The disparity and similarity images, and each plane of the DSI, have a band of hw NaN valued pixels along the top, bottom and right edges, where the window extends beyond the image. The band along the left edge is hw + drange[0] wide for the disparity and similarity images, and hw + drange[0] + d wide for the DSI plane of disparity d (counting from 0), since the shifted window in the right image must also lie within the image.

References

Warning

Not fast.

Changed in version 2.5.0: The outputs are the same size as the input images, as documented. Previously they were larger by 2*hw in each direction, with the result for pixel (u, v) at (u+hw, v+hw). The disparity at a pixel is now the best of its valid disparities, and NaN only if none are valid, and an integer image is padded with NaN instead of 0, so windows that extend beyond the image are invalid for every image type.