Image Contour Extraction

Copyright Tristan Aubrey-Jones November 2006.

imedgefilter.m

home Home   up Up   ( Download )


function img = imedgefilter(im) % IMEDGEFILTER Finds borders in image % Takes the image intensity for each pixel to be the difference % in colour between it and it's neighbours. %% init im = double (im ); sz = size(im); img = zeros(sz(1), sz(2)); %% iterate over all pixels for x = 1:sz(1) for y = 1:sz(2) % get the colour at (x,y) c = im(x,y); % sum the differences between the colour % of this point (x,y) and its neighbours dc = 0; if x > 1 dc = norm(c - im(x-1,y)); end if x < sz(1) dc = dc + norm(c - im(x+1,y)); end if y > 1 dc = dc + norm(c - im(x,y-1)); end if y < sz(2) dc = dc + norm(c - im(x,y+1)); end % add this to the new image img(x,y) = dc; end end imax = max ( max (img )); imin = min ( min (img )); img = ones(sz(1), sz(2)) - (img - imin )/( imax - imin );