function RMAP = region_grow(IN, RMAP, v, h, tolerance, center)

%get size of image

[a,b] = size(IN);

%find max of image and determine tolerange step

imax = max(max(IN));
tstep = tolerance*imax;

%grow the region

for j = -1:1,
  for k = -1:1,
    if (v+j) > 0 & (h+k) > 0 & (v+j) <= a & (h+k) <= b
	if RMAP(v+j, h+k) == .5
	  diff = abs(IN(v+j, h+k) - center);
	  if diff < tstep
	    RMAP(v+j, h+k) = 1;
	    RMAP = region_grow(IN, RMAP, v+j, h+k, tolerance, center);
	  else
	    RMAP(v+j, h+k) = 0;
	  end
	end
    end
  end
end

