存储对图像的一系列小更改的简单但有效的方法?

发布于 2024-08-27 17:14:09 字数 356 浏览 9 评论 0原文

我有一系列图像。每个区域通常(但并非总是)与前一个相似,更新了 3 或 4 个小矩形区域。我需要使用最少的磁盘空间来记录这些更改。

源图像未压缩,但我希望压缩增量。

我需要能够完全按照输入重新创建图像(因此有损视频编解码器不合适。)

我正在考虑以下内容:

  • 将新图像与旧图像的负片合成
  • 将合成图​​像保存在任何格式中可以使用 RLE 压缩的通用格式(可能是 PNG)。
  • 通过将前一个图像与增量合成来重新创建第二个图像。

尽管图像具有 Alpha 通道,但出于此函数的目的,我可以忽略它。

是否有易于实现的算法或具有此功能的免费 Java 库?

I have a series of images. Each one is typically (but not always) similar to the previous one, with 3 or 4 small rectangular regions updated. I need to record these changes using a minimum of disk space.

The source images are not compressed, but I would like the deltas to be compressed.

I need to be able to recreate the images exactly as input (so a lossy video codec is not appropriate.)

I am thinking of something along the lines of:

  • Composite the new image with a negative of the old image
  • Save the composited image in any common format that can compress using RLE (probably PNG.)
  • Recreate the second image by compositing the previous image with the delta.

Although the images have an alpha channel, I can ignore it for the purposes of this function.

Is there an easy-to-implement algorithm or free Java library with this capability?

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

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

发布评论

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

评论(3

姜生凉生 2024-09-03 17:14:09

使用现有的无损压缩器(PNG、无损 JPEG 等)在仅包含更改的图像上进行一些实验(您可以使用 PNG 的透明背景或某种统一的颜色)。这些算法在压缩基本恒定的图像时非常有效,如果您不是专家,您将无法击败它们。

Experiment a little with existing lossless compressors -- PNG, lossless JPEG, etc -- on an image consisting of the changes only (you can use transparent background for PNG, or some uniform color). These algorithms are very efficient when it comes to compressing an image which is mostly constant, you'll not be able to beat them if you are not an expert.

帅的被狗咬 2024-09-03 17:14:09

如果矩形的数量通常很小,并且矩形本身也很小,您可以找出有差异的行和列,用它来得出可能不同的矩形......

想象一下具有以下像素值的图像。 ...

0 0 0 1 1 1 2 2 3 3
0 0 1 1 0 0 1 1 2 2
0 0 1 1 0 0 0 1 1 2
0 0 1 1 0 0 0 1 1 2
0 1 1 0 0 3 0 0 1 1
0 1 1 0 0 3 0 0 1 1
0 0 1 1 0 0 0 1 1 2
0 0 1 1 0 0 0 1 1 2
0 0 0 1 1 1 1 1 0 2
2 2 2 2 2 1 1 2 2 2

并且...

0 0 0 1 1 1 2 2 3 3
0 1 1 1 0 0 1 1 2 2
0 1 2 4 0 0 0 1 1 2
0 1 2 3 0 0 0 1 1 2
0 1 1 0 0 3 0 0 1 1
0 1 1 0 0 3 0 0 1 1
0 0 1 1 0 3 3 2 1 2
0 0 1 1 0 3 3 2 1 2
0 0 0 1 1 2 2 2 0 2
2 2 2 2 2 1 1 2 2 2

首先,您将提出一个掩码,其中像素行、行和列有差异...

    0 1 1 1 0 1 1 1 0 0

0   0 0 0 0 0 0 0 0 0 0
1   0 1 0 0 0 0 0 0 0 0
1   0 1 1 1 0 0 0 0 0 0
1   0 1 1 1 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
1   0 0 0 0 0 1 1 1 0 0
1   0 0 0 0 0 1 1 1 0 0
1   0 0 0 0 0 1 1 1 0 0
0   0 0 0 0 0 0 0 0 0 0

行和列数据为我们提供了关于哪里可能存在矩形的指导...

    0 1 1 1 0 1 1 1 0 0

0   0 0 0 0 0 0 0 0 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
0   0 0 0 0 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
0   0 0 0 0 0 0 0 0 0 0

迭代每个可能的矩形并确定是否有变化,然后对它们进行编码。如果需要,您可以添加其他散列轴而不是行和列...就像您可以将图片细分为区域并散列某个区域是否有任何更改,然后使用散列来决定某个区域是否需要被编码。您可以执行任意次数,并且有一个相当快的算法,也可以生成小文件。

不管怎样,我认为最好的选择是构建一个已更改内容的地图,并使用聚合来告诉您块是否已更改,以指导您的决策。如果你收集了足够多的这些,你甚至可以创建几个不同的算法,在不同的情况下都能很好地工作,然后将它们放入责任链中,该责任链根据你构建的映射和哈希的特征决定使用哪种算法。

If the number of rectangles is typically small, and the rectangles themselves are small, you can makes out rows and columns with differences, use that to come up with rectangles that might be different...

Imagine the images with the following pixel values...

0 0 0 1 1 1 2 2 3 3
0 0 1 1 0 0 1 1 2 2
0 0 1 1 0 0 0 1 1 2
0 0 1 1 0 0 0 1 1 2
0 1 1 0 0 3 0 0 1 1
0 1 1 0 0 3 0 0 1 1
0 0 1 1 0 0 0 1 1 2
0 0 1 1 0 0 0 1 1 2
0 0 0 1 1 1 1 1 0 2
2 2 2 2 2 1 1 2 2 2

...and...

0 0 0 1 1 1 2 2 3 3
0 1 1 1 0 0 1 1 2 2
0 1 2 4 0 0 0 1 1 2
0 1 2 3 0 0 0 1 1 2
0 1 1 0 0 3 0 0 1 1
0 1 1 0 0 3 0 0 1 1
0 0 1 1 0 3 3 2 1 2
0 0 1 1 0 3 3 2 1 2
0 0 0 1 1 2 2 2 0 2
2 2 2 2 2 1 1 2 2 2

First you would come up with a mask of which pixels rows, rows, and columns had differences...

    0 1 1 1 0 1 1 1 0 0

0   0 0 0 0 0 0 0 0 0 0
1   0 1 0 0 0 0 0 0 0 0
1   0 1 1 1 0 0 0 0 0 0
1   0 1 1 1 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
1   0 0 0 0 0 1 1 1 0 0
1   0 0 0 0 0 1 1 1 0 0
1   0 0 0 0 0 1 1 1 0 0
0   0 0 0 0 0 0 0 0 0 0

The row and column data give us guidance as to where there might be rectangles...

    0 1 1 1 0 1 1 1 0 0

0   0 0 0 0 0 0 0 0 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
0   0 0 0 0 0 0 0 0 0 0
0   0 0 0 0 0 0 0 0 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
1   0 ? ? ? 0 ? ? ? 0 0
0   0 0 0 0 0 0 0 0 0 0

Iterate over each of the possible rectangles and decide if there are changes or not and then encode them. You can add other hashing axes instead of rows and columns, if you need to... like you can subdivide the picture into regions and hash on whether a region has any changes, then use the hash to decide whether or not a region needs to be encoded. That you could do an arbitrary number of times and have a reasonably quick algorithm that also produces small files.

Whatever the case, I think your best bet is to build a map of what has been changed and use aggregates that tell you if blocks have been changed to guide your decision-making. If you collect enough of these, you could even create a couple different algorithms that do good jobs under different circumstances and then put them in a Chain of Responsibility that decides which algorithm to use based on the characteristics of the map and hashes you built.

兔小萌 2024-09-03 17:14:09

如果更改将保持矩形,您可以单独保存这些部分,即原始图像加上更改及其位置。

If the changes are going to stay rectangular you could save these sections separately, i.e. the original image plus the changes and their positions.

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