在 OpenCV 中保存双精度值矩阵

发布于 2024-09-02 18:42:54 字数 163 浏览 6 评论 0原文

我有一个双值 (CV_32F) 的 OpenCV 矩阵。我想将其保存到磁盘上。我知道,我可以将其转换为 1-Channel 8-bit IplImage 并保存。但这样一来,我就失去了精确性。有没有办法直接保存为32位格式,而不需要先转换?如果生成的文件具有图像格式,那就太好了,这样我就可以将结果作为图像查看。

I have an OpenCV matrix of double (CV_32F) values. I'd like to save it to the disk. I know, I could convert it to an 1-Channel 8-bit IplImage and save it. But that way, I loose precision. Is there a way to save it directly in the 32-bit format, without having to convert it first? It also would be nice, if the resulting file would have an image format, so I can view the result as an image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠北森屋 2024-09-09 18:42:54

您始终可以使用 cvSave() 从 OpenCV“按原样”保存任何“对象”(CvMat、IplImage 等)并使用 cvLoad() 将其加载回来。根据我的经验,大多数浮点图像内容都无法正常工作,我通常以这种方式保存浮点数据。
但是,您无法直接查看存储的数据。

我们经常使用的另一种可能性是包含自己构建的 OpenEXR。您可以使用此库轻松存储全精度浮点图像,并且许多第三方应用程序都能够打开 EXR 文件。请注意,如果我没有记错的话,OpenCV 包括 OpenEXR,但上次我尝试时,保存/加载浮点图像无法正常工作。但是,您应该首先尝试将 fp 图像保存为 *.exr,也许这已经在最新版本中发挥了作用。

You can always save any "object" (CvMat, IplImage, anything..) from OpenCV "as is" by using cvSave() and loading it back with cvLoad(). As to my experience, most floating-point image stuff does not work correctly, I usually save my floating point data this way.
However, you cannot directly view the stored data.

Another possibility we have used frequently is including an own built of OpenEXR. You can easily store full precision floating point images using this library and many third party applications are able to open EXR files. Note that OpenCV includes OpenEXR, if i am not mistaken, but the last time i've tried, saving/loading floating point images did not work correctly. However, you should first try to save an fp image as *.exr, maybe that already does the magic with recent versions.

指尖微凉心微凉 2024-09-09 18:42:54

您始终可以迭代矩阵并自己写出来。如果您希望将其作为图像查看,可以使用 PPM 的变体。如果您使用 0-255 范围之外的值,我不确定哪些程序能够本机读取您的图像格式。

You could always iterate over the matrix and write it out yourself. If you want it to be viewable as an image, you can use a variant of PPM. I'm not sure what programs would be able to natively read your image format if you use values out of the 0-255 range though.

久伴你 2024-09-09 18:42:54

这是旧的,但我想我会投入我的两分钱。

如果您只想将浮动图像保存到磁盘,并且不需要查看它们,则可能需要查看便携式浮动地图(PFM)图像格式。非常简单的格式,只是将浮点数保存到磁盘,没有压缩,最小的标头。您可以非常快速地为此编写自己的读/写代码。这就是我用于 HDR 研究的方法。

正如其他人指出的那样,要“查看”浮动图像,您需要问自己一些有关其内容的问题,以及如何合理地将它们缩放回可以在显示器上显示的 8 位范围。您可能会考虑 Matlab 的图像查看器(imshow 函数),它提供了一些双缩放功能。

您还可以考虑保存为 EXR 或 HDR 格式,并使用 Photomatix 的内置 HDR 图像查看器,它为您提供一个单独的小窗口,显示当前光标位置周围的实时色调映射窗口。这是导航 HDR 或浮点图像的好方法,可以了解“真实情况”,而无需对整个图像进行色调映射。

This is old, but thought I'd throw in my two cents.

If you just want to save float images to disk, and you don't need to view them, you may want to look at Portable Float Map (PFM) image format. Very simple format, just saves floats to disk, no compression, minimal header. You can write your own read/write code for this very quickly. That's what I'm using for HDR research.

As the others pointed out, to "view" float images you need to ask yourself some questions about their contents and how to sensibly scale them back into an 8-bit range you can display on your monitor. You might consider Matlab's image viewer (imshow function) which offers some double scaling functionality.

You might also consider saving to either EXR or HDR format and using Photomatix's built-in HDR image viewer which gives you a little separate window that shows you a real-time tonemapped window around your current cursor position. It's a good way to navigate an HDR or floating point image to get a sense of "what's really there" without tonemapping the whole thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文