如何从压缩图像文件打开某些区域而不将完整图像文件加载到内存中?

发布于 2025-01-02 06:05:20 字数 167 浏览 1 评论 0原文

我们将一些压缩的 JPG 或 PNG 文件中的图像加载到打开的 CV 中。它真的很大。我们有一些投资回报率,比如从 (2000:2000) 到 (2100:2100)(100x100 平方)。我们关闭了一张图片。我们能否再次打开该 ROI,而不将完整图像文件加载到内存中?如果是的话我们该怎么办呢?需要保存任何元数据吗?

We had an image loaded into open CV from some compressed JPG or PNG file. It was really big. We had some ROI on it say from (2000:2000) to (2100:2100) (square 100x100). We closed an image. Could we any how open that ROI again not loading full image file into memory? If yes what shall we do for it? Any metadata to save?

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

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

发布评论

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

评论(2

九厘米的零° 2025-01-09 06:05:20

如果您正在使用位图或其他以常规模式存储位的格式,那么您可以通过自己解码文件并仅读取所需的偏移量来完成此操作。

位图文件格式

提取 PNG 图像的一部分

我不确定,但我认为对于 jpeg,这是不可能的,因为图像存储为频域信息意味着您需要所有数据才能生成原始细节图像的任何部分。

或者正如我在评论中建议的那样,如果您的 ROI 数量有限并且您知道稍后需要哪些(或者即使您不知道如果有的话),您可以在内存中有 ROI 时保存它没有那么多)。

其中哪一个听起来对您来说是个好方法?我很久以前就读过bmp,但手头没有代码。如果您需要节省投资回报率,我可以挖掘 opencv 代码。不过这很容易。

If you are working with a bitmap or other format that stores bits in a regular pattern, then yes you can do this by decoding the file yourself and only reading the offsets that you need.

Bitmap file format

Extracting part of a PNG image

I am not sure, but I think with jpeg, that is not possible since the image is stored as frequency domain information meaning you would need all of the data to produce any one part of the image in the original detail.

Or as I suggested in the comments, you could just save the ROI when you have it in memory if you have a limited number of ROIs and you know which ones you will need later (or even if you don't know which ones if there are not so many).

Which of those sounds like a good approach for you? I did the bmp reading at some point a long time ago, but don't have the code on hand. I could dig up the opencv code if you need that for saving ROI. It's pretty easy though.

饮惑 2025-01-09 06:05:20

我们遇到了同样的问题,最终使用 GDAL (http://www.gdal.org) 来加载图像,然后将它们转换为 IplImage。

We had the same problem and ended up using GDAL (http://www.gdal.org) for loading images and then converting them to IplImage.

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