Reshaping a Mat object

A Mat object can be reshaped using the Mat::reshape function. Note that reshaping, in this sense, means changing the number of channels and rows of an image. Here's an example:

int ch = 1; 
int rows = 200; 
Mat rshpd = image.reshape(ch, rows); 

Note that passing a value of zero as the number of channels means that the number of channels will stay the same as the source. Similarly, passing a value of zero as the number of rows means the number of rows in the image will stay the same.

Note that Mat::resize is another useful function for reshaping a matrix, but it only allows changing the number of rows in an image. Another function that can come in handy when reshaping matrices or dealing with the number of elements in a matrix, is the Mat::total function, which returns the total number of elements in an image.

That's about it for the functionalities embedded into the Mat class itself. Make sure to go through the Mat class documentation and familiarize yourself with possible variants of the methods you just learned in this section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.33.235