我用matlab编写了一个函数。我想将图片分成4(2 * 2)部分。我的代码是
function [new_file] = divide( input_file)
picture_file = imread(input_file); % read input picture file
[rows , cols , colors] = size(picture_file);
n=2;
height = floor(rows/n);
width = floor(cols/n);
new_file = zeros(height*n, width*n, colors);
for i = 1:n
for j = 1:n
temp = picture_file((i-1)*height+1:i*height,(j-1)*width+1:j*width,:);
new_file((i-1)*height+1:i*height,(j-1)*width+1:j*width,:) = temp;
figure;
imshow(temp);
figure;
imshow(new_file((i-1)*height+1:i*height,(j-1)*width+1:j*width,:));
end
end
end
temp
和new_file((i-1)*height+1:i*height,(j-1)*width+1:j*width,:)
是相等的矩阵。但是显示不同的图片。为什么会这样?