40 lines
1.3 KiB
Matlab
40 lines
1.3 KiB
Matlab
function [directions] = etalonnage(spheres, exterieur_masque, centre, rayon)
|
|
|
|
taille_noyau = round(rayon/20);
|
|
triangle = @(n)(1+n-abs(-n:n))/n;
|
|
|
|
[height, width, N_photo, N_sphere] = size(spheres);
|
|
|
|
directions = zeros(3, N_photo);
|
|
for p=1:N_photo
|
|
for s=1:N_sphere
|
|
% recup info sphere
|
|
image_sphere = spheres(:,:,p,s);
|
|
|
|
% filtrage
|
|
image_filtree = conv2(triangle(taille_noyau), triangle(taille_noyau), image_sphere, 'same');
|
|
image_filtree = image_filtree .* ( 1 - exterieur_masque);
|
|
|
|
% recup point brillant
|
|
[~, I] = max(image_filtree, [], 'all');
|
|
|
|
% recup des coords
|
|
xc = centre(2);
|
|
yc = centre(1);
|
|
[x, y] = ind2sub([height, width], I);
|
|
|
|
% calcul de la normale
|
|
normal = [ x-xc, y-yc, 0 ];
|
|
normal(3) = sqrt(rayon^2 - normal(1)^2 - normal(2)^2);
|
|
normal = normal / norm(normal');
|
|
|
|
% calcul de la direction
|
|
axe_optique = [0, 0, 1];
|
|
direction = 2 * (axe_optique * normal') * normal - axe_optique;
|
|
|
|
directions(:, p) = directions(:, p) + direction';
|
|
end
|
|
directions(:, p) = directions(:, p) / N_sphere;
|
|
directions(:, p) = directions(:, p) / norm(directions(:, p));
|
|
end
|
|
end |