Files
jens 7b34529b24 imported RBM
git-svn-id: http://moon:8086/svn/matlab/trunk@91 801c6759-fa7c-4059-a304-17956f83a07c
2016-07-12 11:24:12 +00:00

26 lines
733 B
Matlab

function patches = samplePatches(rawImages, patchSize, numPatches)
% rawImages is of size (image width)*(image height) by number_of_images
% We assume that image width = image height
imWidth = sqrt(size(rawImages,1));
imHeight = imWidth;
numImages = size(rawImages,2);
rawImages = reshape(rawImages,imWidth,imHeight,numImages);
% Initialize patches with zeros.
patches = zeros(patchSize*patchSize, numPatches);
% Maximum possible start coordinate
maxWidth = imWidth - patchSize + 1;
maxHeight = imHeight - patchSize + 1;
% Sample!
for num = 1:numPatches
x = randi(maxHeight);
y = randi(maxWidth);
img = randi(numImages);
p = rawImages(x:x+patchSize-1,y:y+patchSize-1, img);
patches(:,num) = p(:);
end