%this program produces two edge images for a given imput gray level image
%Longin Jan Latecki, latecki@temple.edu, Oct. 9, 2002

%im8 = imread('trees.tif'); %this image is included in Matlab
im8 = imread('blood1.tif');

im=double(im8); %for further processing you need to convert the image into double

% figure; imshow(im8); %displays image

figure; colormap(gray(256)); image(im); title('input image') %displays image withouth Image Proc. TB
figure; mesh(im); title('input image mesh')


% image smoothing example
S=1/9*[1 1 1; 1 1 1; 1 1 1] %filter mask for smoothing

smooth1=filter2(S,im); %convolution of the image with the filter mask S

figure; image(smooth1); colormap(gray(256)); title('smoothed image obtained by averaging')
figure; mesh(smooth1); title('mesh of the smoothed image obtained by averaging')

im=smooth1;

% first edge detection example with Laplacian
B=[-1 -1 -1; -1 8 -1; -1 -1 -1] %filter mask to produce edges

e1=filter2(B,im); %convolution of the image with the filter mask B

figure; image(e1); colormap(gray); title('edge image obtained by Laplacian')
figure; mesh(e1); title('edge image mesh obtained by Laplacian')


% second edge detection example with Sobel
h=fspecial('sobel') %we use a predefined Matlab filter mask named after Sobel

e2=filter2(h,im);

figure; image(e2); colormap(gray); title('edge image obtained by Sobel')
figure; mesh(e2); title('edge image mesh obtained by Sobel')


