0.9 OpenCvSharp4图像阈值

    科技2023-10-08  84

    0.9 OpenCvSharp4图像阈值

      阈值(Threshold):将图像分割的标尺。

    // // 摘要: // Thresholding type [Flags] public enum ThresholdTypes { // // 摘要: // \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] Binary = 0, // // 摘要: // \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f] BinaryInv = 1, // // 摘要: // \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] Trunc = 2, // // 摘要: // \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] Tozero = 3, // // 摘要: // \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] TozeroInv = 4, Mask = 7, // // 摘要: // flag, use Otsu algorithm to choose the optimal threshold value Otsu = 8, // // 摘要: // flag, use Triangle algorithm to choose the optimal threshold value Triangle = 16 }

    // // 摘要: // Applies a fixed-level threshold to each array element. // // 参数: // src: // input array (single-channel, 8-bit or 32-bit floating point). // // dst: // output array of the same size and type as src. // // thresh: // threshold value. // // maxval: // maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding // types. // // type: // thresholding type (see the details below). // // 返回结果: // the computed threshold value when type == OTSU public static double Threshold(InputArray src, OutputArray dst, double thresh, double maxval, ThresholdTypes type);

    实现:

    Mat gray = new Mat(srt.Size(), srt.Type()); Cv2.CvtColor(srt, gray, ColorConversionCodes.BGR2GRAY); Cv2.Threshold(gray,dst, 175, 255,ThresholdTypes.Binary);

    参考 opencv学习(二十八)之基本图像阈值操作threshold

    Processed: 0.015, SQL: 8