
X = double(imread('moon.png'));

% Laplacian
l = [0 1 0; 1 -4 1; 0 1 0];
% Laplacian with diagonals
l2 = [1 1 1; 1 -8 1; 1 1 1];

Y = filter2(l, X);
% rescaled in [0, 255]
Y2 = (Y-min(Y(:)))/(max(Y(:))-min(Y(:)))*255;

X2 = X-.4*Y;

fprintf('X2 (image + Laplacian) range: [%f, %f]\n', [min(X2(:)) max(X2(:))]);

X = uint8(X);
X2 = uint8(X2);
Y = uint8(Y);
Y2 = uint8(Y2);

figure; imshow(X); title('Original image');
figure; imshow(Y); title('Laplacian');
figure; imshow(Y2); title('Rescaled Laplacian'); 
figure; imshow(X2); title('Image+Laplacian');

Z = filter2(l2, X);
% rescaled in [0, 255]
Z2 = (Z-min(Z(:)))/(max(Z(:))-min(Z(:)))*255;

X = double(X);
X3 = X-.3*Z;
fprintf('X3 (image + diagonal Laplacian): [%f, %f]\n', [min(X3(:)) max(X3(:))]);

X = uint8(X);
X3 = uint8(X3);
fprintf('Z (diagonal Laplacian) range: [%d, %d]\n', [min(Z(:)) max(Z(:))]);
Z = uint8(Z);
Z2 = uint8(Z2);

figure; imshow(Z); title('Laplacian (with diagonals)');
figure; imshow(Z2); title('Rescaled Laplacian (with diagonals)');
figure; imshow(X3); title('Image+Laplacian (with diagonals)');

