rootpath = 'D:\images\'; fid = fopen('c:\files.txt','r'); while (~feof(fid)) in = textscan(fid,'%s %s',1,'delimiter','\t'); in{1} im_crop = imread(char(strcat(rootpath,in{1}))); im_orig = imread(char(strcat(rootpath,in{2}))); [im_orig_h, im_orig_w,~] = size(im_orig); if im_orig_w > im_orig_h % landscape, resizing only required. im = imresize(im_orig,[NaN 150]); else im = cropxcorr(im_crop, im_orig); end [~, name, ext] = fileparts(char(in{1})); imwrite(im, strcat(rootpath, name, '-XYZ', ext)); end