threshold関数でさまざまなしきい値処理

double threshold( InputArray src, OutputArray dst, double thresh, double maxval, int type );

引数

返り値

解説

サンプルコード

#geshi(c++){{

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/imgcodecs/imgcodecs.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <iostream>

const char filename[] = "path/to/opencv/samples/data/pic6.png"; const char windowName[] = "Threshold"; const double kThreshold = 100; const double kHigh = 255;

int main(int argc, char**argv) {

	using namespace cv;
	Mat input = imread(filename, IMREAD_GRAYSCALE);
	namedWindow(windowName);
	imshow(windowName, input);
	waitKey(0);
	Mat result;
	// try various thresholding type
	threshold(input, result, kThreshold, kHigh, THRESH_BINARY);     imshow(windowName,result);	waitKey(0);
	threshold(input, result, kThreshold, kHigh, THRESH_BINARY_INV); imshow(windowName,result);	waitKey(0);
	threshold(input, result, kThreshold, kHigh, THRESH_TRUNC);      imshow(windowName,result);	waitKey(0);
	threshold(input, result, kThreshold, kHigh, THRESH_TOZERO);     imshow(windowName,result);	waitKey(0);
	threshold(input, result, kThreshold, kHigh, THRESH_TOZERO_INV); imshow(windowName,result);	waitKey(0);
	double estimatedTh = 0.f;
	// try automatic threshold
	// try OTSU method
	estimatedTh = threshold(input, result, 0, kHigh, THRESH_BINARY+THRESH_OTSU);
	std::cout << "OTSU threshold    :" << estimatedTh << std::endl;	imshow(windowName,result);	waitKey(0);
	// try OTSU method
	estimatedTh = threshold(input, result, 0, kHigh, THRESH_BINARY+THRESH_TRIANGLE);
	std::cout << "TRIANGLE threshold:" << estimatedTh << std::endl;	imshow(windowName,result);	waitKey(0);
	return 0;

} }}

実行結果

実体ファイル

ジャンル:OpenCV:OpenCV 2.4:OpenCV 3.0:OpenCV 3.1準拠


添付ファイル: fileresult0000.png 986件 [詳細] fileresult0001.png 1043件 [詳細] fileresult0002.png 968件 [詳細] fileresult0003.png 1023件 [詳細] fileresult0004.png 1017件 [詳細] fileresult0005.png 993件 [詳細] fileresult0006.png 1011件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-01-17 (日) 12:29:03