Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:43:16+00:00 2026-06-11T05:43:16+00:00

according to this post and from OpenCV documentation, I can initialize and access each

  • 0

according to this
post and from OpenCV documentation, I can initialize and access each element of a multidimensional Mat.

Actually, I firstly coded in MATLAB and now need to convert to OpenCV. MATLAB matrix supports sub-matrix access like: a(:,:,3) or b(:,:,3:5)

Can this be done in OpenCV? as far as I know, this can be done with 2D Mat. How about more that 2D??

Edit01:
moreover, with multidimensional Mat, the properties cols and rows are not enough to characterize 3 sizes of the matrix. There are cases with dimension larger than 3. How to store these properties?

Edit02:

// create a 100x100x100 8-bit array
int sz[] = {100, 100, 100};
Mat bigCube(3, sz, CV_8U, Scalar::all(0));

I give up the idea of sub-matrix access with OpenCV Mat. Perhaps, it’s not supported in OpenCV. But from this sample code, the constructor receives the 3rd dimension from ‘sz’. Which property of Mat this 3rd dimension is passed to? probably in this case, rows = 100, cols = 100, the other ?? = 100
I’m lost with OPenCV documentation

Edit03: tracking Mat class from OpenCV source
I’ve found the definition of the constructor in Edit02 from mat.hpp:

inline Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s)
    : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
    datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
{
    create(_dims, _sz, _type);
    *this = _s;
}  

the next question is where and how “create” function here is defined?
=> tracing this Mat definition in OpenCV probably helps me to modify/customize my own features in Mat matrix

PS: excuse me if my post is written too messy!! I’m a novic programmer, trying to solve my programming problem. Plz feel free to correct me if my approach is not good or right enough. Thank you!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:43:17+00:00Added an answer on June 11, 2026 at 5:43 am

    You can easily access sub-matrix of 2D cv::Mat using functions rowRange, colRange or even

    cv::Mat subMat = originalMat(cv::Rect(x,y,width,height));
    

    Also, the number of channels in a matrix, that you can define in the matrix constructor, can be used as the third dimension (but it is limited to 256 or 512 i think).

    There is also the templated cv::Mat_ class that you can adapt to fit your purpose

    [edit]

    I have checked the constructor for >2 dimensional matrices. When you run it the rows and cols field of Mat are set to -1. The actual matrix size is store in Mat::size as an array of int.
    For matrix of dimensions >2 you cannot use the submatrices constructors using a cv::Rect or rowRange/colRange.

    I’m afraid you have to do a bit of work to extract submatrices for dim>2, working directly with the row data. But you can use the information stored in Mat::step which tells you the layout of the array. This is explained in the official documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this post in Recursive Descent vs. LALR , any LALR(k) can be
It appears that glColorMaterial() is absent from OpenGL ES . According to this post
According to this post , in .Net, Finalizers are actually even worse than that.
What is the best way to access my managedObjectContext. According to this post I
I'm using Android 2.3, so according to this post: Streaming Audio from A URL
According to this post a typical firefox user has 2-3 tabs open. How can
According to this blog post and the documentation of onStartCommand() if you have a
I got the javascript email validation code from this post . According to the
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According to this post , i ask $title. Which are your favorite PHP coding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.