
X = imread('luna.png');

dx =[-1 1];
dy =[-1; 1];

X = double(X);
DX = imfilter(X, dx);
% riscala tra 0 e 255
DX2 = (DX-min(DX(:)))/(max(DX(:))-min(DX(:)))*255;

DY = imfilter(X, dy);
% riscala tra 0 e 255
DY2 = (DY-min(DY(:)))/(max(DY(:))-min(DY(:)))*255;

DXY = sqrt(DX.^2+DY.^2);

fprintf('intervallo DX (derivata x): [%d, %d]\n', [min(DX(:)) max(DX(:))]);
fprintf('intervallo DY (derivata y): [%d, %d]\n', [min(DY(:)) max(DY(:))]);
fprintf('intervallo DXY (gradiente): [%f, %f]\n', [min(DXY(:)) max(DXY(:))]);

DXY = uint8(DXY);
DXY2 = histeq(DXY);

X = uint8(X);
DX = uint8(DX);
DX2 = uint8(DX2);
DY = uint8(DY);
DY2 = uint8(DY2);
DXY = uint8(DXY);

figure; imshow(X); title('Immagine originale');
figure; imshow(DX); title('Derivata x');
figure; imshow(DX2); title('Derivata x scalata');
figure; imshow(DY); title('Derivata y');
figure; imshow(DY2); title('Derivata y scalata');
figure; imshow(DXY); title('Gradiente');
figure; imshow(DXY2); title('Gradiente equalizzato');

