Any other approach for Fasters implementation - matlab cell array

孤街醉人 提交于 2019-12-12 02:53:24

问题


I have an image; I am running a loop over it and creating a cell array. But the process for all the values is very slow. Is it any way possible to fasten the process?

Or any other way to do this faster?

Any help would be appreciated.

  [a,b] = size(depth);
  for i=1:a   % a = 1024
   for j=1:b  %b = 1360

    if isfinite(depth(i,j))
                segId = (label(i,j));
                if (segId > 0)
                  mycell{1,idx,segId} = {i,j,depth(i,j)};
                  idx=idx+1;       
                end 
             end
           end
         end

回答1:


Instead of updating the size of mycell each interaction, create the cell structure beforehand. That should fasten it a bit.

Nevertheless, you are evaluating all the points of a image. Why not make some mathematical operations?

[rol,col] = find(depth(depth>0)) - I quick scan your code, your are looking for this values I think.

this gives you the positions in your image that you wanna find. Maybe you just need to put this on a for cycle and it will be faster.




回答2:


This is much faster than earlier approach. Thanks for the help.

    [row,col] = find(~(isnan(depth)));

    len = length(row);

    for i= 1:len            
       segId = (label(row(i),col(i)));
       if (segId > 0)
            mycell{1,idx,segId} = {row(i),col(i),depth(row(i),col(i))};
            idx=idx+1;
       end
    end


来源:https://stackoverflow.com/questions/36689941/any-other-approach-for-fasters-implementation-matlab-cell-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!