Learn Threshold Operation


double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Applies a fixed-level threshold to each array element
Parameters:
  • src – input array (single-channel, 8-bit or 32-bit floating point).
  • dst – output array of the same size as well as type every bit src.
  • threshthreshold value.
  • maxval – maximum value to role amongst the THRESH_BINARY as well as THRESH_BINARY_INV thresholding types.
  • typethresholding type
  • THRESH_BINARY
     output array of the same size as well as type every bit  Learn Threshold operation
  • THRESH_BINARY_INV
     output array of the same size as well as type every bit  Learn Threshold operation
  • THRESH_TRUNC
     output array of the same size as well as type every bit  Learn Threshold operation
  • THRESH_TOZERO
     output array of the same size as well as type every bit  Learn Threshold operation
  • THRESH_TOZERO_INV
     output array of the same size as well as type every bit  Learn Threshold operation
Find an instance inwards OpenCV documentaion.

Steps:

  1. Load an image
  2. Create a window to display results
  3. Create Trackbar to conduct type of Threshold
  4. Call the component "Threshold_Demo" to perform threshold operation.

Functions:

    Example:

    ------------
    #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h>  using namespace cv;  int threshold_value = 0; int threshold_type = 3;; int const max_value = 255; int const max_type = 4; int const max_BINARY_value = 255;  Mat src, src_gray, dst; char* window_name = "Threshold Demo";  char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted"; char* trackbar_value = "Value";  void Threshold_Demo( int, void* );  int main( int argc, char** argv ) {   /// Load an icon   src = imread( "shape.jpg", i );    /// Convert the icon to Gray   cvtColor( src, src_gray, CV_RGB2GRAY );    /// Create a window to display results   namedWindow( window_name, CV_WINDOW_AUTOSIZE );    /// Create Trackbar to conduct type of Threshold   createTrackbar( trackbar_type,                   window_name, &threshold_type,                   max_type, Threshold_Demo );    createTrackbar( trackbar_value,                   window_name, &threshold_value,                   max_value, Threshold_Demo );    /// Call the component to initialize   Threshold_Demo( 0, 0 );    /// Wait until user finishes plan   while(true)   {     int c;     c = waitKey( xx );     if( (char)c == 27 )       { break; }    } }   void Threshold_Demo( int, void* ) {   /* 0: Binary      1: Binary Inverted      2: Threshold Truncated      3: Threshold to Zero      4: Threshold to Zero Inverted    */    threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );    imshow( window_name, dst ); } 
    ------------

    Result:


    Sources:
    http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html

    Comments

    Popular posts from this blog

    Accueil Technologie Ct 1.2 - Frauder Une Ou Des Hypothèses Rasé Matérialiser À Une Croix Ou À Un Irradiant Démarquage

    Accueil Technologie Ct 1.1 - Imaginer, Synthétiser, Formaliser Et Engorger Une Procédure, Un Protocole.

    Accueil Technologie Satisfecit Exonérer Ma Spontanément ?