码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV Tutorials —— Basic Thresholding Operations

时间:2014-11-18 23:53:21      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   sp   for   div   

bubuko.com,布布扣

 

Threshold Binary

  • This thresholding operation can be expressed as:

    bubuko.com,布布扣

  • So, if the intensity of the pixel bubuko.com,布布扣 is higher than bubuko.com,布布扣, then the new pixel intensity is set to a bubuko.com,布布扣. Otherwise, the pixels are set to bubuko.com,布布扣.

    bubuko.com,布布扣

二分 ~~ 阈值化最朴素的形式

 

Threshold Binary, Inverted

  • This thresholding operation can be expressed as:

    bubuko.com,布布扣

  • If the intensity of the pixel bubuko.com,布布扣 is higher than bubuko.com,布布扣, then the new pixel intensity is set to a bubuko.com,布布扣. Otherwise, it is set to bubuko.com,布布扣.

    bubuko.com,布布扣

反向二分操作

 

Truncate

  • This thresholding operation can be expressed as:

    bubuko.com,布布扣

  • The maximum intensity value for the pixels is bubuko.com,布布扣, if bubuko.com,布布扣 is greater, then its value is truncated. See figure below:

    bubuko.com,布布扣

截短 ———— 发现渐渐调整阈值可以做出很有美感的demo :)

 

Threshold to Zero

  • This operation can be expressed as:

    bubuko.com,布布扣

  • If bubuko.com,布布扣 is lower than bubuko.com,布布扣, the new pixel value will be set to bubuko.com,布布扣.

    bubuko.com,布布扣

 

截短操作的逆操作

Threshold to Zero, Inverted

  • This operation can be expressed as:

    bubuko.com,布布扣

  • If bubuko.com,布布扣 is greater than bubuko.com,布布扣, the new pixel value will be set to bubuko.com,布布扣.

    bubuko.com,布布扣

 

 

#include "stdafx.h"

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

/// Global variables

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";

/// Function headers
void Threshold_Demo( int, void* );

/**
 * @function main
 */
int main( int argc, char** argv )
{
  /// Load an image
  src = imread( "zanxin.jpg", 1 );

  /// Convert the image to Gray
  cvtColor( src, src_gray, CV_RGB2GRAY );

  /// Create a window to display results
  namedWindow( window_name, CV_WINDOW_AUTOSIZE );

  /// Create Trackbar to choose 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 function to initialize
  Threshold_Demo( 0, 0 );

  /// Wait until user finishes program
  while(true)
  {
    int c;
    c = waitKey( 20 );
    if( (char)c == 27 )
      { break; }
   }

}


/**
 * @function Threshold_Demo
 */
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 );
}

OpenCV Tutorials —— Basic Thresholding Operations

标签:style   http   io   ar   color   os   sp   for   div   

原文地址:http://www.cnblogs.com/sprint1989/p/4106537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!