% The edge function performs the edge detection.

I = imread('coins.png');

% BW = edge(I)
% takes a grayscale image and returns a binary image where white
% pixels are those where an edge has been detected in the input image.
% Several edge detecting techniques can be used (see "doc edge").
% For instance, 

thresh = .15;
BW = edge(I,'sobel',thresh);
hf(1) = figure; imshow(I);
figure; imshow(BW); title(['sobel (threshold: ' num2str(thresh) ')']);

% different techniques make a different use of the parameters
BW2 = edge(I,'canny',thresh);
figure; imshow(BW2); title(['canny (threshold: ' num2str(thresh) ')']);
thresh = .5;
BW2 = edge(I,'canny',thresh);
figure; imshow(BW2); title(['canny (threshold: ' num2str(thresh) ')']);
% Using 'canny', both high and low threshold can be specified.


% Boundaries
% The bwtraceboundary returns the set of pixels that compose the
% boundary the point seed belongs to.
[rows, cols] = find(BW2);

boundary = bwtraceboundary(BW2, [rows(1) cols(1)], 'N');
hold on;
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
figure(hf(1));
hold on;
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);

