我想写一个matlab代码,将图像划分为子图像10x10(原始图像为100x100)

时间:2013-12-03 14:53:22

标签: matlab

S=imread(img2.gif); 
for img=1:100;
   C = mat2cell(S,[10 10],[10 10]);
   plot(C);
end

1 个答案:

答案 0 :(得分:0)

以下代码将图像分成指定大小的子图像。

im = imread('peppers.png');
widthSub = 10;
heightSub = 10;
numHeightFull = floor(size(im,1)/heightSub);
numWidthFull = floor(size(im,2)/widthSub);
if mod(size(im,1),heightSub) == 0
    heights = heightSub*ones(1,numHeightFull);
else
    heights = [heightSub*ones(1,numHeightFull),mod(size(im,1),heightSub)];
end
if mod(size(im,2),widthSub) == 0
    widths = widthSub*ones(1,numWidthFull);
else
    widths = [widthSub*ones(1,numWidthFull),mod(size(im,2),widthSub)];
end
if ndims(im) < 2 
    subImages = mat2cell(im,heights,widths);
elseif ndims(im) > 2
    subImages = mat2cell(im,heights,widths,size(im,3));
end