I'm working on an algorithm, which requires filtering of a 3D matrix (non-sparse, 512^3) to find edges.
I only want to find edges in each slice, so I have been doing the following:
filteredVolume = zeros(size(vol))
for n = 1:size(vol,3)
filteredVolume(:,:,n) = imfilter(vol(:,:,n),DGauss,'conv','symmetric');
I also tried to do the same by calling imfilter on the entire volume:
filteredVolume = imfilter(vol,DGauss,'conv','symmetric');
I compared the performance of both of these approaches, but the loop version is significantly faster (6.5 seconds to 20 seconds).
Should this behavior be expected? If so, why?