How to save opencv mat matrix to a file that can be loaded in matlab. To save the previously loaded image we can use the imwrite method of the imgcodecs class. In fact this is sort of documented.