本文整理匯總了Java中org.opencv.core.Core.subtract方法的典型用法代碼示例。如果您正苦於以下問題:Java Core.subtract方法的具體用法?Java Core.subtract怎麽用?Java Core.subtract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.core.Core
的用法示例。
在下文中一共展示了Core.subtract方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transEstimate
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat transEstimate(Mat img, int patchSz, double[] airlight, double lambda, double fTrans,
int r, double eps, double gamma) {
int rows = img.rows();
int cols = img.cols();
List<Mat> bgr = new ArrayList<>();
Core.split(img, bgr);
int type = bgr.get(0).type();
// calculate the transmission map
Mat T = computeTrans(img, patchSz, rows, cols, type, airlight, lambda, fTrans);
// refine the transmission map
img.convertTo(img, CvType.CV_8UC1);
Mat gray = new Mat();
Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
gray.convertTo(gray, CvType.CV_32F);
Core.divide(gray, new Scalar(255.0), gray);
T = Filters.GuidedImageFilter(gray, T, r, eps);
Mat Tsmooth = new Mat();
Imgproc.GaussianBlur(T, Tsmooth, new Size(81, 81), 40);
Mat Tdetails = new Mat();
Core.subtract(T, Tsmooth, Tdetails);
Core.multiply(Tdetails, new Scalar(gamma), Tdetails);
Core.add(Tsmooth, Tdetails, T);
return T;
}
示例2: Saliency
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat Saliency(Mat img) {
// blur image with a 3x3 or 5x5 Gaussian filter
Mat gfbgr = new Mat();
Imgproc.GaussianBlur(img, gfbgr, new Size(3, 3), 3);
// Perform sRGB to CIE Lab color space conversion
Mat LabIm = new Mat();
Imgproc.cvtColor(gfbgr, LabIm, Imgproc.COLOR_BGR2Lab);
// Compute Lab average values (note that in the paper this average is found from the
// un-blurred original image, but the results are quite similar)
List<Mat> lab = new ArrayList<>();
Core.split(LabIm, lab);
Mat l = lab.get(0);
l.convertTo(l, CvType.CV_32F);
Mat a = lab.get(1);
a.convertTo(a, CvType.CV_32F);
Mat b = lab.get(2);
b.convertTo(b, CvType.CV_32F);
double lm = Core.mean(l).val[0];
double am = Core.mean(a).val[0];
double bm = Core.mean(b).val[0];
// Finally compute the saliency map
Mat sm = Mat.zeros(l.rows(), l.cols(), l.type());
Core.subtract(l, new Scalar(lm), l);
Core.subtract(a, new Scalar(am), a);
Core.subtract(b, new Scalar(bm), b);
Core.add(sm, l.mul(l), sm);
Core.add(sm, a.mul(a), sm);
Core.add(sm, b.mul(b), sm);
return sm;
}
示例3: LocalContrast
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat LocalContrast(Mat img) {
double[] h = { 1.0 / 16.0, 4.0 / 16.0, 6.0 / 16.0, 4.0 / 16.0, 1.0 / 16.0 };
Mat mask = new Mat(h.length, h.length, img.type());
for (int i = 0; i < h.length; i++) {
for (int j = 0; j < h.length; j++) {
mask.put(i, j, h[i] * h[j]);
}
}
Mat localContrast = new Mat();
Imgproc.filter2D(img, localContrast, img.depth(), mask);
for (int i = 0; i < localContrast.rows(); i++) {
for (int j = 0; j < localContrast.cols(); j++) {
if (localContrast.get(i, j)[0] > Math.PI / 2.75) localContrast.put(i, j, Math.PI / 2.75);
}
}
Core.subtract(img, localContrast, localContrast);
return localContrast.mul(localContrast);
}
示例4: LocalContrast
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat LocalContrast(Mat img) {
double[] h = { 1.0 / 16.0, 4.0 / 16.0, 6.0 / 16.0, 4.0 / 16.0, 1.0 / 16.0 };
Mat mask = new Mat(h.length, h.length, img.type());
for (int i = 0; i < h.length; i++) {
for (int j = 0; j < h.length; j++) {
mask.put(i, j, h[i] * h[j]);
}
}
Mat localContrast = new Mat();
Imgproc.filter2D(img, localContrast, img.depth(), mask);
for (int i = 0; i < localContrast.rows(); i++) {
for (int j = 0; j < localContrast.cols(); j++) {
if (localContrast.get(i, j)[0] > Math.PI / 2.75)
localContrast.put(i, j, Math.PI / 2.75);
}
}
Core.subtract(img, localContrast, localContrast);
return localContrast.mul(localContrast);
}
示例5: LaplacianPyramid
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat[] LaplacianPyramid(Mat img, int level) {
Mat[] lapPyr = new Mat[level];
//Mat mask = filterMask(img);
lapPyr[0] = img.clone();
Mat tmpImg = img.clone();
for (int i = 1; i < level; i++) {
// resize image
Imgproc.resize(tmpImg, tmpImg, new Size(), 0.5, 0.5, Imgproc.INTER_LINEAR);
lapPyr[i] = tmpImg.clone();
}
// calculate the DoG
for (int i = 0; i < level - 1; i++) {
Mat tmpPyr = new Mat();
Imgproc.resize(lapPyr[i + 1], tmpPyr, lapPyr[i].size(), 0, 0, Imgproc.INTER_LINEAR);
Core.subtract(lapPyr[i], tmpPyr, lapPyr[i]);
}
return lapPyr;
}
示例6: getInputDataLeNet
import org.opencv.core.Core; //導入方法依賴的package包/類
private float[] getInputDataLeNet(Bitmap bitmap) {
final int INPUT_LENGTH = 28;
Mat imageMat = new Mat();
Mat inputMat = new Mat();
Utils.bitmapToMat(bitmap, imageMat);
// convert the image to 28 * 28, grayscale, 0~1, and smaller means whiter
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_RGBA2GRAY);
imageMat = centerCropAndScale(imageMat, INPUT_LENGTH);
imageMat.convertTo(imageMat, CvType.CV_32F, 1. / 255);
Core.subtract(Mat.ones(imageMat.size(), CvType.CV_32F), imageMat, inputMat);
float[] inputData = new float[inputMat.width() * inputMat.height()];
inputMat.get(0, 0, inputData);
return inputData;
}
示例7: preDehaze
import org.opencv.core.Core; //導入方法依賴的package包/類
private static Mat preDehaze(Mat img, double a, double nTrans) {
// nOut = ( (blkIm - a) * nTrans + 128 * a ) / 128;
Core.subtract(img, new Scalar(a), img);
Core.multiply(img, new Scalar(nTrans), img);
Core.add(img, new Scalar(128.0 * a), img);
Core.divide(img, new Scalar(128.0), img);
return img;
}
示例8: enhanceEachChannel
import org.opencv.core.Core; //導入方法依賴的package包/類
@SuppressWarnings("unused")
public static Mat enhanceEachChannel(Mat image, int blkSize, int patchSize, double lambda, double eps, int krnlSize) {
image.convertTo(image, CvType.CV_32F);
// split image to three channels
List<Mat> bgr = new ArrayList<>();
Core.split(image, bgr);
Mat bChannel = bgr.get(0);
Mat gChannel = bgr.get(1);
Mat rChannel = bgr.get(2);
// obtain air-light
double[] airlight = AirlightEstimate.estimate(image, blkSize);
// obtain coarse transmission map and refine it for each channel
double fTrans = 0.3;
Mat T = TransmissionEstimate.transEstimateEachChannel(bChannel, patchSize, airlight[0], lambda, fTrans);
Core.subtract(T, new Scalar(1.0), T);
Core.multiply(T, new Scalar(-1.0), T);
Mat Tb = Filters.GuidedImageFilter(bChannel, T, krnlSize, eps);
T = TransmissionEstimate.transEstimateEachChannel(gChannel, patchSize, airlight[1], lambda, fTrans);
Core.subtract(T, new Scalar(1.0), T);
Core.multiply(T, new Scalar(-1.0), T);
Mat Tg = Filters.GuidedImageFilter(gChannel, T, krnlSize, eps);
T = TransmissionEstimate.transEstimateEachChannel(rChannel, patchSize, airlight[2], lambda, fTrans);
Core.subtract(T, new Scalar(1.0), T);
Core.multiply(T, new Scalar(-1.0), T);
Mat Tr = Filters.GuidedImageFilter(rChannel, T, krnlSize, eps);
// dehaze
bChannel = dehaze(bChannel, Tb, airlight[0]);
gChannel = dehaze(gChannel, Tg, airlight[1]);
rChannel = dehaze(rChannel, Tr, airlight[2]);
Mat outval = new Mat();
Core.merge(new ArrayList<>(Arrays.asList(bChannel, gChannel, rChannel)), outval);
return outval;
}
示例9: dehaze
import org.opencv.core.Core; //導入方法依賴的package包/類
private static Mat dehaze(Mat img, Mat T, double airlight) {
// J = (img - airlight) ./ T + airlight;
Core.subtract(img, new Scalar(airlight), img);
Core.divide(img, T, img);
Core.add(img, new Scalar(airlight), img);
return img;
}
示例10: dehaze
import org.opencv.core.Core; //導入方法依賴的package包/類
private static Mat dehaze(Mat channel, Mat t, double minAtmosLight) {
Mat t_ = new Mat();
Core.subtract(t, new Scalar(1.0), t_);
Core.multiply(t_, new Scalar(-1.0 * minAtmosLight), t_);
Core.subtract(channel, t_, channel);
Core.divide(channel, t, channel);
return channel;
}
示例11: dehazeProcess
import org.opencv.core.Core; //導入方法依賴的package包/類
private static Mat dehazeProcess(Mat img, Mat trans, double[] airlight) {
Mat balancedImg = Filters.SimplestColorBalance(img, 5);
Mat bCnl = new Mat();
Core.extractChannel(balancedImg, bCnl, 0);
Mat gCnl = new Mat();
Core.extractChannel(balancedImg, gCnl, 1);
Mat rCnl = new Mat();
Core.extractChannel(balancedImg, rCnl, 2);
// get mean value
double bMean = Core.mean(bCnl).val[0];
double gMean = Core.mean(gCnl).val[0];
double rMean = Core.mean(rCnl).val[0];
// get transmission map for each channel
Mat Tb = trans.clone();
Core.multiply(Tb, new Scalar(Math.max(bMean, Math.max(gMean, rMean)) / bMean * 0.8), Tb);
Mat Tg = trans.clone();
Core.multiply(Tg, new Scalar(Math.max(bMean, Math.max(gMean, rMean)) / gMean * 0.9), Tg);
Mat Tr = trans.clone();
Core.multiply(Tr, new Scalar(Math.max(bMean, Math.max(gMean, rMean)) / rMean * 0.8), Tr);
// dehaze by formula
// blue channel
Mat bChannel = new Mat();
Core.subtract(bCnl, new Scalar(airlight[0]), bChannel);
Core.divide(bChannel, Tb, bChannel);
Core.add(bChannel, new Scalar(airlight[0]), bChannel);
// green channel
Mat gChannel = new Mat();
Core.subtract(gCnl, new Scalar(airlight[1]), gChannel);
Core.divide(gChannel, Tg, gChannel);
Core.add(gChannel, new Scalar(airlight[1]), gChannel);
// red channel
Mat rChannel = new Mat();
Core.subtract(rCnl, new Scalar(airlight[2]), rChannel);
Core.divide(rChannel, Tr, rChannel);
Core.add(rChannel, new Scalar(airlight[2]), rChannel);
Mat dehazed = new Mat();
Core.merge(new ArrayList<>(Arrays.asList(bChannel, gChannel, rChannel)), dehazed);
return dehazed;
}
示例12: unevenLightCompensate
import org.opencv.core.Core; //導入方法依賴的package包/類
/**
* 其主要思路為:
1、求取源圖I的平均灰度,並記錄rows和cols;
2、按照一定大小,分為N*M個方塊,求出每塊的平均值,得到子塊的亮度矩陣D;
3、用矩陣D的每個元素減去源圖的平均灰度,得到子塊的亮度差值矩陣E;
4、用雙立方差值法,將矩陣E差值成與源圖一樣大小的亮度分布矩陣R;
5、得到矯正後的圖像result=I-R;
* @Title: unevenLightCompensate
* @Description: 光線補償
* @param image
* @param blockSize
* void
* @throws
*/
public static void unevenLightCompensate(Mat image, int blockSize) {
if(image.channels() == 3) {
Imgproc.cvtColor(image, image, 7);
}
double average = Core.mean(image).val[0];
Scalar scalar = new Scalar(average);
int rowsNew = (int) Math.ceil((double)image.rows() / (double)blockSize);
int colsNew = (int) Math.ceil((double)image.cols() / (double)blockSize);
Mat blockImage = new Mat();
blockImage = Mat.zeros(rowsNew, colsNew, CvType.CV_32FC1);
for(int i = 0; i < rowsNew; i ++) {
for(int j = 0; j < colsNew; j ++) {
int rowmin = i * blockSize;
int rowmax = (i + 1) * blockSize;
if(rowmax > image.rows()) rowmax = image.rows();
int colmin = j * blockSize;
int colmax = (j +1) * blockSize;
if(colmax > image.cols()) colmax = image.cols();
Range rangeRow = new Range(rowmin, rowmax);
Range rangeCol = new Range(colmin, colmax);
Mat imageROI = new Mat(image, rangeRow, rangeCol);
double temaver = Core.mean(imageROI).val[0];
blockImage.put(i, j, temaver);
}
}
Core.subtract(blockImage, scalar, blockImage);
Mat blockImage2 = new Mat();
int INTER_CUBIC = 2;
Imgproc.resize(blockImage, blockImage2, image.size(), 0, 0, INTER_CUBIC);
Mat image2 = new Mat();
image.convertTo(image2, CvType.CV_32FC1);
Mat dst = new Mat();
Core.subtract(image2, blockImage2, dst);
dst.convertTo(image, CvType.CV_8UC1);
}
示例13: subspaceProject
import org.opencv.core.Core; //導入方法依賴的package包/類
public static Mat subspaceProject(Mat W, Mat mean, Mat src) {
int n = src.rows();
int d = src.cols();
Mat X = new Mat();
Mat Y = new Mat();
src.convertTo(X, W.type());
if(!mean.empty()) {
for(int i = 0; i < n; i ++) {
Mat r_i = X.row(i);
Core.subtract(r_i, mean.reshape(1, 1), r_i);
}
}
Core.gemm(X, W, 1.0, new Mat(), 0.0, Y);
return Y;
}
示例14: GuidedImageFilter
import org.opencv.core.Core; //導入方法依賴的package包/類
/**
* Guided Image Filter for grayscale image, O(1) time implementation of guided filter
*
* @param I guidance image (should be a gray-scale/single channel image)
* @param p filtering input image (should be a gray-scale/single channel image)
* @param r local window radius
* @param eps regularization parameter
* @return filtered image
*/
public static Mat GuidedImageFilter(Mat I, Mat p, int r, double eps) {
I.convertTo(I, CvType.CV_64FC1);
p.convertTo(p, CvType.CV_64FC1);
//[hei, wid] = size(I);
int rows = I.rows();
int cols = I.cols();
// N = boxfilter(ones(hei, wid), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
Mat N = new Mat();
Imgproc.boxFilter(Mat.ones(rows, cols, I.type()), N, -1, new Size(r, r));
// mean_I = boxfilter(I, r) ./ N;
Mat mean_I = new Mat();
Imgproc.boxFilter(I, mean_I, -1, new Size(r, r));
// mean_p = boxfilter(p, r) ./ N
Mat mean_p = new Mat();
Imgproc.boxFilter(p, mean_p, -1, new Size(r, r));
// mean_Ip = boxfilter(I.*p, r) ./ N;
Mat mean_Ip = new Mat();
Imgproc.boxFilter(I.mul(p), mean_Ip, -1, new Size(r, r));
// cov_Ip = mean_Ip - mean_I .* mean_p; % this is the covariance of (I, p) in each local patch.
Mat cov_Ip = new Mat();
Core.subtract(mean_Ip, mean_I.mul(mean_p), cov_Ip);
// mean_II = boxfilter(I.*I, r) ./ N;
Mat mean_II = new Mat();
Imgproc.boxFilter(I.mul(I), mean_II, -1, new Size(r, r));
// var_I = mean_II - mean_I .* mean_I;
Mat var_I = new Mat();
Core.subtract(mean_II, mean_I.mul(mean_I), var_I);
// a = cov_Ip ./ (var_I + eps); % Eqn. (5) in the paper;
Mat a = new Mat();
Core.add(var_I, new Scalar(eps), a);
Core.divide(cov_Ip, a, a);
//b = mean_p - a .* mean_I; % Eqn. (6) in the paper;
Mat b = new Mat();
Core.subtract(mean_p, a.mul(mean_I), b);
// mean_a = boxfilter(a, r) ./ N;
Mat mean_a = new Mat();
Imgproc.boxFilter(a, mean_a, -1, new Size(r, r));
Core.divide(mean_a, N, mean_a);
// mean_b = boxfilter(b, r) ./ N;
Mat mean_b = new Mat();
Imgproc.boxFilter(b, mean_b, -1, new Size(r, r));
Core.divide(mean_b, N, mean_b);
// q = mean_a .* I + mean_b; % Eqn. (8) in the paper;
Mat q = new Mat();
Core.add(mean_a.mul(I), mean_b, q);
q.convertTo(q, CvType.CV_32F);
return q;
}
示例15: filterSingleChannel
import org.opencv.core.Core; //導入方法依賴的package包/類
private static Mat filterSingleChannel(Mat p, double s, ArrayList<Mat> Isubchannels, ArrayList<Mat> Ichannels,
Mat mean_I_r, Mat mean_I_g, Mat mean_I_b, Mat invrr, Mat invrg, Mat invrb, Mat invgg, Mat invgb,
Mat invbb, double r_sub) {
Mat p_sub = new Mat();
Imgproc.resize(p, p_sub, new Size(p.cols() / s, p.rows() / s), 0.0, 0.0, Imgproc.INTER_NEAREST);
Mat mean_p = boxfilter(p_sub, (int) r_sub);
Mat mean_Ip_r = boxfilter(Isubchannels.get(0).mul(p_sub), (int) r_sub);
Mat mean_Ip_g = boxfilter(Isubchannels.get(1).mul(p_sub), (int) r_sub);
Mat mean_Ip_b = boxfilter(Isubchannels.get(2).mul(p_sub), (int) r_sub);
// convariance of (I, p) in each local patch
Mat cov_Ip_r = new Mat();
Mat cov_Ip_g = new Mat();
Mat cov_Ip_b = new Mat();
Core.subtract(mean_Ip_r, mean_I_r.mul(mean_p), cov_Ip_r);
Core.subtract(mean_Ip_g, mean_I_g.mul(mean_p), cov_Ip_g);
Core.subtract(mean_Ip_b, mean_I_b.mul(mean_p), cov_Ip_b);
Mat temp1 = new Mat();
Mat a_r = new Mat();
Mat a_g = new Mat();
Mat a_b = new Mat();
Core.add(invrr.mul(cov_Ip_r), invrg.mul(cov_Ip_g), temp1);
Core.add(temp1, invrb.mul(cov_Ip_b), a_r);
Core.add(invrg.mul(cov_Ip_r), invgg.mul(cov_Ip_g), temp1);
Core.add(temp1, invgb.mul(cov_Ip_b), a_g);
Core.add(invrb.mul(cov_Ip_r), invgb.mul(cov_Ip_g), temp1);
Core.add(temp1, invbb.mul(cov_Ip_b), a_b);
Mat b = new Mat();
Core.subtract(mean_p, a_r.mul(mean_I_r), b);
Core.subtract(b, a_g.mul(mean_I_g), b);
Core.subtract(b, a_b.mul(mean_I_b), b);
Mat mean_a_r = boxfilter(a_r, (int) r_sub);
Mat mean_a_g = boxfilter(a_g, (int) r_sub);
Mat mean_a_b = boxfilter(a_b, (int) r_sub);
Mat mean_b = boxfilter(b, (int) r_sub);
Imgproc.resize(mean_a_r, mean_a_r,
new Size(Ichannels.get(0).cols(), Ichannels.get(0).rows()), 0.0, 0.0, Imgproc.INTER_LINEAR);
Imgproc.resize(mean_a_g, mean_a_g,
new Size(Ichannels.get(0).cols(), Ichannels.get(0).rows()), 0.0, 0.0, Imgproc.INTER_LINEAR);
Imgproc.resize(mean_a_b, mean_a_b,
new Size(Ichannels.get(0).cols(), Ichannels.get(0).rows()), 0.0, 0.0, Imgproc.INTER_LINEAR);
Imgproc.resize(mean_b, mean_b,
new Size(Ichannels.get(0).cols(), Ichannels.get(0).rows()), 0.0, 0.0, Imgproc.INTER_LINEAR);
Mat result = new Mat();
Core.add(mean_a_r.mul(Ichannels.get(0)), mean_a_g.mul(Ichannels.get(1)), temp1);
Core.add(temp1, mean_a_b.mul(Ichannels.get(2)), temp1);
Core.add(temp1, mean_b, result);
return result;
}