threshold

来源:互联网 发布:淘宝号被冻结解冻方法 编辑:程序博客网 时间:2024/05/18 14:12

Applies a fixed-level threshold to each array element.

C++: double threshold(InputArraysrc, OutputArray dst, double thresh, doublemaxval, int type)

Python:cv2.threshold(src, thresh, maxval, type[, dst]) → retval, dst

C: double cvThreshold(const CvArr*src, CvArr* dst, double threshold, doublemax_value, int threshold_type)

Python:cv.Threshold(src, dst,threshold, maxValue, thresholdType) → None
Parameters:
  • src – input array (single-channel, 8-bit or 32-bit floating point).
  • dst – output array of the same size and type as src.
  • threshthreshold value.
  • maxval – maximum value to use with the THRESH_BINARY and THRESH_BINARY_INVthresholding types.
  • typethresholding type (see the details below).

The function applies fixed-level thresholdingto a single-channel array. The function is typically used to get abi-level (binary) image out of a grayscale image (compare() couldbe also used for this purpose) or for removing a noise, that is, filteringout pixels with too small or too large values. There are severaltypes ofthresholding supported by the function. They are determined bytype :

  • THRESH_BINARY

    \texttt{dst} (x,y) =  \fork{\texttt{maxval}}{if $\texttt{src}(x,y) > \texttt{thresh}$}{0}{otherwise}

  • THRESH_BINARY_INV

    \texttt{dst} (x,y) =  \fork{0}{if $\texttt{src}(x,y) > \texttt{thresh}$}{\texttt{maxval}}{otherwise}

  • THRESH_TRUNC

    \texttt{dst} (x,y) =  \fork{\texttt{threshold}}{if $\texttt{src}(x,y) > \texttt{thresh}$}{\texttt{src}(x,y)}{otherwise}

  • THRESH_TOZERO

    \texttt{dst} (x,y) =  \fork{\texttt{src}(x,y)}{if $\texttt{src}(x,y) > \texttt{thresh}$}{0}{otherwise}

  • THRESH_TOZERO_INV

    \texttt{dst} (x,y) =  \fork{0}{if $\texttt{src}(x,y) > \texttt{thresh}$}{\texttt{src}(x,y)}{otherwise}

Also, the special value THRESH_OTSU may be combined withone of the above values. In this case, the function determines the optimalthresholdvalue using the Otsu’s algorithm and uses it instead of the specifiedthresh .The function returns the computed threshold value.Currently, the Otsu’s method is implemented only for 8-bit images.

../../../_images/threshold.png

See also

adaptiveThreshold(),findContours(),compare(),min(),max()

0 0
原创粉丝点击