Image.hitormiss#
- Image.hitormiss(s1: ndarray, s2: ndarray | None = None, border: str = 'replicate', bordervalue: float = 0, **kwargs: Any) Self[source]#
Hit or miss transform
- Parameters:
s1 (ndarray(N,M)) – structuring element 1
s2 (ndarray(N,M)) – structuring element 2
kwargs – arguments passed to
opencv.morphologyEx
- Returns:
transformed image
- Return type:
Return the hit-or-miss transform of the binary image which is defined by two structuring elements structuring elements
\[Y = (X \ominus S_1) \cap (X \ominus S_2)\]which is the logical-and of the binary image and its complement, eroded by two different structuring elements. This preserves pixels where ones in the window are consistent with \(S_1\) and zeros in the window are consistent with \(S_2\).
- If only
s1is provided it has three possible values: 1, must match a non-zero value
-1, must match a zero value
0, don’t care, matches any value.
Example:
>>> from machinevisiontoolbox import Image >>> import numpy as np >>> pixels = np.array([[0,0,1,0,1,1],[1,1,1,1,0,1],[0,1,0,1,1,0],[1,1,1,1,0,0],[0,1,1,0,1,0]]) >>> img = Image(pixels) >>> img.print() 0 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 1 1 0 0 0 1 1 0 1 0 >>> se = np.array([[0,1,0],[1,-1,1],[0,1,0]]) >>> se array([[ 0, 1, 0], [ 1, -1, 1], [ 0, 1, 0]]) >>> img.hitormiss(se).print() 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0
Note
For the single argument case
s1\(=S_1 - S_2\).- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.6.3.
Important
Uses OpenCV function
cv2.morphologyEx(withMORPH_HITMISS) which accepts single-channel, CV_8U or CV_16S images.- Seealso: