public static IImageMatrix ToImage(this Mat mat) { var colorMatrix = new ColorMatrix(mat.Width, mat.Height); using (var matrixData = colorMatrix.LockData()) { Native .Kernel32 .CopyMemory(matrixData.Scan0, mat.Data, matrixData.Stride * matrixData.Height); } return(colorMatrix); }