Bonjour,
Je travaille sur un petit programme qui analyse 200 images afin d'extraire la moyenne de chaque pixel.
Pour ce faire je remplis d'abord un
une fois remplie, je fais un premier tri, je mets chaque pixel compris entre 0 et 29 dans une pseudo-liste (en tout 8 pseudo-listes car ça va de 0 à 255)...
Code : Sélectionner tout - Visualiser dans une fenêtre à part vector<vector<vector<int> > > v (200,vector<vector<int> >(480, vector<int>(640)));
Voici une partie de mon code:
Cela fonctionne parfaitement cependant c'est un peu trop lent à mon goût (entre 10 et 12 secondes).
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 int list1=0, n1=0, list2=0, n2=0, list3=0, n3=0, list4=0, n4=0, list5=0, n5=0, list6=0, n6=0, list7=0, n7=0, list8=0, n8=0; for (int x = 0; x < 480; x++) { for (int y = 0; y < 640; y++) { for (int i = 0; i < 200; i++) { if (v[i][x][y] <= 29) { list1 += v[i][x][y]; n1 += 1; } else if (v[i][x][y] >= 30 && v[i][x][y] <= 59) { list2 += v[i][x][y]; n2 += 1; } else if (v[i][x][y] >= 60 && v[i][x][y] <= 89) { list3 += v[i][x][y]; n3 += 1; }else if (v[i][x][y] >= 90 && v[i][x][y] <= 119) { list4 += v[i][x][y]; n4 += 1; } else if (v[i][x][y] >= 120 && v[i][x][y] <= 159) { list5 += v[i][x][y]; n5 += 1; } else if (v[i][x][y] >= 160 && v[i][x][y] <= 189) { list6 += v[i][x][y]; n6 += 1; } else if (v[i][x][y] >= 190 && v[i][x][y] <= 219) { list7 += v[i][x][y]; n7 += 1; } else if (v[i][x][y] >= 220 && v[i][x][y] <= 255) { list8 += v[i][x][y]; n8 += 1; } } int total = n1; int listfinal = list1; if (n2 > total) { total = n2; listfinal = list2; } if (n3 > total) { total = n3; listfinal = list3; } if (n4 > total) { total = n4; listfinal = list4; } if (n5 > total) { total = n5; listfinal = list5; } if (n6 > total) { total = n6; listfinal = list6; } if (n7 > total) { total = n7; listfinal = list7; } if (n8 > total) { total = n8; listfinal = list8; } int final_v = listfinal / total; } }
Pouvez-vous me dire comment puis-je accélérer ce tri ? utiliser une approche différente peut-être ?
Merci d'avance pour vos réponses,
Cordialement,
Nicolas.
Partager