67 lines
2.3 KiB
Matlab
Executable file
67 lines
2.3 KiB
Matlab
Executable file
function [moyennes,variances] = estimation_RVB(I,N,couleur_classes,fig)
|
|
% fig3 = figure(3);
|
|
% densR = ksdensity(reshape(255*I(:,:,1),1,[]),0:255);
|
|
% densG = ksdensity(reshape(255*I(:,:,2),1,[]),0:255);
|
|
% densB = ksdensity(reshape(255*I(:,:,3),1,[]),0:255);
|
|
%
|
|
% plot(0:255,densR,'r');
|
|
% hold on;
|
|
% plot(0:255,densG,'g');
|
|
% plot(0:255,densB,'b');
|
|
% plot(0:255,densR+densG+densB,'k');
|
|
|
|
|
|
fprintf('Selectionnez %d echantillons\n',N);
|
|
[nb_lignes,nb_colonnes,nbchannel] = size(I);
|
|
|
|
moyennes = zeros(N,nbchannel);
|
|
variances = zeros(N,nbchannel,nbchannel);
|
|
coords = [ 62.8251 22.2301 57.1851 16.3336;
|
|
138.1969 95.5509 131.2750 101.9601;
|
|
80.0017 123.2385 88.7182 131.1859 ];
|
|
for k = 1:N
|
|
figure(fig);
|
|
x1 = coords(k,1);
|
|
y1 = coords(k,2);
|
|
x2 = coords(k,3);
|
|
y2 = coords(k,4);
|
|
% [x1,y1] = ginput(1);
|
|
% while (x1<1)||(x1>nb_colonnes)||(y1<1)||(y1>nb_lignes)
|
|
% [x1,y1] = ginput(1);
|
|
% end
|
|
% [x2,y2] = ginput(1);
|
|
% while (x2<1)||(x2>nb_colonnes)||(y2<1)||(y2>nb_lignes)||(x2==x1)||(y2==y1)
|
|
% [x2,y2] = ginput(1);
|
|
% end
|
|
% x1y1x2y2 = [x1 y1 x2 y2]
|
|
line([x1,x1],[y1,y2],'Color',couleur_classes(k,:),'Linewidth',2);
|
|
line([x1,x2],[y2,y2],'Color',couleur_classes(k,:),'Linewidth',2);
|
|
line([x2,x2],[y2,y1],'Color',couleur_classes(k,:),'Linewidth',2);
|
|
line([x2,x1],[y1,y1],'Color',couleur_classes(k,:),'Linewidth',2);
|
|
drawnow;
|
|
|
|
echantillons = [];
|
|
for i = floor(min([y1,y2])):ceil(max([y1,y2]))
|
|
for j = floor(min([x1,x2])):ceil(max([x1,x2]))
|
|
tmp(:) = I(i,j,:);
|
|
echantillons = [ echantillons ; tmp ];
|
|
end
|
|
end
|
|
|
|
% figure(k+10);
|
|
% densR = ksdensity(reshape(255*echantillons(:,1),1,[]),0:255);
|
|
% densG = ksdensity(reshape(255*echantillons(:,2),1,[]),0:255);
|
|
% densB = ksdensity(reshape(255*echantillons(:,3),1,[]),0:255);
|
|
%
|
|
% plot(0:255,densR,'r');
|
|
% hold on;
|
|
% plot(0:255,densG,'g');
|
|
% plot(0:255,densB,'b');
|
|
% plot(0:255,densR+densG+densB,'k');
|
|
|
|
moyenne = mean(echantillons);
|
|
moyennes(k,:) = moyenne;
|
|
covariances = cov(echantillons);
|
|
variances(k,:,:) = covariances;
|
|
|
|
end |