function save_as_stack(img, save_name)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here


outputFileName = [save_name, '.tif'];
%{
if exist(outputFileName, 'file'), delete(outputFileName), end;
pause(1);
%}

if length(size(img)) == 3,
    imwrite(img(:, :, 1), outputFileName, 'WriteMode', 'overwrite');
    for K=2:length(img(1, 1, :))
        imwrite(img(:, :, K), outputFileName, 'WriteMode', 'append');
    end
else
    imwrite(img, outputFileName, 'WriteMode', 'overwrite');
end


end

