function [m,ws] = mmiwatershed( f, Bc ) % MMIWATERSHED Interactive watershed from markers. % % [M,WS] = MMIWATERSHED( F, BC ) % % Input: % F - Gray-scale (uint8 or uint16) or binary image (logical uint8). % BC - Structuring element. Connectivity. DEFAULT: mmsecross. % % Output: % [M,WS] - Gray-scale (uint8 or uint16) or binary image (logical % uint8). % % The image is interactively segmented by placing markers with the % mouse. The markers are placed by pointing the mouse and press any % mouse button or key. Each key is associated to a different label, % so the user can choose different keys to segment different % regions. As the markers are placed, the image is segmented and % the result presented immediately to the user. If DEL or BACK- % SPACE is pressed on a marker, it is deleted. The key ESC is used % to exit. Internally, the watershed is computed on the % morphological gradient of the input image. % % See also MMCWATERSHED, MMFREEDOM, MMSEBOX, MMSECROSS. % begin of the default argument automatic treatment if ~exist('Bc','var') Bc = mmsecross; end % end of the default argument automatic treatment 1 disp('Interactive watershed, press ESC to exit'); mmshow(f); g=mmgradm(f,Bc,Bc); m=mmintersec(f,uint8(0)); z=m; button=1; while 1 [x, y, button]=ginput(1); if button==27; break; end; % ESC: Exit if ((button==127) | (button==8))% DEL,BS: remove marker aux=z; z(y,x)=uint8(255); m=mmintersec(m,mmneg(mmdil(z,mmsedisk(3)))); fprintf('Marker deleted\n'); else % else place marker m(y,x)=button; fprintf('Region %2.0f\n',button); end ws=mmcwatershed(g,mmdil(m),Bc); mmshow(f,ws,mmbinary(mmdil(m))); drawnow; end % Copyright (c) 1998-2001 by SDC Information Systems.