Bonjour à tous!
Je cherche à optimiser une fonction. J'ai une image dans le domaine de couleur HSV (src_HSV) et je cherche à lui appliquer 2 valeurs de seuils (une normale, et une large).
En résultera une image avec 3 niveaux de gris (dst_gray), selon la valeur de chaque pixel.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 H_Threshold = 8; S_Threshold = 166; V_Threshold = 127; H_Threshold_large = 15; S_Threshold_large = 121; V_Threshold_large = 67;
Pourriez-vous me conseiller pour ce qui est de l'optimisation de cette fonction, où puis-je gagner du temps de calcul (cette image a 3 canaux (H, S et V) et a pour dimensions 640*270)?
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 int CImageProcessing::HSV_Thresholding(IplImage* src_HSV, IplImage* dst_gray) { int x,y; char* MyImageData = m_pImage_gray->imageData ; int MyStep = m_pImage_gray->widthStep ; char* MyHSVImageData = src_HSV->imageData ; int MyHSVStep = src_HSV->widthStep ; for (y=269;y>=0;--y) for (x=width-1;x>=0;--x) { Hue = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3]; Saturation = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3+1]; Value = ((uchar*)(MyHSVImageData + MyHSVStep*y))[x*3+2]; if ( ((Hue>H_Threshold_large) && (Hue<180-H_Threshold_large)) || (Saturation<S_Threshold_large) || (Value<V_Threshold_large) ) { ((uchar*)(MyImageData + MyStep*y))[x] = 0 ; } else if ( ((Hue>H_Threshold) && (Hue<180-H_Threshold)) || (Saturation<S_Threshold) || (Value<V_Threshold) ) { ((uchar*)(MyImageData + MyStep*y))[x] = 125 ; } else { ((uchar*)(MyImageData + MyStep*y))[x] = 255 ; } } return 0; }
Je vous remercie d'avance pour votre aide!





Répondre avec citation











Partager