【问题标题】:How to quantise an image with an 8x8 matrix using blockproc in matlab?如何在 matlab 中使用 blockproc 量化具有 8x8 矩阵的图像?
【发布时间】:2016-10-27 23:56:08
【问题描述】:

这个想法来自 jpeg 压缩,您可以将量化矩阵 (8x8) 逐块应用于(余弦变换)图像。

funQY = @(block_struct) (block_struct.data)./quantY;
QY = blockproc(dctY, [8 8], funQY);

dctY 是一个 2D 矩阵,表示图片的亮度 (2856x4290)。 quantY 是对应的量化矩阵(8x8)。

错误消息说矩阵尺寸不一致。 block_struct.data 不代表来自 dctY 的 8x8 块吗?如果是这样,为什么不能用 8x8 矩阵来划分?我的错误是什么?

【问题讨论】:

  • 我怀疑这是因为4290 不是 8 的偶数倍。
  • 可以分享整个脚本和图片吗?

标签: matlab image-processing


【解决方案1】:

作为@beaker noted in a comment,原因是您的图像大小不能与块的大小整除。这是一个简单的例子,我们检查传递给blockproc中函数的每个块的大小:

dctY = rand(24,34); % first dim is divisible, second is not
funtmp = @(block_struct) size(block_struct.data);
blockproc(dctY,[8 8],funtmp)

返回

ans =

     8     8     8     8     8     8     8     8     8     2
     8     8     8     8     8     8     8     8     8     2
     8     8     8     8     8     8     8     8     8     2

正如您在最右侧看到的那样,每个块行中的最后一个块是大小为[8, 2] 的部分块。

你可以使用the PadPartialBlocks option of blockproc:

'PadPartialBlocks'  A logical scalar.  When set to true, blockproc will
                    pad partial blocks to make them full-sized (M-by-N)
                    blocks.  Partial blocks arise when the image size
                    is not exactly divisible by the block size.  If
                    they exist, partial blocks will lie along the right
                    and bottom edge of the image.  The default is
                    false, meaning the partial blocks are not padded,
                    but processed as-is.

                    blockproc uses zeros to pad partial blocks when
                    necessary.

这会导致

>> blockproc(dctY,[8 8],funtmp,'padpartialblocks',true)

ans =

     8     8     8     8     8     8     8     8     8     8
     8     8     8     8     8     8     8     8     8     8
     8     8     8     8     8     8     8     8     8     8

根据您的应用程序,您最好修剪掉最后一个部分块,而不是使用给定值填充。您可以选择使用TrimBorderBorderSize 选项执行此操作,它们将对称地修剪像素。

【讨论】:

  • 通过将图像切割几个像素到可被 8 整除的值来解决问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多