矩阵如何存储在内存中?
注意 - 可能与计算机组织比软件更相关,不确定。
我正在尝试了解与数据压缩相关的内容,例如 jpeg 照片。本质上,一个非常密集的矩阵被转换(通过离散余弦变换)为一个更加稀疏的矩阵。据说存储的就是这个稀疏矩阵。看一下这个链接:
http://en.wikipedia.org/wiki/JPEG
比较原始 8x8 子块图像示例转换为矩阵“B”,该矩阵被转换为具有整体较低的幅度值和更多的零。矩阵 B 是如何存储的,以便比原始矩阵节省更多内存?
原始矩阵显然需要 8x8(条目数)x 8 位/条目,因为值可以从 0 到 255 随机变化。好的,所以我认为很明显我们需要 64 字节的内存。另一方面,矩阵 B,嗯。我能想到的最好的情况是值范围从 -26 到 +5,所以最多一个条目(如 -26)需要 6 位(我猜 5 位形成 26,1 位用于符号)。那么你可以存储 8x8x6 位 = 48 字节。
我看到的另一种可能性是矩阵从左上角开始以“之字形”顺序存储。然后我们可以指定起始地址和结束地址,并沿着对角线继续存储,直到只剩下零。假设它是 32 位机器;那么2个地址(开始+结束)将构成8个字节;例如,对于每个 6 位的其他非零条目,我们必须沿着几乎所有顶部对角线来存储 28 个元素的总和。该方案总共需要 29 个字节。
总结一下我的问题:如果 JPEG 和其他图像编码器声称通过使用算法降低图像矩阵的密度来节省空间,那么这些额外的空间是如何在我的硬盘中实现的?
干杯
Note - may be more related to computer organization than software, not sure.
I'm trying to understand something related to data compression, say for jpeg photos. Essentially a very dense matrix is converted (via discrete cosine transforms) into a much more sparse matrix. Supposedly it is this sparse matrix that is stored. Take a look at this link:
http://en.wikipedia.org/wiki/JPEG
Comparing the original 8x8 sub-block image example to matrix "B", which is transformed to have overall lower magnitude values and much more zeros throughout. How is matrix B stored such that it saves much more memory over the original matrix?
The original matrix clearly needs 8x8 (number of entries) x 8 bits/entry since values can range randomly from 0 to 255. OK, so I think it's pretty clear we need 64 bytes of memory for this. Matrix B on the other hand, hmmm. Best case scenario I can think of is that values range from -26 to +5, so at most an entry (like -26) needs 6 bits (5 bits to form 26, 1 bit for sign I guess). So then you could store 8x8x6 bits = 48 bytes.
The other possibility I see is that the matrix is stored in a "zig zag" order from the top left. Then we can specify a start and an end address and just keep storing along the diagonals until we're only left with zeros. Let's say it's a 32-bit machine; then 2 addresses (start + end) will constitute 8 bytes; for the other non-zero entries at 6 bits each, say, we have to go along almost all the top diagonals to store a sum of 28 elements. In total this scheme would take 29 bytes.
To summarize my question: if JPEG and other image encoders are claiming to save space by using algorithms to make the image matrix less dense, how is this extra space being realized in my hard disk?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
DCT 需要与其他利用零/高频出现的压缩方案一起使用。一个简单的例子是游程编码。
JPEG 使用霍夫曼编码的变体。
The dct needs to be accompanied with other compression schemes that take advantage of the zeros/high frequency occurrences. A simple example is run length encoding.
JPEG uses a variant of Huffman coding.
正如“熵编码”中所述,使用了锯齿形图案以及 RLE,这在许多情况下已经减少了尺寸。然而,据我所知,DCT 本身并没有给出稀疏矩阵。但它通常会增强矩阵的熵。这是压缩变得有损的点:使用 DCT 传输输入矩阵,然后对值进行量化,然后使用哈夫曼编码。
As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for many cases. However, as far as I know the DCT isn't giving a sparse matrix per se. But it usually enhances the entropy of the matrix. This is the point where the compressen becomes lossy: The intput matrix is transferred with DCT, then the values are quantizised and then the huffman-encoding is used.
最简单的压缩将利用重复的符号序列(零)。内存中的矩阵可能看起来像这样(假设在 dec 系统中)
压缩后它可能看起来像这样
The most simple compression would take advantage of repeated sequences of symbols (zeros). A matrix in memory may look like this (suppose in dec system)
After compression it may look like this
据我了解,JPEG 不仅会压缩,还会丢失数据。在8x8块转移到频繁域之后,它会丢弃不重要的(高频)数据,这意味着它只需要保存重要的6x6甚至4x4数据。它可以比非丢失方法(如 gif)具有更高的压缩率
As my under stand, JPEG on only compress, it also drop data. After the 8x8 block transfer to frequent domain, it drop the in-significant (high-frequent) data, which means it only has to save the significant 6x6 or even 4x4 data. That it can has higher compress rate then non-lost method (like gif)