I am trying to use recursion to apply region growing but I have got an error: Out of memory. The likely cause is an infinite recursion within the program.
I am posting the code snippet here,Can somebody point out the error and make suggestions.Thank you.
Here,Ig is the grayscale image with intensities to check
i is column vector containing x-coordinates of seed pixels
j is column vector containing y-coordinates of seed pixels
threshold is column vector containing threshold values for seed pixels
reg_output is the final logical array output after region growing ,
visited is a matrix used to prevent redundant computations using recursion,
%REGION GROWING FROM ALL LOW INTENSITY PIXELS
global reg_output;reg_output = zeros(size(Ig));global visited;visited = zeros(size(Ig));global row;global col;row = [-1;-1;-1;0;0;1;1;1];col = [-1;0;1;-1;1;-1;0;1];global si;global sj;[si,sj] = size(Ig);for ll = 1:length(i) region_grow(i(ll),j(ll),threshold(ll));endfigure,imshow(reg_output)function region_grow(m,n,t)global reg_output;global visited;global Ig;global row;global col;global si;global sj;reg_output(m,n) = 1;visited(m,n) = 1;for kc = 1:length(row) i = m+row(kc); j = n+col(kc); if i>=1 && i<=si && j>=1 && j<=sj if visited(i,j)==0 && Ig(i,j)>= t region_grow(i,j,t); end endendend
Best Answer