Make code for svm region descriptors more efficient

2 次查看(过去 30 天)
I'm having a rather large image (32000 x 32000) where I have detected regions of interest ("blobs" of approx. size of 150 cells). In the end I would like to have a Mean/Standard deviation descriptor for each region/blob to feed into a svm.
I've written the following function, which worked fine for smaller image subsets (6000x10000), to test the code. But when applying it on the whole image (32000x32000) it already takes ages to calculate the descriptor for 400 regions (and I will have to calculate it for over a million regions in the end).
dimDescriptor = size(Image,3)*2;
MeStdDescriptor = zeros(size(points,1),dimDescriptor);
for i = 1:size(points,1)
for band = 1:size(Image,3)
banddata = Image(:,:,band);
MeStdDescriptor(i,band) = mean(banddata(regionMask==i));
MeStdDescriptor(i,band+4) = std(banddata(regionMask==i));
end
end
"Points" is a vector with all the unique numbers of my regions/blobs (here 1:400). "regionMask" is a mask (same size as image), which I have created in advance, where every region/blob has a unique number and the rest is zero.
Does anybody have a suggestion of how to improve this code to make it faster? Thank you very much!

采纳的回答

Kushagr Gupta
Kushagr Gupta 2017-3-15
There are various different approaches that you could make use of to improve the speed, for example resizing, preprocessing the dataset into smaller segments among others.
Following are some ideas that may help:
1. Resizing the image into a smaller image which still contains useful information. Go through the documentation of the ' imresize ' function to see if it could help.
2. Extracting required information over segments. Another MATLAB Answers post discusses this: Extract Mean over segments
3. If you have access to GPU hardware, 'gpuArray' could help in making the code run faster. Go through the documentation of ' gpuArray ' to learn more.
4. There is also the Parallel Computing Toolbox which is again requires more hardware resources, but executes tasks in parallel (as the name suggests) and can prove to be handy for such applications.
  1 个评论
Sandra Roth
Sandra Roth 2017-3-16
Thank you for your answer. I will try to resize the image and adjust my code according to the recommendations in 'Extract Mean over segments' post.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by