function X = loadcroppedimages(fname, dim, frames, n, coords)



coords = round(coords);

coords(:,1) = bracket(coords(:,1), n/2+1, dim(2) - n/2-1);
coords(:,2) = bracket(coords(:,2), n/2+1, dim(1) - n/2-1);

num = length(frames);

for i = 1:num
  I = load_frames(fname,dim,frames(i));
  I = reshape(I,dim(1),dim(2));
  
  I = I( (coords(i,2)-n/2):(coords(i,2)+n/2-1), (coords(i,1)-n/2):(coords(i,1)+n/2-1) );
  
  %image(I);

  X(:,i) = I(:);
end
  
