matlab - Huge array because of bad algorithm? -


i trying implement segmentation algorithm , create spatial kernel image depends on distance predefined image points (stored in s) or more accurate need minimum distance of pixel in image predefined points s.

% sample s s = [4 4]; % have 2k entries  % point coordinates of every matrix position [cols, rows] = meshgrid(1:width, 1:height); ptcoords = cat(3, rows, cols);  % here problem. array gets **huge** spatdist = zeros(height, width, sumspts);  % distance current s j = 1:sumspts     currs = s(j, :);     scoords = cat(3, repmat(currs(1), height, width),  repmat(currs(2), height, width));      rowdiff = ptcoords(:,:,1) - scoords(:,:,1);     coldiff = ptcoords(:,:,2) - scoords(:,:,2);      spatdist(:,:,j) = sqrt(rowdiff.^2 + coldiff.^2);  end  % save smallest dist per group minspatdist = zeros(height, width, nsgroups); spatkernel = zeros(height, width, sumspts); spatprob = zeros(height, width, nsgroups); = 1:nsgroups;      % indices of current s     currindices = 1:nspts(i);     if(i > 1)         currindices = currindices + sum(nspts(1:i-1));     end      % min on scribble matrices of 1 group     minspatdist(:,:,i) = min(spatdist(:,:,currindices),[], 3);     roh = minspatdist .* params.alpha;      % normdistr.     % gaussian pdf value each pixel        j = currindices;          spatkernel(:,:,j) = normpdf(spatdist(:,:,j), 0, roh(:,:,i));        end      % sum on scribble matrices of 1 group     spatprob(:,:,i) = sum(spatkernel(:,:, currindices), 3); end 

i know cannot run code there way less memory usage?


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -