當前位置: 首頁>>代碼示例>>Java>>正文


Java Core.sort方法代碼示例

本文整理匯總了Java中org.opencv.core.Core.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java Core.sort方法的具體用法?Java Core.sort怎麽用?Java Core.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.core.Core的用法示例。


在下文中一共展示了Core.sort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SimplestColorBalance

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Simplest Color Balance. Performs color balancing via histogram
 * normalization.
 *
 * @param img input color or gray scale image
 * @param percent controls the percentage of pixels to clip to white and black. (normally, choose 1~10)
 * @return Balanced image in CvType.CV_32F
 */
public static Mat SimplestColorBalance(Mat img, int percent) {
	if (percent <= 0)
		percent = 5;
	img.convertTo(img, CvType.CV_32F);
	List<Mat> channels = new ArrayList<>();
	int rows = img.rows(); // number of rows of image
	int cols = img.cols(); // number of columns of image
	int chnls = img.channels(); //  number of channels of image
	double halfPercent = percent / 200.0;
	if (chnls == 3) Core.split(img, channels);
	else channels.add(img);
	List<Mat> results = new ArrayList<>();
	for (int i = 0; i < chnls; i++) {
		// find the low and high precentile values (based on the input percentile)
		Mat flat = new Mat();
		channels.get(i).reshape(1, 1).copyTo(flat);
		Core.sort(flat, flat, Core.SORT_ASCENDING);
		double lowVal = flat.get(0, (int) Math.floor(flat.cols() * halfPercent))[0];
		double topVal = flat.get(0, (int) Math.ceil(flat.cols() * (1.0 - halfPercent)))[0];
		// saturate below the low percentile and above the high percentile
		Mat channel = channels.get(i);
		for (int m = 0; m < rows; m++) {
			for (int n = 0; n < cols; n++) {
				if (channel.get(m, n)[0] < lowVal) channel.put(m, n, lowVal);
				if (channel.get(m, n)[0] > topVal) channel.put(m, n, topVal);
			}
		}
		Core.normalize(channel, channel, 0.0, 255.0 / 2, Core.NORM_MINMAX);
		channel.convertTo(channel, CvType.CV_32F);
		results.add(channel);
	}
	Mat outval = new Mat();
	Core.merge(results, outval);
	return outval;
}
 
開發者ID:IsaacChanghau,項目名稱:OptimizedImageEnhance,代碼行數:44,代碼來源:Filters.java

示例2: SimplestColorBalance

import org.opencv.core.Core; //導入方法依賴的package包/類
/**
 * Simplest Color Balance. Performs color balancing via histogram
 * normalization.
 *
 * @param img
 *            input color or gray scale image
 * @param percent
 *            controls the percentage of pixels to clip to white and black.
 *            (normally, choose 1~10)
 * @return Balanced image in CvType.CV_32F
 */
public static Mat SimplestColorBalance(Mat img, int percent) {
	if (percent <= 0)
		percent = 5;
	img.convertTo(img, CvType.CV_32F);
	List<Mat> channels = new ArrayList<Mat>();
	int rows = img.rows(); // number of rows of image
	int cols = img.cols(); // number of columns of image
	int chnls = img.channels(); //  number of channels of image
	double halfPercent = percent / 200.0;
	if (chnls == 3) {
		Core.split(img, channels);
	} else {
		channels.add(img);
	}
	List<Mat> results = new ArrayList<Mat>();
	for (int i = 0; i < chnls; i++) {
		// find the low and high precentile values (based on the input percentile)
		Mat flat = new Mat();
		channels.get(i).reshape(1, 1).copyTo(flat);
		Core.sort(flat, flat, Core.SORT_ASCENDING);
		double lowVal = flat.get(0, (int) Math.floor(flat.cols() * halfPercent))[0];
		double topVal = flat.get(0, (int) Math.ceil(flat.cols() * (1.0 - halfPercent)))[0];
		// saturate below the low percentile and above the high percentile
		Mat channel = channels.get(i);
		for (int m = 0; m < rows; m++) {
			for (int n = 0; n < cols; n++) {
				if (channel.get(m, n)[0] < lowVal)
					channel.put(m, n, lowVal);
				if (channel.get(m, n)[0] > topVal)
					channel.put(m, n, topVal);
			}
		}
		Core.normalize(channel, channel, 0, 255, Core.NORM_MINMAX);
		channel.convertTo(channel, CvType.CV_32F);
		results.add(channel);
	}
	Mat outval = new Mat();
	Core.merge(results, outval);
	return outval;
}
 
開發者ID:IsaacChanghau,項目名稱:ImageEnhanceViaFusion,代碼行數:52,代碼來源:ColorBalance.java


注:本文中的org.opencv.core.Core.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。