function KernelCell=kernel2cellmat(Kernel,varargin)
%--------------------------------------------------------------------------
% kernel2cellmat function                                          ImBasic
% Description: Convert a set of kernels into a cell array of matrices.
%              OBSOLETE: Use Kernel2.cellmat instead.
% Input  : - A set of kernels. This can be:
%            A ClassPSF object.
%            A matrix.
%            A function.
%            A cell array of matrices.
%            A cell array of functions.
%          * Arbitrary number of arguments.
%            If the first input argument is a ClassPSF object these
%            arguments will be passed to getmpsf.m. If the first input
%            argument is a function or cell of functions, then these
%            arguments will be passed to the function.
%            If this is a single cell array than it will be assumed that
%            each element of the cell array is a cell array that will be
%            passed to the corresponding function (see example).
% Output : - A cell array of matrices. Each matrix represent the kenel.
% License: GNU general public license version 3
% Tested : Matlab R2015b
%     By : Eran O. Ofek                    Jun 2016
%    URL : http://weizmann.ac.il/home/eofek/matlab/
% Example: KernelCell=kernel2cellmat(rand(11,11));
%          KernelCell=kernel2cellmat({rand(11,11)});
%          KernelCell=kernel2cellmat(@kernel_gauss);
%          KernelCell=kernel2cellmat({@kernel_exp},3);
%          KernelCell=kernel2cellmat({@kernel_exp,@kernel_gauss},{{3},{2,2}});
% Reliable: 2
%--------------------------------------------------------------------------



if (isclasspsf(Kernel)),
    % kernel is a ClassPSF object
    KernelCell = getmpsf(Kernel,varargin{:});
elseif (isnumeric(Kernel)),
    % Kernel is a matrix
    KernelCell = {Kernel};
elseif (isa(Kernel,'function_handle')),
    % Kernel is a function
    KernelCell = {Kernel(varargin{:})};
elseif (iscell(Kernel)),
    Ncell      = numel(Kernel);
    KernelCell = cell(Ncell,1);
    for Icell=1:1:Ncell,
        if (isnumeric(Kernel{Icell})),
            % Kernel cell element is a matrix
            KernelCell{Icell} = Kernel{Icell};
        elseif (isa(Kernel{Icell},'function_handle')),
            % Kernel cell element is a function 
            if (numel(varargin)>0),
                if (iscell(varargin{1})),
                    Par = varargin{1}; %{Icell};
                else
                    Par = varargin;
                end
            else
                Par = {};
            end
            KernelCell{Icell} = Kernel{Icell}(Par{Icell}{:});
        else
            error('Unknown Kernel input option');
        end
    end
else
    error('Unknown Kernel input option');
end

        
        
        
        