我对一张图进行的分块并且保存分块的简单实现:
[FileName,PathName] = uigetfile('*.*','Select the image');
Im=imread([PathName FileName]);
imshow(Im)
hold on
L = size(Im);
height=64;
width=64;
max_row = floor(L(1)/height);
max_col = floor(L(2)/width);
seg = cell(max_row,max_col);
%分块
for row = 1:max_row
for col = 1:max_col
seg(row,col)= {Im((row-1)*height+1:row*height,(col-1)*width+1:col*width,:)};
end
end
for i=1:max_row*max_col
imwrite(seg{i},strcat('m',int2str(i),'.bmp'));
end
%画出分块的边界
for row = 1:max_row
for col = 1:max_col
rectangle('Position',[160*(col-1),160*(row-1),160,160],...
'LineWidth',2,'LineStyle','-','EdgeColor','r');
end
end
hold off
后面贴一个小方法:
A=rand(256,64);
%将A分块
B=mat2cell(A,ones(256/16,1)*16,ones(64/16,1)*16);
%B{i,j}就是所要的分块矩阵
%将分块矩阵合并
C=cell2mat(B)
%C就是合并好的矩阵,即C=A