Java OpenCV腐蚀膨胀内核锚点

内核坐标系为

在这里插入图片描述

测试代码

	public static void main(String[] args) {

		//读入灰度图
        Mat src = Imgcodecs.imread("F:\\opencvPhoto\\photo\\108.jpg", Imgcodecs.IMREAD_GRAYSCALE);
        //二值化
        Imgproc.threshold(src, src, 120, 255, Imgproc.THRESH_BINARY);
        //对比图
        Mat temp = src.clone();
        
        int width = 4; //内核宽度
        int height = 4; //内核高度
        Mat element= Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(width , height ));

        Point point = new Point(-1, -1); //定义内核位置 等价于 Point(width  /2, height / 2);
        //膨胀 
        Imgproc.dilate(src, src, horizontalStructure, point, 1, Core.BORDER_CONSTANT, new Scalar(255));
        Imgcodecs.imwrite("F:\\opencvPhoto\\result\\dst1.jpg", src);
        
		/***************************还原原图*************************/
	
		//定义内核位置
        int x = width / 2;
        int y = width / 2;
        if ((minWidth&1) == 0) {  //偶数
            x -= 1;
        }
        if ((minWidth&1) == 0) { //偶数
            y -= 1;
        }
        point = new Point(x, y);
        //腐蚀
        Imgproc.erode(src, src, horizontalStructure, point, 1, Core.BORDER_CONSTANT, new Scalar(255));
        
		//判断是否与原图一致
        boolean flag = true;
        for (int i = 0; i < temp.rows(); i++) {
            for (int j = 0; j < temp.cols(); j++) {
                if (src.get(i, j)[0] != temp.get(i, j)[0]) {
                    flag = false;
                    break;
                }
            }
            if (!flag) {
                break;
            }
        }
        System.out.println(flag);

    }

代码内核锚点 :(x, y)
在这里插入图片描述
原图
在这里插入图片描述
原图坐标说明
在这里插入图片描述
dst1坐标说明
在这里插入图片描述
后台输出
true

其他说明

边界填充
腐蚀膨胀说明

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值