function imagenorm

jpg_dir = 'J:\Research\CVPR10_ori\Dataset\NewDataset\annotation\images\Play_Bassoon\*.jpg';
img_dir = 'J:\Research\CVPR10_ori\Dataset\NewDataset\annotation\images\Play_Bassoon\';
ann_dir = 'J:\Research\CVPR10_ori\Dataset\NewDataset\annotation\annotation\Play_Bassoon\';
dst_img_dir = 'J:\Research\CVPR10_ori\Dataset\NewDataset\OriAnn\';
% return names of all images and folders in image_dir
image_lists = dir(jpg_dir);


for i = 1 : length(image_lists)
    i
    img_path = [img_dir image_lists(i).name];
    [dir_t, filename, ext] = fileparts(img_path);
    ann_path = [ann_dir, filename, '.txt'];

    if (exist(ann_path, 'file'))
        img = imread(img_path);
        ann = load(ann_path);
        for j = 1 : size(ann, 1)
            % image_height / 256 = face_size / 32;
            scale_ratio = (ann(j,4) - ann(j,2)) / 32;
            scaled_img = imresize(img, scale_ratio);
            disp('finished resizing');
            ref_point = [(ann(j,1) + ann(j,3))/2, ann(j,2)];
            
            new_img = 128 .* ones(160, 256, size(scaled_img,3));
            bound_left = max(1, ref_point(1)-79);
            bound_right = min(size(scaled_img,2), ref_point(1)+80);
            bound_top = max(1, ref_point(1)-63);
            bound_bottom = min(size(scaled_img,1), ref_point(2)+192);
            new_img(bound_top:bound_bottom, bound_left:bound_right, :) ...
                = scaled_img(bound_top:bound_bottom, bound_left:bound_right, :);
            
            dst_img_path = [dst_img_dir, filename, '.jpg'];
            imwrite(new_img, dst_img_path);
        end
    end
end