作为@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
根据您的应用程序,您最好修剪掉最后一个部分块,而不是使用给定值填充。您可以选择使用TrimBorder 和BorderSize 选项执行此操作,它们将对称地修剪像素。