function T = bsq2tensorflow(I, n) sx = size(I, 1); sy = size(I, 2) / n; %get the size of the tensor along Y sb = size(I, 3); T = zeros(sx * sy * sb, n); %allocate space for the output matrix for i = 0:n-1 ti = I(:, i * sy + 1 : i * sy + sy, :); T(:, i+1) = ti(:); end end