如何将图像分割为重叠的块



我想将PGM图像划分为重叠的块,并对每个块进行DCT变换。然后我想取每个DCT矩阵的第一列,把它们都放到一个新的矩阵中。

我已经阅读了帖子的答案:如何在matlab中将图像分割为64块,但我不确定它是否正常工作。我可以使用blockproc函数来制作重叠块吗?如果可以,我应该如何使用它?

我更喜欢用for循环的答案。

I=im2double(rgb2gray(imread('yourimage.png'))); %select channels separation
%%%for non-overlapping blocks
fun = @(block_struct) dct2(block_struct.data);
imageY =(blockproc(I,[8 8],fun));
BY=im2col(imageY,[8 8],'distinct');
FinalOP=BY(1:8,:);
%dct-8x8 ,if you want u can choose [64 64].
%you need the first column of dct?.so ,i.e 8 values of dct in this case.

对于重叠块:使用'sliding',但会出现内存问题。然后你必须使用你自己的for循环。

最新更新