标签:style http io ar color os sp for div
This thresholding operation can be expressed as:
So, if the intensity of the pixel
is higher than
, then the new pixel intensity is set to a
. Otherwise, the pixels are set to
.
二分 ~~ 阈值化最朴素的形式
This thresholding operation can be expressed as:
If the intensity of the pixel
is higher than
, then the new pixel intensity is set to a
. Otherwise, it is set to
.
反向二分操作
This thresholding operation can be expressed as:
The maximum intensity value for the pixels is
, if
is greater, then its value is truncated. See figure below:
截短 ———— 发现渐渐调整阈值可以做出很有美感的demo :)
This operation can be expressed as:
If
is lower than
, the new pixel value will be set to
.
截短操作的逆操作
This operation can be expressed as:
If
is greater than
, the new pixel value will be set to
.
#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