function [Xh, Xl] = rnd_smp_patch(img_path, par) %type, par.patch_size, par.num_patch, par.upscale)

img_dir = [dir(fullfile(img_path, '*.bmp')); dir(fullfile(img_path, '*.png')); dir(fullfile(img_path, '*.jpg'))];

Xh = [];
Xl = [];

img_num = length(img_dir);
nper_img = zeros(1, img_num);

for ii = 1:length(img_dir),
    im = imread(fullfile(img_path, img_dir(ii).name));
    nper_img(ii) = numel(im);
end

nper_img = floor(nper_img*par.num_patch/sum(nper_img));

for ii = 1:img_num,
    patch_num = nper_img(ii);
    im = imread(fullfile(img_path, img_dir(ii).name));
    [H, L] = sample_patches(im, patch_num, par);
    Xh = [Xh, H];
    Xl = [Xl, L];
    disp(ii/img_num);
end

% patch_path = ['Training/rnd_patches_' num2str(par.patch_size) '_' num2str(par.num_patch) '_s' num2str(par.upscale) '.mat'];
% save(patch_path, 'Xh', 'Xl');