Opencv 实验系列之Mat

Opencv 实验系列之Mat的初步理解

Mat的组成

Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for storing) . The matrix header size is constant, however the size of the matrix itself may vary from image to image and usually is larger by orders of magnitude.

Mat主要由两部分组成第一部分称为矩阵头,其包含了有关于矩阵的信息和方法例如大小,储存地址,读取图片的函数等,剩余一部分为指向图像相素值储存区的指针。每个Mat变量的矩阵头部分都是独立的私有的,但储存指针可能是相同的,既两个不同的Mat变量可能指向同一矩阵数据。在进行如下操作时,其实A,B,C,D,E共用同一个储存区域,对其中任意一个变量进行更改都会影响其余变量的储存值。

Mat A, C;                          // creates just the header parts
A = imread(argv[1], IMREAD_COLOR); // here we'll know the method used (allocate matrix)
Mat B(A);                                 // Use the copy constructor
C = A;                                    // Assignment operator
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
Mat E = A(Range::all(), Range(1,3)); // using row and column boundaries

如果需要对矩阵数据进行真正的备份,则需要调用clone()或copyTo()在下面的例子中A,F,G有各自的储存区域,而非共享存储区域。

Mat F = A.clone();
Mat G;
A.copyTo(G);

Mat的储存图片的方式

RGB is the most common as our eyes use something similar, however keep in mind that OpenCV standard display system composes colors using the BGR color space (a switch of the red and blue channel).
The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. You might, for example, dismiss the last component, making your algorithm less sensible to the light conditions of the input image.
YCrCb is used by the popular JPEG image format.
CIE L*a*b* is a perceptually uniform color space, which comes handy if you need to measure the distance of a given color to another color.

1)灰度图
2)BGR图(注意在opencv中,蓝红两通道被颠倒了)
3)HSV和HLS,使用该方法可降低算法对光照条件的敏感度(以下关于HSV HLS的解释摘自知乎)

HSB 和 HSV 是是一样的,只是叫法不同,HSL 则还有一些细微的区别:在所有的情况下,H(Hue) 代表色相,S(Saturation) 代表饱和度。Hue(色相)是指取值范围在0-360°的圆心角,每个角度可以代表一种颜色。B 在 HSB 模式中是 Brightness 的意思, V 在 HSV 中是值,但是所表述的是一个东西:对光的量或光源的功率的感知。色相和明度(值)可以在0 - 1或者0% - 100%间取值。HSL 稍微有一些不同,Hue(色相)和 HSB/HSV 模式中一样用数值表示,但是, S,同样代表“饱和度”,定义不一样,且需要转换。 L 代表亮度,和 Brightness/Value 不一样,Brightness(明度)是被认为是”光的量“,可以是任何颜色。而 Lightness(亮度)是作为”白的量“来理解的。Saturation(饱和度)不一样,因为在两个模型中,饱和度都按比例缩放以适应明度或亮度的定义。
作者:知乎用户
链接:https://www.zhihu.com/question/22077462/answer/29483467

4)YCrCb既YUV,其与RGB转换方式为

Y = (B * 1868 + G * 9617 + R * 4899 + 8192)/16384;
U = ((B - Y)* 9241 + 8192)/16384 + 128;
V = ((R - Y)*11682 + 8192)/16384 + 128;
R = Y + 1.14V
G = Y - 0.39U - 0.58V
B = Y + 2.03U

5)CIE(略)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值