J'ai lu un tuto sur la normalisation. Mais j'ai toujours des soucis je n'arrive pas à normaliser mon image en couleur. En effet je travaille sur une image couleur en C.voici le code que j'ai réadapté
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <opencv/cv.h>
 
#include <opencv/highgui.h>
 
#include <opencv/cxcore.h>
#include<stdio.h>
 
 
 
 
void etirerHistogrammeBGR(IplImage *img){
    /*if(img->nChannels!=1)
        return;*/
    IplImage* B;
    IplImage* G;
    IplImage* R;
    CvScalar scalaire;   
    int p_min = 255;
    int p_max = 0;
    int x,y;
    B = cvCreateImage(cvGetSize(img), img->depth, 1);
    G = cvCreateImage(cvGetSize(img), img->depth, 1);
    R = cvCreateImage(cvGetSize(img), img->depth, 1);
    cvSplit(img,B,G,R,NULL);
 
    //On parint court toute l'image
    for(x=0; x<B->width; x++)
    {
        for(y=0; y<B->height; y++)
        {
 
            //On récupère le pixel de coordonnées (x,y)
            scalaire=cvGet2D(B, y, x);
 
            //Si le niveau de gris est inférieur à p_min, il devient p_min
            if(scalaire.val[0]<p_min)
            {
                p_min=scalaire.val[0];
            }
 
            //Si le niveau de gris est supérieur à p_max, il devient p_max
            if(scalaire.val[0]>p_max)
            {
                p_max=scalaire.val[0];
            }
        }
    }
 
    //p_min est maintenant le nvg minimum et p_max le nvg maximum
 
    //On parcourt l'image une seconde fois
     for(x=0; x<B->width; x++)
    {
        for(y=0; y<B->height; y++)
        {
            //On récupère le pixel (x,y)
            scalaire=cvGet2D(B, y, x);
 
            //Normalisation
            scalaire.val[0] = 255*(scalaire.val[0]-p_min);
            scalaire.val[0] = scalaire.val[0]/(p_max-p_min);
 
            //On remplace le pixel dans l'image
            cvSet2D(B, y, x, scalaire);
        }
    }
 
    //Notre image B est normalisée ;)
   p_min = 255;
    p_max = 0;
     //On parcourt toute l'image
    for(x=0; x<G->width; x++)
    {
        for(y=0; y<G->height; y++)
        {
 
            //On récupère le pixel de coordonnées (x,y)
            scalaire=cvGet2D(G, y, x);
 
            //Si le niveau de gris est inférieur à p_min, il devient p_min
            if(scalaire.val[0]<p_min)
            {
                p_min=scalaire.val[0];
            }
 
            //Si le niveau de gris est supérieur à p_max, il devient p_max
            if(scalaire.val[0]>p_max)
            {
                p_max=scalaire.val[0];
            }
        }
    }
 
    //p_min est maintenant le nvg minimum et p_max le nvg maximum
 
    //On parcourt l'image une seconde fois
     for(x=0; x<G->width; x++)
    {
        for(y=0; y<G->height; y++)
        {
            //On récupère le pixel (x,y)
            scalaire=cvGet2D(G, y, x);
 
            //Normalisation
            scalaire.val[0] = 255*(scalaire.val[0]-p_min);
            scalaire.val[0] = scalaire.val[0]/(p_max-p_min);
 
            //On remplace le pixel dans l'image
            cvSet2D(G, y, x, scalaire);
        }
    }
 
    //Notre image G est normalisée ;)   
     p_min = 255;
     p_max = 0;
     //On parcourt toute l'image
    for(x=0; x<R->width; x++)
    {
        for(y=0; y<R->height; y++)
        {
 
            //On récupère le pixel de coordonnées (x,y)
            scalaire=cvGet2D(R, y, x);
 
            //Si le niveau de gris est inférieur à p_min, il devient p_min
            if(scalaire.val[0]<p_min)
            {
                p_min=scalaire.val[0];
            }
 
            //Si le niveau de gris est supérieur à p_max, il devient p_max
            if(scalaire.val[0]>p_max)
            {
                p_max=scalaire.val[0];
            }
        }
    }
 
    //p_min est maintenant le nvg minimum et p_max le nvg maximum
 
    //On parcourt l'image une seconde fois
     for(x=0; x<R->width; x++)
    {
        for(y=0; y<R->height; y++)
        {
            //On récupère le pixel (x,y)
            scalaire=cvGet2D(R, y, x);
 
            //Normalisation
            scalaire.val[0] = 255*(scalaire.val[0]-p_min);
            scalaire.val[0] = scalaire.val[0]/(p_max-p_min);
 
            //On remplace le pixel dans l'image
            cvSet2D(R, y, x, scalaire);
        }
    }
 
    //Notre image R est normalisée ;) 
    cvMerge(B,G,R,NULL,img);  
    cvReleaseImage(&B);
    cvReleaseImage(&G);
    cvReleaseImage(&R);
 
 
}
int main()
{
    IplImage *img;
    IplImage *imghistogramme;
    img = cvLoadImage("1.jpg",1);
 imghistogramme = cvCloneImage(img);
     etirerHistogrammeBGR(imghistogramme);
 
    //On affiche le résultat dans une fenêtre
    cvNamedWindow("Resultat", CV_WINDOW_AUTOSIZE);
    cvShowImage("Resultat",  imghistogramme);
 
    //On attend que l'utilisateur appuie sur une touche
    cvWaitKey(0);
 
    cvDestroyWindow("Resultat");
    cvReleaseImage(&img);
    cvReleaseImage(&imghistogramme);
  return 0;
}
Merci beaucoup d'avance.