方法一
如果您有图像处理工具箱,这是首选且最有效的方法。它利用了非常有用的blockproc 功能,该功能专为处理大块图像而设计。例如,当您的图像没有平均分成相同大小的块并将块处理的结果连接到一个结果矩阵时,它会处理填充。
最好看一下official documentation,但您的情况如下:
vSize = [17935 10968];
imBig = rand([vSize 3]);
nParts = [2 2]; %means divide into 4 parts, 2 horizontal, 2 vertical
blockproc(imBig, ceil(vSize ./ nParts), @yourAlgorithm);
function res = yourAlgorithm(blockStruct)
%do your processing of the block here and
%optionally return a result in 'res'
%for example, just return the RGB vector of the first pixel
res = blockStruct.data(1,1,:);
end
方法二
如果您没有图像处理工具箱,您可以改用mat2cell 函数。首先计算出所需的块大小,然后得到一个包含不同块的元胞数组。但是,对于如此大的图像,速度和内存可能会成为问题。代码借自this Matlab Central 答案。
vSize = [17935 10968];
imBig = rand([vSize 3]);
nParts = [2 2]; %means divide into 4 parts, 2 horizontal, 2 vertical
%figure out the size of "regular" block and the last block
vRegBlockSize = ceil(vSize ./ nParts);
vLastBlockSize = vSize - vRegBlockSize .* (nParts - 1);
%put the sizes into a vector
vSplitR = [vRegBlockSize(1)*ones(1,nParts(1)-1), vLastBlockSize(1)];
vSplitC = [vRegBlockSize(2)*ones(1,nParts(2)-1), vLastBlockSize(2)];
%split the image
C = mat2cell(imBig, vSplitR, vSplitC, 3);
%access RGB pixel (x,y) in top left {1,1} block
p = C{1,1}(x, y, :);