Bonjours à tous
J'ai une fonction "mouvement" qui calcule les amplitudes des vecteurs mouvements après l'appel à une autre fonction "motionEstES" qui fait la mise en correspondance des blocs .J'ai généré 9 images en niveau de gris par un code simple "imgtest" pour tester la fonction "mouvement" et vérifier si le amplitudes résultats sont correctes ou pas(le vecteurs mouvement sont donnés par celui "mvt" dans le code de "imgtest").L'image initiale contient le bloc à suivre (de taille 3x3) donc mbSize était fixée à 3 et la taille du région de la recherche étai fixée à 2.
Mais je trouve les 4 premiers amplitudes qui sont correctes et les autres sont bizarres.Quelqu'un pourrait m'aider à corriger mes codes ou me dire où est ma faute si elle existe et merci d'avance.voici le codes:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function [V,t]=mouvement(m,n,mbSize,p,nc)
dir_im=('C:\COURS BECHIR\PFE\image créés');
path_img=strcat(dir_im,'\','*.bmp');
files_img=dir(path_img);
nbr_im=numel(files_img);
V=[];
x=0;
y=0;
for i=1:(nbr_im-1)
    im1=double(imread(strcat(dir_im,'\',files_img(i).name)));
    im2=double(imread(strcat(dir_im,'\',files_img(i+1).name)));
    b=block_num(m+y,n+x,mbSize,nc);
    [motionVect]=motionEstES(im2,im1,mbSize,p);
    y=motionVect(1,b);
    x=motionVect(2,b);
    A=(x^2+y^2)^0.5 ;
    V=[V A];
end
t=1:19 ;
end
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function imgtest(m,n,o,p)
mvt=[1 2 -1 1 1 1 1 1 -2 2 -2 1 0 0 0 1 -1 1 0;
    1 -2 2 1 -1 2 -1 2 -2 1 0 1 0 0 0 1 2 -2 1];
im=zeros(30);
im(m:n,o:p)=255;
figure;imshow(im);
impixelinfo;
adresse= ['C:\COURS BECHIR\PFE\image créés\test' num2str(1) '.bmp'];
imwrite(im,adresse);
for j=1:size(mvt,2)
    x=mvt(1,j);
    y=mvt(2,j);
    im=zeros(30);
    im(m+x:n+x,o+y:p+y)=255;
    m=m+x;
    n=n+x;
    o=o+y;
    p=p+y;
    figure;imshow(im);
    impixelinfo
    chemin= ['C:\COURS BECHIR\PFE\image créés\test' num2str(j+1) '.bmp'];
    imwrite(im,chemin);
end
end
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [motionVect, EScomputations] = motionEstES(imgP, imgI, mbSize, p)
 
[row col] = size(imgI);
 
vectors = zeros(2,row*col/mbSize^2);
costs = ones(2*p + 1, 2*p +1) * 65537;
 
computations = 0;
 
% we start off from the top left of the image
% we will walk in steps of mbSize
% for every marcoblock that we look at we will look for
% a close match p pixels on the left, right, top and bottom of it
 
mbCount = 1;
for i = 1 : mbSize : row-mbSize+1
    for j = 1 : mbSize : col-mbSize+1
 
        % the exhaustive search starts here
        % we will evaluate cost for  (2p + 1) blocks vertically
        % and (2p + 1) blocks horizontaly
        % m is row(vertical) index
        % n is col(horizontal) index
        % this means we are scanning in raster order
 
        for m = -p : p        
            for n = -p : p
                refBlkVer = i + m;   % row/Vert co-ordinate for ref block
                refBlkHor = j + n;   % col/Horizontal co-ordinate
                if ( refBlkVer < 1 || refBlkVer+mbSize-1 > row ...
                        || refBlkHor < 1 || refBlkHor+mbSize-1 > col)
                    continue;
                end
                costs(m+p+1,n+p+1) = costFuncMAD(imgP(i:i+mbSize-1,j:j+mbSize-1), ...
                     imgI(refBlkVer:refBlkVer+mbSize-1, refBlkHor:refBlkHor+mbSize-1), mbSize);
                computations = computations + 1;
 
            end
        end
 
        % Now we find the vector where the cost is minimum
        % and store it ... this is what will be passed back.
 
        [dx, dy, min] = minCost(costs); % finds which macroblock in imgI gave us min Cost
        vectors(1,mbCount) = dy-p-1;    % row co-ordinate for the vector
        vectors(2,mbCount) = dx-p-1;    % col co-ordinate for the vector
        mbCount = mbCount + 1;
        costs = ones(2*p + 1, 2*p +1) * 65537;
    end
end
 
motionVect = vectors;
EScomputations = computations/(mbCount - 1);