为什么相等矩阵显示不同的图片?

时间:2019-05-06 09:47:55

标签: matlab

我用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

tempnew_file((i-1)*height+1:i*height,(j-1)*width+1:j*width,:)是相等的矩阵。但是显示不同的图片。为什么会这样?

0 个答案:

没有答案