简体   繁体   English

OpenCV写入一个浮动图像,要使用哪种转换?

[英]OpenCV imwrite a float image, which conversion to use?

I need to store a float image in OpenCV. 我需要在OpenCV中存储浮动图像。 Converting it to a CV8U image as suggested by @tomriddle_1234 still stores a black png. 按照@ tomriddle_1234的建议将其转换为CV8U图像仍会存储黑色png。

reference.type() = 5
reference.channels() = 1
reference.depth() = 5

How can I convert the image to a 8bit or 16bit so that imwrite can store the image, while maintaining it's float property ie: the stored image is not "washed out colours" due to conversion/loss of precision! 我如何将图像转换为8bit或16bit,以便imwrite可以存储图像,同时保持其float属性,即:由于转换/精度损失,存储的图像不会“褪色”!

imshow("5t aligned Mean", reference); //Displays the correct image
//reference.convertTo(reference, CV_8U); //Convert image to 8Bit INCORRECT
reference.convertTo(reference, CV_8U, 255.0, 1/255.0); //Correct image
imwrite(subject.c_str(), reference); //Stores a completely black png

Any suggestions are much appreciated! 任何建议,不胜感激!

You can convert to 16bit by multiplying each float pixel by 2^16. 您可以通过将每个浮动像素乘以2 ^ 16来转换为16位。 Floating point images are stored with values between 0-1 浮点图像的存储值介于0-1之间

opencv will save 16bit uncompressed in PNG and TIFF with the normal imwrite(). opencv将使用正常的imwrite()将16位未压缩的内容保存在PNG和TIFF中。

(It will also save them as JPEG although I've had less luck finding things that read 16bit jpeg) (尽管我运气不好,无法找到读取16位jpeg的内容,但也会将它们另存为JPEG)

使用CV_NORM_MINMAX在0到255之间转换之前对图像进行归一化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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