%% Edge Detection introduction materials

I1 = imread('pout.tif');

I = imread('coins.png');




%% Local Rates of Change

clear x y a ych

x=0:0.1:10;

y=sin(x)+.5*x;

figure(1)
plot(x,y)

%Calculate local rates of change

a=diff(y)./diff(x);


figure(2)
plot(x(2:end),a)

figure(3)
plot(x(2:end),abs(a))

% Chooses which rates of change are "large enough"
c=1;
for ind=1:length(a)
    if abs(a(ind)) >= c
        ych(ind)=1;
    else
        ych(ind)=0;
    end
end

figure(4)
plot(x(2:end),ych)

figure(5)
imagesc(y)
axis equal off;
colormap gray

figure(6)
imagesc(a)
axis equal off;
colormap gray

figure(7)
imagesc(ych)
axis equal off;
colormap gray

%% Edge Detection

I = imread('coins.png');

A=edge(I);

A2=edge(I,'canny');

figure(12)
imshow(A)

figure(13)
imshow(A2)


%% Image Histograms

I = imread('coins.png');

figure(21)
imshow(I)

figure(22)
imhist(I)

%% Image thresholding

[m k]=size(I);

I2=zeros(m,k);

c=80;

for ind=1:m
    for jnd=1:k
        
        if I(ind,jnd)>c
            I2(ind,jnd)=1;
        end
    end
end

A=edge(I2);

A2=edge(I2,'canny');

figure(23)
imshow(I2)

figure(24)
imshow(A)

figure(25)
imshow(A2)