I'm making an algorithm which extracts information from images - most of these informations are energy-like data. This is basically done by running through the image with a kernel (size is given as parameter), and get the squared sums of values in that kernel.
This is done in three scales, where the three kernel (patch) sizes are (at this point): smallestPatchSize, smallestPatchSize * 3, smallestPatchSize * 9 (with overlapping kernels in the second and third case). This is done for several color channels, gradient filters, etc (17 of these altogether).
My question is whether it is possible to vectorize the code below; obviously this part of the code requires much more time to run than any other. I'm quite a beginner in Matlab and still try to get the hang of vectorization but this one beats me :)
for dim = 1:17
for i = 1:smallestPatchSize:(size(image,1) - currentPatchSize)
for j = 1:smallestPatchSize:(size(image,2) - currentPatchSize)
% calculate the position in the energy matrix
% which has different dimensions than the input pictures
iPosition = (i - 1 + smallestPatchSize) / smallestPatchSize;
jPosition = (j - 1 + smallestPatchSize) / smallestPatchSize;
% calculate the energy values and save them into the energy matrix
energy(iPosition, jPosition, dim) = sum(sum(abs(...
filters(i:i+currentPatchSize, j:j+currentPatchSize,dim)))) ^ 2;
end
end
end
Thanks in advance - this is my first question @ StackOverflow :)