% Simula la transformación de una imagen en un dibujo hecho a lápiz
% empleando diferentes filtros de convolución

% Pon la image que más te guste y compara los resultados. 

imag = imread('image.jpg');
imag = rgb2gray(imag);

figure(1) 
imshow( imag )
title('Imagen original', 'FontSize', 20)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h2 = [0 1 0;1 -4 1;0 1 0]; % 4 vecinos
imagf = imfilter( imag, h2, 'conv');
imagf = 255-imagf;
figure(2)
imshow( imagf )
title('Detección de bordes con 4 vecinos', 'FontSize', 20)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h2 = [1 1 1;1 -8 1;1 1 1]; % 8 vecinos
imagf = imfilter( imag, h2, 'conv');
imagf = 255-imagf;
figure(3)
imshow( imagf )
title('Detección de bordes con 8 vecinos', 'FontSize', 20)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h2 =   [0 0 1 1 0 0; 
	0 0 1 1 0 0;
	1 1 -4 -4 1 1;
	1 1 -4 -4 1 1;
	0 0 1 1 0 0;
	0 0 1 1 0 0]; % 4 bloques vecinos 
imagf = imfilter( imag, h2, 'conv');
imagf = 255-imagf;
figure(4)
imshow( imagf )
title('4 vecinos bloques 2 x 2', 'FontSize', 20)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h2 =   [1 1 1 1 1 1; 
	1 1 1 1 1 1;
	1 1 -8 -8 1 1;
	1 1 -8 -8 1 1;
	1 1 1 1 1 1;
	1 1 1 1 1 1]; % 8 bloques vecinos 
imagf = imfilter( imag, h2, 'conv');
imagf = 255-imagf;
figure(5)
imshow( imagf )
title('8 vecinos bloques 2 x 2', 'FontSize', 20)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h2 =   [1 1 1 1 1 1; 
	1 1 1 1 1 1;
	1 1 -8 -8 1 1;
	1 1 -8 -8 1 1;
	1 1 1 1 1 1;
	1 1 1 1 1 1]/2; %  8 bloques vecinos con factor 1/2 y clamp [0,200] 
imagf = imfilter( imag, h2, 'conv');
imagf = 255-imagf;
figure(6)
imshow( imagf, [0,200])
title('8 bloques vecinos con factor 2 y clamping [0,200]', 'FontSize', 20)
