Out of Memory using bsxfun MATLAB

人盡茶涼 提交于 2019-12-25 03:44:46

问题


I try to implement image compression using Burrows-Wheeler transform. Consider an 1D matrix from path scanning is:

p = [2 5 4 2 3 1 5];

and then apply the Burrows-Wheeler transform :

function output = bwtenc(p) 
n = numel(p);
x = zeros(length(p),1);
for i = 1:length(p)
    left_cyclic = mod(bsxfun(@plus, 1:n, (0:n-1).')-1, n) + 1;
    x = p(left_cyclic);
end
[lex ind] = sortrows(x);
output = lex(:,end);
output = uint8(output(:)');
end

And it works! But the problem is when i try to implement 1D matrix from Lena.bmp which the size is 512*512, Error message showing that bsxfun is out of memory. Anyone please help me.


回答1:


See if this works for you -

function output = bwtenc(p) 
np = numel(p);
[~,sorted_ind] = sort(p);
ind1 = mod((1:np)+np-2,np)+1;
output = p(ind1(sorted_ind));
output = uint8(output(:)');
end


来源:https://stackoverflow.com/questions/25857880/out-of-memory-using-bsxfun-matlab

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