Bonjour, j'essaie d’implémenter l'algorithme de localconsistency.

Voici une courte description



That is, modeling local surfaces as frontal-parallel, the
posterior probability P R
fg(D(f)) of a specific disparity
hypothesis D(f) implicitly made by the blue point f on
the red point g is related to the spatial proximity between
(f, g), (f', g') and to the color proximity between (f, g),
(f', g'), (f, f'). Color and spatial proximity are encoded
according to the Euclidean distance (see [15] for details).

Donc voici une version simplifie de mon algorithme

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
for (int disp = 0; disp < maxdisp; ++disp)
    {
        for (unsigned int i = 0; i < left->width; ++i)
        {
            for (unsigned int j = 0; j < left->height; ++j)
            {
                CvPoint center = cvPoint(i + (winsize - 1) / 2, j + (winsize - 1) / 2);
                for (unsigned int x = 0; x < winsize; ++x)
                {
                    for (unsigned int y = 0; y < winsize; ++y)
                    {
                                //center diff color
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3)
                                        - CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3));
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 1)
                                        - CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 1));
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 2)
                                        - CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 2));
 
                                //left center to point color
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3)
                                        - CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3));
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 1)
                                        - CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3 + 1));
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 2)
                                        - CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3 + 2));
 
                                // right center to point color
                                if (i + x + disp < left->width)
                                {
                                    CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3)
                                            - CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3));
                                    CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 1)
                                            - CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3 + 1));
                                    CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 2)
                                            - CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3 + 2));
                                }
// distance
                                CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += sqrtf((center.x - (i + x)) * (center.x - (i + x)) + (center.y - (j + y)) * (center.y - (j + y)));
                    }
                }
            }
Donc je calcule bien les difference de couleur et la distance comme indique dans l'algorithme.
Au final j'obtiens une image assez sale compare a ce que je devrais obtenir.

Je sais que j'ai peu de chance d'avoir une réponse car il faut qu'une personne ai étudié cette algorithme pour pouvoir répondre, mais on ne sait jamais.

Merci.