Multiview image processing

These methods perform image processing operations on stereo images.

class machinevisiontoolbox.ImageMultiview.ImageMultiviewMixin[source]
stereo_simple(right, hw, drange)[source]

Simple stereo matching

Parameters
  • right (Image) – right image

  • hw (int) – window half width

  • drange (array_like(2)) – disparity range

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 imagesm and whose third dimension is the number of disparities. Each fibre DSI[v,u,:] is window similarity versus disparity.

Example:

>>> 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.

References
  • Robotics, Vision & Control for Python, Section 14.4, P. Corke, Springer 2023.

Warning

Not fast.

Seealso

DSI_refine stereo_BM stereo_SGBM

classmethod DSI_refine(DSI, drange=None)[source]

Refine disparity from disparity space image

Parameters
  • DSI (ndarray(H,W,D)) – disparity space image

  • drange (array_like(2), optional) – disparity range, defaults to span of DSI values

Returns

refined disparity image

Return type

Image

Performs subpixel interpolation on the peaks in the DSI to provide disparity estimates to a fraction of a pixel.

Example:

>>> 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])
>>> disparity = Image.DSI_refine(DSI)
References
  • Robotics, Vision & Control for Python, Section 14.4.1, P. Corke, Springer 2023.

Seealso

stereo_simple

stereo_BM(right, hw, drange, speckle=None)[source]

Stereo block matching

Parameters
  • right (Image) – right image

  • hw (int) – window half width

  • drange (array_like(2)) – disparity range

  • speckle (array_like(2), optional) – speckle filter parameters, defaults to None

Raises

ValueError – block size too small

Returns

disparity image

Return type

Image

This is an efficient block-matching stereo implementation. It returns the disparity image, same size as input images, whose elements give the subpixel-interpolated disparity (in pixels) of the corresponding point in the left image.

Speckle are small regions of anomalous disparity. A speckle is defined as less than A pixels with disparity variation less than V, and the filter parameters are (A, V). The disparity values within a detected speckle are set to that of its enclosing region.

Example:

>>> rocks_l = Image.Read("rocks2-l.png", reduce=2)
>>> rocks_r = Image.Read("rocks2-r.png", reduce=2)
>>> disparity = rocks_l.stereo_BM(rocks_r, hw=3, drange=[40, 90], speckle=(200, 2))

Note

The images are assumed to be epipolar aligned.

References
  • Robotics, Vision & Control for Python, Section 14.4.2.7, P. Corke, Springer 2023.

Seealso

stereo_SGBM stereo_simple opencv.StereoBM

stereo_SGBM(right, hw, drange, speckle=None)[source]

Stereo semi-global block matching

Parameters
  • right (Image) – right image

  • hw (int) – window half width

  • drange (array_like(2)) – disparity range

  • speckle (array_like(2), optional) – speckle filter parameters, defaults to None

Raises

ValueError – block size too small

Returns

disparity image

Return type

Image

This is an efficient semi-global block-matching stereo implementation. It returns the disparity image, same size as input images, whose elements give the subpixel-interpolated disparity (in pixels) of the corresponding point in the left image.

Speckle are small regions of anomalous disparity. A speckle is defined as less than A pixels with disparity variation less than V, and the filter parameters are (A, V). The disparity values within a detected speckle are set to that of its enclosing region.

Example:

>>> rocks_l = Image.Read("rocks2-l.png", reduce=2)
>>> rocks_r = Image.Read("rocks2-r.png", reduce=2)
>>> disparity = rocks_l.stereo_SGBM(rocks_r, hw=3, drange=[40, 90], speckle=(200, 2))

Note

The images are assumed to be epipolar aligned.

References
  • Stereo processing by semiglobal matching and mutual information, Heiko Hirschmuller, IEEE Transactions on Pattern Analysis and Machine Intelligence, 30(2):328–341, 2008.

  • Robotics, Vision & Control for Python, Section 14.4.2.7, P. Corke, Springer 2023.

Seealso

stereo_SGBM stereo_simple opencv.StereoSGBM

rectify_homographies(m, F)[source]

Create rectification homographies

Parameters
  • m (FeatureMatch) – corresponding points

  • F (ndarray(3,3)) – fundamental matrix

Returns

rectification homographies

Return type

ndarray(3,3), ndarray(3,3)

Given the epipolar geometry between two images, defined by the fundamental matrix and corresponding points, compute a pair of homographies that can be used to rectify the images so that they are epipolar aligned.

Examples:

>>> walls_l = Image.Read('walls-l.png', reduce=2)
>>> walls_r = Image.Read('walls-r.png', reduce=2)
>>> sf_l = walls_l.SIFT()
>>> sf_r = walls_r.SIFT()
>>> matches = sf_l.match(sf_r);
>>> F, resid = matches.estimate(CentralCamera.points2F, method="ransac", confidence=0.95);
>>> H_l, H_r = walls_l.rectify_homographies(matches, F)
>>> walls_l_rect = walls_l.warp_perspective(H_l)
>>> walls_r_rect = walls_r.warp_perspective(H_r)
References
  • Robotics, Vision & Control for Python, Section 14.4.3, P. Corke, Springer 2023.

Seealso

warp_perspective Match opencv.stereoRectifyUncalibrated