% this function's purpose is to create the
% data set from which a hi-resolution will be constructed
function [ returned, offs, pre_alter_pics ] = generate_set(im, img_count, BLS)    
% BLS- the blur filter
% im - the original image
% img_count- how many smaples to create
    pdr = 0.2;% ratio for the edges 
    gaus='gaussian';
    r1=pdr * size(im, 1)/2;
    r1=round(r1);
    r2=(1 - pdr/2) * size(im, 1);
    r2=round(r2);
    rows =  r1:r2 ;
    % boundaries for the generated images
    c1=pdr * size(im, 2)/2;
    c1=round(c1);
    c2=(1 - pdr/2) * size(im, 1);
    c2=round(c2);
    cols = c1 :c2;
    
    pre_alter_pics = im(rows, cols);
    % perserve the orginial
    offs(1, :) = [ 0 0 ];
    returned{1} = im(rows, cols);  
    
    i=2;
    while( i <= img_count)
        offs(i, :) = 2 * rand - 1;% randomly choose offsets to deflect image
        tr_x = rows - offs(i, 2);
        tr_y = cols - offs(i, 1);
        [ x y ] = meshgrid(1 : size(im, 2), 1 : size(im, 1));
        [ x2 y2 ] = meshgrid(tr_y, tr_x);
        returned{i} = interp2(x, y, im, x2, y2);% distort quality
        i=i+1;
    end

    BK = fspecial(gaus, 3, BLS);
    
    for i=1:img_count
        disp(i);
        returned{i} = conv2(returned{i}, BK, 'same');
        current_photo = returned{i};
        returned{i} = current_photo(2 : 2 : end - 1, 2 : 2 : end - 1);
    end
end