# 用MATLAB对图片进行切割及复原

SkipStep=8;%每一个切割后的图片块的大小 和遍历的补偿
M=8;%图片块的长
N=8;%图片块的宽
n=0;%图片块的编号
I = im2double(I);
%imshow(I);
%I=rgb2gray(I);%灰度转化
[H,W,t]=size(I);
xStepNum = floor((W-N)/SkipStep+1);%朝负无穷方向取整 宽度方向block移动的次数        
     yStepNum = floor((H-M)/SkipStep+1);%朝负无穷方向取整  高度y方向移动的次数
for j=1:xStepNum%一列一列来取的
for m=1:yStepNum

n=n+1;
PImg=I((m-1)*SkipStep+1:(m-1)*SkipStep+M,(j-1)*SkipStep+1:(j-1)*SkipStep+N,:);%分割图像
a = strcat('/home/k40/caffe-master/matlab/demo/tupian/2/4/',num2str(n),'.png');%存储的图片的位置及每幅图片块的命名
imwrite(double(PImg),a);

end
end


N = 8;
M = 8;
stepsize = 8;
n = 0;
I = zeros(256,256,3);%原图片的大小为256*256的彩色图

x = 256 / N;
y = 256 / M;

for i = 1 : x
for j = 1 : y
n = n + 1;
a = strcat('/home/k40/caffe-master/matlab/demo/tupian/2/2_4/',num2str(n),'.png');%存储的切割的图片块的位置及每幅图片块的命名
A = im2double(A);
I((j-1)*stepsize+1 : (j-1)*stepsize+M,(i-1)*stepsize+1 : (i-1)*stepsize+N,:) = A;
end
end
w = strcat('/home/k40/caffe-master/matlab/demo/tupian/2/total4.png');%将合成的图片存储的位置及命名
imwrite(double(I),w);
imshow(double(I));

04-16

12-08
08-08 2158
06-13
05-11
03-12
01-05 2万+
04-12 1728
12-03 3555
04-18 670
12-21
07-20
11-05