Hit or Miss

Include <mln/morpho/hit_or_miss.hpp>

Image{I}
image_concrete_t<I> hit_or_miss(I image, StructuringElement se_hit, StructuringElement se_miss)
void hit_or_miss(Image image, StructuringElement se_hit, StructuringElement se_miss, OutputImage out)

The hit-or-miss transform is non-linerar filter used to detect pattern in images. It is defined as:

\[UHTM_\mathcal{B}(f)(x) = \begin{cases} \varepsilon_{B_{fg}}(x) - \delta_{B_{bg}}(x) & \mathrm{if} \varepsilon_{B_{fg}}(x) > \delta_{B_{bg}}(x)\newline 0 & otherwise \end{cases}\]

where \($ \mathcal{B} = (B_{fg}, B_{bg})\) is the composite structuring element composed by the two disjoint foreground and background SEs.

  • (2) If the optional output image is provided, it must be wide enough to store the results (the function does not perform any resizing).

param ima:

Input image 𝑓

param se_hit:

Structuring element for the foreground \(B_{fg}\)

param se_miss:

Structuring element for the foreground \(B_{bg}\)

param output (optional):

Output image

return:
  • (1) An image whose type is deduced from the input image

  • (2) Nothing (the output image is passed as an argument)

exception:

N/A

Notes

Complexity

Example 1 : Staff lines selection

Hit or miss transform to detect horizontal 1px-thick line, with pattern:

x x x
o o o
x x x
mln::se::mask2d se_hit  = {{0, 0, 0}, {1, 1, 1}, {0, 0, 0}};
mln::se::mask2d se_miss = {{1, 1, 1}, {0, 0, 0}, {1, 1, 1}};

markers1 = mln::morpho::hit_or_miss(input, se_hit, se_miss);
mln::io::imsave(not markers1, argv[2]);
../_images/staff_lines.png ../_images/morpho_hitormiss_1.png

Hit or miss transform to detect horizontal 2px-thick line, with pattern:

x x x
o o o
o o o
x x x
mln::se::mask2d se_hit  = {{0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}};
mln::se::mask2d se_miss = {{0, 0, 0}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}};

markers2 = mln::morpho::hit_or_miss(input, se_hit, se_miss);
mln::io::imsave(not markers2, argv[3]);
../_images/staff_lines.png ../_images/morpho_hitormiss_2.png

Logical or between the two previous images:

using mln::view::ops;
auto markers = markers1 || markers2;
../_images/staff_lines.png ../_images/staff_lines_markers.png