Tutorial Hit-or-Miss
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
Hit-or-Miss {#tutorial_hitOrMiss}
|
||||
=================================
|
||||
|
||||
@prev_tutorial{tutorial_opening_closing_hats}
|
||||
@next_tutorial{tutorial_morph_lines_detection}
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to find a given configuration or pattern in a binary image by using the Hit-or-Miss transform (also known as Hit-and-Miss transform).
|
||||
This transform is also the basis of more advanced morphological operations such as thinning or pruning.
|
||||
|
||||
We will use the OpenCV function @ref cv::morphologyEx.
|
||||
|
||||
|
||||
We will use the OpenCV function **morphologyEx()** .
|
||||
|
||||
Hit-or-Miss theory
|
||||
-------------------
|
||||
|
||||
Morphological operators process images based on their shape. These operators apply one or more *structuring elements* to an input image to obtain the output image.
|
||||
The two basic morphological operations are the *erosion* and the *dilation*. The combination of these two operations generate advanced morphological transformations such as *opening*, *closing*, or *top-hat* transform.
|
||||
To know more about these and other basic morphological operations refer to previous tutorials @ref tutorial_erosion_dilatation "here" and @ref tutorial_opening_closing_hats "here".
|
||||
To know more about these and other basic morphological operations refer to previous tutorials (@ref tutorial_erosion_dilatation "Eroding and Dilating") and (@ref tutorial_opening_closing_hats "More Morphology Transformations").
|
||||
|
||||
The Hit-or-Miss transformation is useful to find patterns in binary images. In particular, it finds those pixels whose neighbourhood matches the shape of a first structuring element \f$B_1\f$
|
||||
while not matching the shape of a second structuring element \f$B_2\f$ at the same time. Mathematically, the operation applied to an image \f$A\f$ can be expressed as follows:
|
||||
@@ -43,11 +44,27 @@ You can see that the pattern is found in just one location within the image.
|
||||
Code
|
||||
----
|
||||
|
||||
The code corresponding to the previous example is shown below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/ImgProc/HitMiss.cpp)
|
||||
@include samples/cpp/tutorial_code/ImgProc/HitMiss.cpp
|
||||
The code corresponding to the previous example is shown below.
|
||||
|
||||
As you can see, it is as simple as using the function @ref cv::morphologyEx with the operation type @ref cv::MORPH_HITMISS and the chosen kernel.
|
||||
@add_toggle_cpp
|
||||
You can also download it from
|
||||
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/ImgProc/HitMiss/HitMiss.cpp)
|
||||
@include samples/cpp/tutorial_code/ImgProc/HitMiss/HitMiss.cpp
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
You can also download it from
|
||||
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/ImgProc/HitMiss/HitMiss.java)
|
||||
@include samples/java/tutorial_code/ImgProc/HitMiss/HitMiss.java
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
You can also download it from
|
||||
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/imgProc/HitMiss/hit_miss.py)
|
||||
@include samples/python/tutorial_code/imgProc/HitMiss/hit_miss.py
|
||||
@end_toggle
|
||||
|
||||
As you can see, it is as simple as using the function **morphologyEx()** with the operation type **MORPH_HITMISS** and the chosen kernel.
|
||||
|
||||
Other examples
|
||||
--------------
|
||||
|
||||
@@ -29,7 +29,9 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
Here we investigate different morphology operators
|
||||
|
||||
- @subpage tutorial_hitOrMiss
|
||||
- @subpage tutorial_hitOrMiss
|
||||
|
||||
*Languages:* C++, Java, Python
|
||||
|
||||
*Compatibility:* \> OpenCV 2.4
|
||||
|
||||
|
||||
Reference in New Issue
Block a user