Hit and Miss morphological op

pull/5622/head
Lorena García 9 years ago
parent 33dc41056f
commit 252feb4774
  1. 4
      modules/imgproc/doc/filtering.rst
  2. 2
      modules/imgproc/include/opencv2/imgproc/imgproc.hpp
  3. 20
      modules/imgproc/src/morph.cpp

@ -1231,6 +1231,8 @@ Performs advanced morphological transformations.
* **MORPH_BLACKHAT** - "black hat" * **MORPH_BLACKHAT** - "black hat"
* **MORPH_HITMISS** - "hit and miss"
:param iterations: Number of times erosion and dilation are applied. :param iterations: Number of times erosion and dilation are applied.
:param borderType: Pixel extrapolation method. See :ocv:func:`borderInterpolate` for details. :param borderType: Pixel extrapolation method. See :ocv:func:`borderInterpolate` for details.
@ -1269,6 +1271,8 @@ Morphological gradient:
\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src} \texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}
"Hit and Miss": Only supported for CV_8UC1 binary images. Tutorial can be found in this page: http://opencv-code.com/tutorials/hit-or-miss-transform-in-opencv/
Any of the operations can be done in-place. In case of multi-channel images, each channel is processed independently. Any of the operations can be done in-place. In case of multi-channel images, each channel is processed independently.
.. seealso:: .. seealso::

@ -352,7 +352,7 @@ CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double
enum { MORPH_ERODE=CV_MOP_ERODE, MORPH_DILATE=CV_MOP_DILATE, enum { MORPH_ERODE=CV_MOP_ERODE, MORPH_DILATE=CV_MOP_DILATE,
MORPH_OPEN=CV_MOP_OPEN, MORPH_CLOSE=CV_MOP_CLOSE, MORPH_OPEN=CV_MOP_OPEN, MORPH_CLOSE=CV_MOP_CLOSE,
MORPH_GRADIENT=CV_MOP_GRADIENT, MORPH_TOPHAT=CV_MOP_TOPHAT, MORPH_GRADIENT=CV_MOP_GRADIENT, MORPH_TOPHAT=CV_MOP_TOPHAT,
MORPH_BLACKHAT=CV_MOP_BLACKHAT }; MORPH_BLACKHAT=CV_MOP_BLACKHAT, MORPH_HITMISS };
//! returns horizontal 1D morphological filter //! returns horizontal 1D morphological filter
CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1); CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1);

@ -1374,6 +1374,8 @@ void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
_dst.create(src.size(), src.type()); _dst.create(src.size(), src.type());
Mat dst = _dst.getMat(); Mat dst = _dst.getMat();
Mat k1, k2, e1, e2; //only for hit and miss op
switch( op ) switch( op )
{ {
case MORPH_ERODE: case MORPH_ERODE:
@ -1409,6 +1411,24 @@ void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
erode( temp, temp, kernel, anchor, iterations, borderType, borderValue ); erode( temp, temp, kernel, anchor, iterations, borderType, borderValue );
dst = temp - src; dst = temp - src;
break; break;
case MORPH_HITMISS:
CV_Assert(src.type() == CV_8UC1);
k1 = (kernel.getMat() == 1);
k2 = (kernel.getMat() == -1);
if (countNonZero(k1) <= 0)
e1 = src;
else
erode(src, e1, k1, anchor, iterations, borderType, borderValue);
if (countNonZero(k2) <= 0)
e2 = src;
else
{
Mat src_complement;
bitwise_not(src, src_complement);
erode(src_complement, e2, k2, anchor, iterations, borderType, borderValue);
}
dst = e1 & e2;
break;
default: default:
CV_Error( CV_StsBadArg, "unknown morphological operation" ); CV_Error( CV_StsBadArg, "unknown morphological operation" );
} }

Loading…
Cancel
Save