ScriptLPE

1  /***********************************************************************************  
2      ImAnalyse : software in image processing and image analysis 
3     
4      Copyright (C) 27 avril 2008  <Vincent MORARD> 
5    Version: 2.0 
6      Contact: vincent<POINT>morard<AROBAS>cpe<POINT>fr 
7    Website: http://pistol.petesampras.free.fr 
8   
9      This program is free software: you can redistribute it and/or modify 
10      it under the terms of the GNU General Public License as published by 
11      the Free Software Foundation, either version 3 of the License, or 
12      (at your option) any later version. 
13   
14      This program is distributed in the hope that it will be useful, 
15      but WITHOUT ANY WARRANTY; without even the implied warranty of 
16      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
17      GNU General Public License for more details. 
18   
19      You should have received a copy of the GNU General Public License 
20      along with this program.  If not, see <http://www.gnu.org/licenses/ 
21  **********************************************************************************/ 
22  #include "../CImage.h" 
23   
24  void Message(HWND hList,HWND hDlg,char *Mes,int Buf) 
25  { 
26    SendMessage(hList,LB_ADDSTRING, 0, (LPARAM)Mes); 
27    SendMessage(hDlg,WM_UPDATE,Buf,0); 
28    Sleep(500); 
29  } 
30  //************************************************************************************ 
31  //Thread cells, Ce thread permet de lister toute une série de traitement plus ou moins 
32  //long. A partir de l'image de cellules, ce processus permet d'effectuer une segmentation 
33  //afin d'isoler chaque cellule. La difficulté pour segmenter correctement cette image 
34  //c'est de séparer les cellules qui se touchent. Pour cela, on utilise l'algorithme de  
35  //la ligne de partage des eaux appliqué sur l'image des distances. 
36  //Cette image des distances permet de créer l'image topologique nécessaire à la LPE et 
37  //de localiser le centre des cellules. 
38  //************************************************************************************ 
39  DWORD WINAPI cells(LPVOID lpParam ) 
40  { 
41    HWND hDlg,hOK,hwndList; 
42   
43    hDlg=(HWND) lpParam; 
44    hwndList=GetDlgItem(hDlg, IDC_LIST1); 
45    hOK=GetDlgItem(hDlg, IDOK); 
46   
47    bool Noyau[9]; 
48    for(int i=0;i<9;i++) Noyau[i]=1; 
49   
50    int t = GetTickCount();  //initialisation du temps 
51   
52    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Début du traitement"); 
53   
54    char szExe[_MAX_PATH],*Q=szExe; 
55    GetModuleFileName(NULL,szExe,_MAX_PATH); 
56    while(*Q!=0)Q++; 
57    while(*Q!='\\')Q--;*Q=0; 
58    strcat(szExe,"\\cell.jpg"); 
59    if(Img[0].LoadJPG_GIF(szExe)==0)return 0; 
60   
61    Message(hwndList,hDlg,"Ouverture de l'image : Fait",0); 
62   
63   
64    if(Img[0].ContrasteAuto(GRAY,&Img[1])==0)return 0; 
65    Message(hwndList,hDlg,"Contraste automatique : Fait",1); 
66   
67   
68    if(Img[1].Threashold(Img[1].thrFuzzy(),&Img[2])==0)return 0; 
69    Message(hwndList,hDlg,"Seuillage automatique : Fait",2); 
70   
71   
72    if(Img[2].NOT(&Img[3])==0)return 0; 
73    Message(hwndList,hDlg,"Inversion : Fait",3); 
74   
75   
76    if(Img[3].morCloseHole(3,&Img[4])==0)return 0; 
77    Message(hwndList,hDlg,"Bouchage des trous : Fait",4); 
78   
79   
80    if(Img[4].NOT(&Img[3])==0)return 0; 
81    if(Img[3].LaplaceI(GRAY,&Img[4])==0)return 0; 
82    if(Img[4].Threashold(10,&Img[4])==0)return 0; 
83    Message(hwndList,hDlg,"Détection des contours :Fait",4); 
84   
85   
86    if(Img[4].DistanceMorphologique(3,TRUE,&Img[5])==0)return 0; 
87    Message(hwndList,hDlg,"Distance morphologique : Fait",5); 
88   
89   
90    if(Img[5].ContrasteAuto(GRAY,&Img[5])==0)return 0; 
91    if(Img[5].Inversion(&Img[6])==0)return 0; 
92    Message(hwndList,hDlg,"Contraste auto + inversion : Fait",6); 
93   
94   
95    if(Img[6].ErosionNG(Noyau,9,0,&Img[7])==0)return 0; 
96    Message(hwndList,hDlg,"Erosion en niveau de gris: Fait",7); 
97   
98   
99    if(Img[7].FindMinimum(&Img[8])==0)return 0; 
100    Message(hwndList,hDlg,"Détermination des marqueur : Fait",8); 
101   
102   
103    if(Img[6].LPE(9,10,4)==0)return 0; 
104    Message(hwndList,hDlg,"LPE : Fait",9); 
105   
106   
107    if(Img[9].lpeFrontiere(&Img[4],&Img[10])==0)return 0; 
108    if(Img[10].Superposition(&Img[1])==0)return 0; 
109    Message(hwndList,hDlg,"Superposition : Fait",10); 
110   
111   
112    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Fin du traitement, temps (ms) "); 
113    t = GetTickCount() - t; 
114    char Buf[20]; 
115    strcpy(Buf,itoa(t,Buf,10)); 
116    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)Buf); 
117   
118    EnableWindow(hOK,TRUE); 
119    return 1; 
120   
121  } 
122   
123  DWORD WINAPI demo(LPVOID lpParam ) 
124  { 
125    HWND hDlg,hOK,hwndList; 
126   
127    hDlg=(HWND) lpParam; 
128    hwndList=GetDlgItem(hDlg, IDC_LIST1); 
129    hOK=GetDlgItem(hDlg, IDOK); 
130   
131    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Début du traitement"); 
132   
133    bool Noyau[9]; 
134    for(int i=0;i<9;i++) Noyau[i]=1; 
135   
136    int t = GetTickCount();  //initialisation du temps 
137    //Ouverture de l'image dans le buffer 0 
138    char szExe[_MAX_PATH],*Q=szExe; 
139    GetModuleFileName(NULL,szExe,_MAX_PATH); 
140    while(*Q!=0)Q++; 
141    while(*Q!='\\')Q--;*Q=0; 
142    strcat(szExe,"\\demo.jpg"); 
143    if(Img[0].LoadJPG_GIF(szExe)==0)return 0; 
144   
145    Message(hwndList,hDlg,"Ouverture de l'image : Fait",0); 
146   
147    //Seuillage suivant la méthode de Fuzzy de l'image 0 ver le buffer 1 
148    if(Img[0].Threashold(Img[0].thrFuzzy(),&Img[1])==0)return 0; 
149    Message(hwndList,hDlg,"Seuillage automatique : Fait",1); 
150   
151    //Détection des contours de l'image 1 vers le buffer 2 
152    if(Img[1].LaplaceI(GRAY,&Img[2])==0)return 0; 
153    //Seuillage à 10 de 'image 2 vers le buffer 2 
154    if(Img[2].Threashold(10,&Img[2])==0)return 0; 
155    Message(hwndList,hDlg,"Détection des contours :Fait",2); 
156   
157   
158    if(Img[2].DistanceMorphologique(3,TRUE,&Img[3])==0)return 0; 
159    Message(hwndList,hDlg,"Distance morphologique : Fait",3); 
160   
161    if(Img[3].ContrasteAuto(GRAY,&Img[3])==0)return 0; 
162    if(Img[3].Inversion(&Img[4])==0)return 0; 
163    Message(hwndList,hDlg,"Contraste auto + inversion : Fait",4); 
164   
165    if(Img[4].ErosionNG(Noyau,9,0,&Img[5])==0)return 0; 
166    Message(hwndList,hDlg,"Erosion en niveau de gris: Fait",5); 
167   
168    if(Img[5].FindMinimum(&Img[6])==0)return 0; 
169    Message(hwndList,hDlg,"Determination des minima locaux : Fait",6); 
170   
171    if(Img[4].LPE(7,8,4)==0)return 0; 
172    if(Img[7].ContrasteAuto(GRAY)==0)return 0; 
173    Message(hwndList,hDlg,"LPE : Fait",7); 
174   
175    if(Img[7].lpeFrontiere(&Img[4],&Img[8])==0)return 0; 
176    if(Img[8].Superposition(&Img[0])==0)return 0; 
177    Message(hwndList,hDlg,"Superposition : Fait",8); 
178   
179    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Fin du traitement, temps (ms) = "); 
180   
181    t = GetTickCount() - t; 
182    char Buf[20]; 
183    strcpy(Buf,itoa(t,Buf,10)); 
184    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)Buf); 
185   
186   
187    EnableWindow(hOK,TRUE); 
188   
189    return 0; 
190   
191  } 

lien1 lien2 lien3