• OpenCV-滤波矩阵(java版)



    用下图做演示
    在这里插入图片描述

    multiply()

    顾名思义,乘法函数。使用该函数可以将像素的每个通道值乘以这个参数。

    方法说明
    multiply(Mat src1, Scalar src2, Mat dst, double scale, int dtype) src1:原图像
    src2:颜色矩阵
    scale:src2矩阵参数的乘数值(从图像的角度来说,可以理解为亮度值,值越大,图像越亮)
    dst:目标图像
    dtype:图像(矩阵)类型
    multiply(Mat src1, Scalar src2, Mat dst, double scale)
    multiply(Mat src1, Scalar src2, Mat dst)
    例:当 src2为[0.0,0.5,1.0]时候,表示在原矩阵像素值的基础上,蓝色通道值乘以0,绿色通道值乘以0.5,红色通道值乘以0(当最终通道值大于255时,通道值为255)
    scale:表示在src通道的基础上乘以相对应的scale值,比如scale为3时,结合前面的src2矩阵,此时src2矩阵值变为[0.0,1.5,3.0]
    为验证结果,下面创建一个3*3,像素值为[122,122,122]的矩阵图 示例:
        public static void main(String[] args) {
            String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
            System.load(libraryPath);
            Mat mat = new Mat(3,3, CvType.CV_8UC3,new Scalar(122,122,122));
            System.out.println("mat1>>"+mat.dump());
            Core.multiply(mat,new Scalar(0.0,0.5,1.0),mat,3,CvType.CV_8UC3);
            System.out.println("mat2>>"+mat.dump()+"=="+mat);
            HighGui.imshow("mat",mat);
            HighGui.waitKey(0);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    执行结果

    mat1>>[122, 122, 122, 122, 122, 122, 122, 122, 122;
    122, 122, 122, 122, 122, 122, 122, 122, 122;
    122, 122, 122, 122, 122, 122, 122, 122, 122]
    mat2>>[ 0, 183, 255, 0, 183, 255, 0, 183, 255;
    0, 183, 255, 0, 183, 255, 0, 183, 255;
    0, 183, 255, 0, 183, 255, 0, 183, 255]==Mat [ 33CV_8UC3, isCont=true, isSubmat=false, nativeObj=0xbdaeb0, dataAddr=0xbdb100 ]

    读取图像
    示例:

        public static void main(String[] args) {
            String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
            System.load(libraryPath);
            Mat mat = Imgcodecs.imread("flower.jpg");
            Core.multiply(mat,new Scalar(0.0,0.5,1.0),mat,1.0,CvType.CV_8UC3);
            HighGui.imshow("mat",mat);
            HighGui.waitKey(0);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    结果
    在这里插入图片描述
    亮度演示:
    示例:

        public static void main(String[] args) {
            String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
            System.load(libraryPath);
            Mat mat = Imgcodecs.imread("flower.jpg");
            //为演示效果,将Scalar设为(1.0,1.0,1.0)
            Core.multiply(mat,new Scalar(1.0,1.0,1.0),mat,2.0,CvType.CV_8UC3);
            HighGui.imshow("mat",mat);
            HighGui.waitKey(0);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    结果:在这里插入图片描述

  • 相关阅读:
    高并发环境下生成序列编码重复问题分析
    .NET深入了解哈希表和Dictionary
    RabbitMQ 学习(二)---- HelloWorld 简单模型
    PL/SQL变量,常量和数据类型(二)
    总结一下Feign的知识点
    基于ATX的自动化测试管理软件:Q-Automation
    《深入理解linux内核》-1-绪论
    node.js+elementUI+echarts前后端分离全栈项目
    关于Kali部署OneForAll,不能运行问题
    51_Pandas (to_excel) 编写 Excel 文件 (xlsx, xls)
  • 原文地址:https://blog.csdn.net/qq_27185879/article/details/127187720