% this file summons all the other files,
function prepareForSecondAlgorithm(varargin)
  
    if(nargin==0)
        img_path='C:\Users\USER\Pictures\Etgar\pic20-1.jpg';
    elseif (strcmp(class(varargin {1}),'char'))
        img_path = varargin {1};
    end
    
    if(nargin>1 && strcmp(class(varargin {2}),'cell'))
        dataset=varargin{2};
        flag=1;
    else
        flag=0;
    end
    %resize and store in test folder
    img = imread(img_path);
    maxSize = max(size(img,1), size(img,2));
    if (maxSize > 400)
        img = imresize(img, (400/maxSize));
    end
    
    past_dir=pwd;
    cd('C:\Users\USER\Documents\MATLAB\SRmatlab\Matlab');
    %this is supposed to be the root dir
    % of the installation
    img_path=strcat('..\DataBase\Berkeley\Test\image\','temp_pic.jpg');
    imwrite(img,img_path);
    img = imread(img_path);
    if(flag==0)
            j=0;
            span=1.5;
            step=0.15;
            starter=0.5;
            len=round(span/step);
            scaled_imgs=cell(1,len);

            for i=starter:step:starter+span
                j=j+1;
                 scaled_imgs{j}=imresize(img,i); 
            end
    else
            scaled_imgs=cell(1,length(dataset));
             len=length(scaled_imgs);
            for i=1:len
                 scaled_imgs{i}=imread(dataset{i});
            end
    end
            for i=1:len
                imwrite(scaled_imgs{ i }, strcat('..\Database\Berkeley\Training\Image\image_',num2str(i),'.jpg'));
            end
            
            GenerateTraining
            % Now the algorithm has studied the scaled images.
            SuperResolution
            
                        
            for i=1:len
               delete(strcat('..\Database\Berkeley\Training\Image\image_',num2str(i),'.jpg'));       
            end
            
            cd(past_dir);
            imshow(img);
     %       delete(img_path);

    
    
end


function directory = split_file(path)
    i=length(path);

    while(i>=1)
        if(path(i)=='\')
            break;
        end
        i=i-1;
    end
    j=1;
    directory='';
    while(j<=i)
        
        directory=strcat(directory,path(j));
        j=j+1;
    end

end
