% The variable I should contain your image

% This is how many patches to take per image
 samplesize = 10000;

%This is size of the window in pixels (along one dimension)
 winsize=16;

% Initialize the matrix to hold the patches
 X = zeros(winsize^2,samplesize);


 sizex = size(I,2); sizey = size(I,1);
 posx = floor(rand(1,samplesize)*(sizex-winsize-2))+1;
 posy = floor(rand(1,samplesize)*(sizey-winsize-1))+1;
  
 for j=1:samplesize
 X(:,j) = reshape( I(posy(1,j):posy(1,j)+winsize-1, ...
			posx(1,j):posx(1,j)+winsize-1),[winsize^2 1]);
 end 
  
