 function save_image(self, ref)
   % funkce pro uložení snímku, celého datasetu výsledku, residuálního
   % snímku do složky Results

   % self..struct, kde je název algoritmu (alg_name) a data
   % ref.. reference
            % directory
            folder = io.check_folder("Results/");
            folder_name = strcat(folder,self.alg_name, "_results");
            save_dir = io.check_folder(folder_name);

            % saving the whole matrix
            X= self.data;
            file_name = strcat(save_dir,"\", self.alg_name);
            save(strcat(file_name, "_data.mat"),'X');
            
            middle = 244;
            figure,imshow(X(:,:,middle),[])
            savefig(strcat(file_name,".fig"))
     
            fprintf(strcat("Figure of middle slice saved to ", folder_name, ".  \n"))

            X(:,:,middle) = rescale(X(:,:,middle));
            self.res = (self.data)-(ref);
            self.res(:,:,middle) = rescale(self.res(:,:,middle));

            imwrite(uint16(X(:,:,middle)*2^16),strcat(file_name,".tif"));
            imwrite(uint16(self.res(:,:,middle)*2^16),strcat(file_name,"_residual",".tif"));

            figure,imshow(self.res(:,:,middle),[])

            
end
