开发者

OpenCV:Difference between a matrix with 1 column of 8UC3 type and 3 columns of 8UC1

Lets say I create a matrix M1 of 5 rows and 1 column of 8UC3 type to store RGB components of an image.Then I create another matrix M2 of 5 rows and 3 columns of 8UC1 type to again store the RGB components of the image.

Is there a difference in the way these 2 types of matrices are stored in/accessed from the memory? From what I understand from http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000 (commonly recommended OpenCV tutorial on Stackoverflow), the data pointer of the matrix points to the first index of the data array(the matrix is internally stored as an array) and the various RGB components are stored in an interwoven fashion(in case of 8UC3).

My logic says that they should be the s开发者_运维技巧ame as in case of 1 column 8UC3(M1), for each column RGB components are stored, and in the case of 3 columns 8UC1(M2), each column stores the RGB component. I hope I have been able to formulate my question well.

Thanks in advance!


Your understanding is correct. The memory layout will be exactly the same. So you can cheaply convert the representation back-and-forth via reshape method.

The thing that would be different is how OpenCV algorithms will handle those matrices.

Let's say the memory footprint is as follow:

255 0 0 
255 0 0 
255 0 0 
255 0 0 
255 0 0 

And you want to call the resize function to add 3 columns. Then in the case of a 5x1 Mat of CV_8UC3, the result will be

255 0 0 255 0 0
255 0 0 255 0 0
255 0 0 255 0 0
255 0 0 255 0 0
255 0 0 255 0 0

And in case of a 5x3 Mat of CV_8UC1, the result will be

255 255 0 0 0 0
255 255 0 0 0 0
255 255 0 0 0 0
255 255 0 0 0 0
255 255 0 0 0 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜