简体   繁体   中英

Opencv: save a double matrix with imwrite

I have a matrix (Mat) constituted by double, in the range [0,1]. When I save it by means of command imwrite, the resulting image is totally black. I suppose the problem is a casting problem, but I don't know how to solve it. Thanks

The only way for OpenCV to store array of doubles without converting them to other formats (and losing information) is by using FileStorage . imwrite is restricted to arrays of 'char' or 'short'.

You get the totally black image is because all images pixels are within range [0,1] (actually either 0 or 1 when saving to image), which is approaching total black (either for gray-scale image or color image).

To save the matrix to the image with normal color, you need first to transform the double matrix to range [0, 255] by multiplying each value by 255 . Remember to transform back if you later load the matrix from this image by dividing each value by 255 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM