图像rows,columns与坐标的对应关系

本文深入解析了OpenCV与Matlab中图像处理的坐标系概念,详细阐述了行(Y轴)与列(X轴)在两种环境下的对应关系,并通过代码示例展示了Mat类型变量的访问方式。对于理解图像处理软件中的坐标系统有重要指导意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

OpenCV Images

转自:https://blog.youkuaiyun.com/sc944201630/article/details/82222909
在这里插入图片描述
行列与坐标系对应关系
行rows:Y (Height)
列cols:X (Width)

在Mat类型变量访问时下标是反着写的,即按照(y, x)的关系形式访问,下面通过代码展示来说明这一点。

    #include "opencv2/core.hpp"
    #include "opencv2/imgproc.hpp"
    #include "opencv2/highgui.hpp"
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    int main()
    {
        Mat mat_src = Mat::eye(3, 4, CV_8UC1);
    
        cout << "mat_src :" << endl;
        cout << mat_src    << endl;
    
        cout << endl;
        cout << "Rows : " << mat_src.rows << endl;
        cout << "Cols : " << mat_src.cols << endl;
    
        //注: mat_src.at<float>(y, x), 下标关系为: y-x
        mat_src.at<float>(0, 2) = 2; 
        mat_src.at<float>(2, 0) = 4;
    
        cout << endl;
        cout << "mat_src :" << endl;
        cout << mat_src    << endl;
    
        return 0;
    }

在这里插入图片描述

Matlab Images

From https://ww2.mathworks.cn/help/images/images-in-matlab.html
An image composed of 200 rows and 300 columns of different colored dots would be stored in MATLAB as a 200-by-300 matrix.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值