function dilated_image = dilate2( source_image, neighborhood ); % DILATE2 dilate a greyscale image. % dilated_image = dilate2( source_image, neighborhood ); % dilates the image to make white objects larger, black cracks smaller. % (The MatLab function "dilate.m" % does the same thing, but only accepts binary black-and-white image). % Assumes source_image is a array 0 = black, max(source_image)=white pixels; % Assumes neighborhood is a array of % 1 = neighbor pixels, 0 = non-neighbor pixels. % See also ERODE2, OPEN2, CLOSE2, DILATE. % Change log: % 1998-03-26:DAV: updated to grayscale version. % 1998-02-04:DAV: David Cary wrote binary version elements = nnz(neighborhood); % rotate structuring element halfway around % to make it consistent with MatLab's "dilate" command. % (this helps "open2" and "close2" do the Right Thing % when the neighborhood is not symmetrical around "the" center pixel, % and when the neighborhood has even size -- for example, circle(10).). dilated_image = ordfilt2(source_image, elements, rot90(neighborhood,2)); % end dilate2.m