<< Datatypes Datatypes PtList >>

scicv >> Datatypes > Mat

Mat

Image type

Description

Mat is the equivalent in Scilab of the OpenCV type of same name Mat.

When a function outputs an image (such as imread for example), internally OpenCV allocates a Mat object, and a Scilab Mat object is returned, containing a reference to the underlying OpenCV Mat object.

Therefore a Scilab Mat object is not a Scilab matrix (it is a mlist), but it can be manipulated so. That means the following operators are (or will be) available:

To create a Mat, use new_Mat(), which has several forms:

The extraction supports the following arguments:

The type returned can be int8, uint8, int16, uint16, int32, uint32 or double depending on the bit depth and pixel type of the image.

Note: OpenCV stores the RBG channels in the different order BGR, but Scilab rearranges in the standard order.

About functions, there are many available for the Mat type, following is a small list:

Note: functions getting as input Mat objects accept also Scilab matrixes, conversion to Mat is automatically done by Scilab.

When an image is no more used, it must be destroyed with delete_Mat(). Scilab does not manage the life cycle of Mat objects, they have to be destroyed manually.

.

Exemples

scicv_Init();

img = imread(getSampleImage("lena.jpg"));

// Get the dimensions of the image
disp("Size:");
disp(size(img));

disp("Number of cols:");
disp(Mat_cols_get(img));

disp("Number of rows:");
disp(Mat_rows_get(img));

delete_Mat(img);
scicv_Init();

// Create an empty image
img = new_Mat();
disp("Empty ?");
disp(Mat_empty(img));
delete_Mat(img);

// Create a color image
img = new_Mat(300, 200, CV_8UC3);
disp(getImageType(img));
delete_Mat(img);

// Create a (black) grayscale image
img = new_Mat(300, 200, CV_8UC1, 0);
disp(getImageType(img));
delete_Mat(img);
scicv_Init();

// Create a blue color image
blue_color = [255, 0, 0] // BGR
img = new_Mat(10, 5, CV_8UC3, blue_color);

// Extract the whole image
disp(img(:,:));

// Extract the last row
disp(img($,:));

// Extract the two first rows and columns
disp(img(1:2,1:2));

delete_Mat(img);

See also


Report an issue
<< Datatypes Datatypes PtList >>