1.图像的加法
实现加权平均,src1和src2的权重均为0.5
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat src1 = Imgcodecs.imread("add1.png");
Mat src2 = Imgcodecs.imread("add2.png");
Mat dst = new Mat();
Core.addWeighted(src1,0.5,src2,0.5,0,dst);//加权平均
HighGui.imshow("mixed",dst);
HighGui.waitKey(0);
}
原图:
结果图:
实现简单的图像相加,当和大于255时,像素值结果为255
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat src1 = Imgcodecs.imread("add1.png");
Mat src2 = Imgcodecs.imread("add2.png");
Mat dst = new Mat();
Core.add(src1,src2,dst);//简单相加,若相加结果大于255,则取结果为255
HighGui.imshow("mixed",dst);
HighGui.waitKey(0);
}
结果图:
2.图像反相:
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat dst = new Mat();
Mat mat = Imgcodecs.imread("1.png");
Core.bitwise_not(mat,dst);//图像反相
HighGui.imshow("mixed",dst);
HighGui.waitKey(0);
}