# Blockproc for 2 functions (mean/std) slower then manuel splitting of the matrix?

3 views (last 30 days)
Andreas on 9 Dec 2016
Edited: Andreas on 9 Dec 2016
Hello,
I try to optimize the processing speed and memory consumption of calculation some operations at different submatrices.
I tried the following versions:
Imagenew = Image(ys(1):ys(end),:);
meanFilterFunction = @(theBlockStructure) mean(theBlockStructure.data);
featureExtractionFunction = @(theBlockStructure) featureExtraction(theBlockStructure.data);
blockSize = [round(size(Imagenew,1)/nrows) 1];
tic
blockyImage_mean = blockproc(Imagenew, blockSize, meanFilterFunction);
t2=toc;
disp(['t2: ' num2str(t2)]);
disp(size(blockyImage_mean));
tic
blockyImage_feature = blockproc(Imagenew, blockSize, featureExtractionFunction);
t3=toc;
disp(['t3: ' num2str(t3)]);
disp(size(blockyImage_feature));
tic
for irow = 1:nrows
for iChan = 1:nChan
tmpSubImg = SubImg2(Image(:,:,iChan),round([1 yc(irow)-halfHeight, ImSize(2), height]),0);
RowMW(irow,:,iChan) = mean(tmpSubImg); % Mittelwert Zeile
RowSTD(irow,:,iChan) = std(tmpSubImg); % Mittelwert Zeile
end
end
t4=toc;
disp(['t4: ' num2str(t4)]);
function features = featureExtraction(Image) features(:,:,1) = mean(Image); features(:,:,2) = std(Image); end
and got the following results: t2: 5.0098 38 5601
t3: 12.0232 38 5601 2
t4: 6.8221
So my the blockproc function (calculating mean and std) seems to need twice the time than only calculating the mean, and even more then using loops.
What is the best way to use blockproc? What is wrong at my use of blockproc?
Thank you