本文整理匯總了Java中org.opencv.core.Core.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Java Core.normalize方法的具體用法?Java Core.normalize怎麽用?Java Core.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.core.Core
的用法示例。
在下文中一共展示了Core.normalize方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例2: norm_0_255
import org.opencv.core.Core; //導入方法依賴的package包/類
/**
* 圖像歸一化
* @Title: norm_0_255
* @Description: TODO(這裏用一句話描述這個方法的作用)
* @param src
* @return
* Mat
* @throws
*/
public static Mat norm_0_255(Mat src) {
// 創建和返回一個歸一化後的圖像矩陣
Mat dst = new Mat();
switch(src.channels()) {
case 1: Core.normalize(src, dst, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC1); break;
case 3: Core.normalize(src, dst, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3); break;
default: src.copyTo(dst);break;
}
return dst;
}
示例3: HarrisCorner
import org.opencv.core.Core; //導入方法依賴的package包/類
void HarrisCorner() {
Mat grayMat = new Mat();
Mat corners = new Mat();
//Converting the image to grayscale
Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);
Mat tempDst = new Mat();
//finding contours
Imgproc.cornerHarris(grayMat, tempDst, 2, 3, 0.04);
//Normalizing harris corner's output
Mat tempDstNorm = new Mat();
Core.normalize(tempDst, tempDstNorm, 0, 255, Core.NORM_MINMAX);
Core.convertScaleAbs(tempDstNorm, corners);
//Drawing corners on a new image
Random r = new Random();
for (int i = 0; i < tempDstNorm.cols(); i++) {
for (int j = 0; j < tempDstNorm.rows(); j++) {
double[] value = tempDstNorm.get(j, i);
if (value[0] > 150)
Imgproc.circle(corners, new Point(i, j), 5, new Scalar(r.nextInt(255)), 2);
}
}
//Converting Mat back to Bitmap
Utils.matToBitmap(corners, currentBitmap);
imageView.setImageBitmap(currentBitmap);
}
示例4: enhance
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat enhance(Mat image, int r, double eps, double eta, double lambda, double krnlRatio) {
image.convertTo(image, CvType.CV_32F);
// extract each color channel
List<Mat> bgr = new ArrayList<>();
Core.split(image, bgr);
Mat bChannel = bgr.get(0);
Mat gChannel = bgr.get(1);
Mat rChannel = bgr.get(2);
int m = rChannel.rows();
int n = rChannel.cols();
// Global Adaptation
List<Mat> list = globalAdaptation(bChannel, gChannel, rChannel, m, n);
Mat Lw = list.get(0);
Mat Lg = list.get(1);
// Local Adaptation
Mat Hg = localAdaptation(Lg, m, n, r, eps, krnlRatio);
Lg.convertTo(Lg, CvType.CV_32F);
// process
Mat alpha = new Mat(m, n, rChannel.type());
Core.divide(Lg, new Scalar(Core.minMaxLoc(Lg).maxVal / eta), alpha);
//Core.multiply(alpha, new Scalar(eta), alpha);
Core.add(alpha, new Scalar(1.0), alpha);
//alpha = adjustment(alpha, 1.25);
Mat Lg_ = new Mat(m, n, rChannel.type());
Core.add(Lg, new Scalar(1.0 / 255.0), Lg_);
Core.log(Lg_, Lg_);
double beta = Math.exp(Core.sumElems(Lg_).val[0] / (m * n)) * lambda;
Mat Lout = new Mat(m, n, rChannel.type());
Core.divide(Lg, Hg, Lout);
Core.add(Lout, new Scalar(beta), Lout);
Core.log(Lout, Lout);
Core.normalize(alpha.mul(Lout), Lout, 0, 255, Core.NORM_MINMAX);
Mat gain = obtainGain(Lout, Lw, m, n);
// output
Core.divide(rChannel.mul(gain), new Scalar(Core.minMaxLoc(rChannel).maxVal / 255.0), rChannel); // Red Channel
Core.divide(gChannel.mul(gain), new Scalar(Core.minMaxLoc(gChannel).maxVal / 255.0), gChannel); // Green Channel
Core.divide(bChannel.mul(gain), new Scalar(Core.minMaxLoc(bChannel).maxVal / 255.0), bChannel); // Blue Channel
// merge three color channels to a image
Mat outval = new Mat();
Core.merge(new ArrayList<>(Arrays.asList(bChannel, gChannel, rChannel)), outval);
outval.convertTo(outval, CvType.CV_8UC1);
return outval;
}
示例5: 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;
}