Other.cpp

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   
23  #include "CImage.h" 
24  #include <queue> 
25  using namespace std; 
26   
27   
28  bool **AllocT_bool(int Width,int Height,int Init=-99) 
29  { 
30    bool **Tab; 
31    Tab=new bool*[Width]; 
32    for(int i=0;i<Width;i++) 
33      Tab[i]=new bool[Height]; 
34   
35    if(Init!=99) 
36      for(int i=0;i<Width;i++) 
37        for(int j=0;j<Height;j++) 
38          if(Init==1) 
39             Tab[i][j]=TRUE; 
40          else 
41            Tab[i][j]=FALSE; 
42    return Tab; 
43  } 
44  void DesAllocT_bool(bool **Tab,int Width) 
45  { 
46    for(int i=0;i<Width;i++) 
47      delete []Tab[i]; 
48    delete []Tab; 
49  } 
50   
51  bool CImage::FindMinimum(CImage *ImgDest) 
52  { 
53    if(hBmp==0){ 
54      MessageBox(NULL,"FindMinimum: L'image source est vide", 
55        NULL,MB_OK|MB_ICONWARNING); 
56      return 0; 
57    } 
58   
59    if(ImgDest==this){ 
60      MessageBox(NULL,"FindMinimum: L'image destination ne doit pas etre l'image source", 
61        NULL,MB_OK|MB_ICONWARNING); 
62      return 0; 
63    } 
64    ImgDest->CopyProp(this); 
65    ImgDest->Fill(0,0,0); 
66   
67    POINT Pt; 
68    int i,j,Pij,X,Y,k,l; 
69    bool **Buffer,Skip; 
70   
71    queue <POINT>Fifo,FifoSave; 
72    //queue <POINT>FifoSave; 
73   
74   
75    //Cette image permet de visualiser les pixels déjà visités.  
76    Buffer=AllocT_bool(Width,Height,FALSE); 
77   
78    //Pour tous les pixels de l'image 
79    for(i=0;i<Width;i++) 
80      for(j=0;j<Height;j++) 
81        if(Buffer[i][j]==FALSE) 
82        { 
83          Buffer[i][j]=TRUE; 
84          Pt.x=i;Pt.y=j; 
85          Fifo.push(Pt); 
86          FifoSave.push(Pt); 
87   
88          Skip=FALSE; 
89   
90          Pij=(int) GetPixel(i,j,RED); 
91   
92          do 
93          { 
94            Pt=Fifo.front(); 
95            Fifo.pop(); 
96            X=Pt.x;Y=Pt.y; 
97   
98            for(k=-1;k<=1;k++) 
99              for(l=-1;l<=1;l++) 
100                if(X+k>=0 && Y+l>=0 && X+k<Width && Y+l<Height) 
101                  if(!(k==0 && l==0)) 
102                    if(Buffer[X+k][Y+l]==FALSE && GetPixel(X+k,Y+l,RED) == Pij) 
103                    { 
104                      Buffer[X+k][Y+l]=TRUE; 
105                      Pt.x=X+k;Pt.y=Y+l; 
106                      Fifo.push(Pt); 
107                      FifoSave.push(Pt); 
108   
109                    } 
110                    else if(GetPixel(X+k,Y+l,RED) < Pij)   //On regarde si on trouve un pixel plus faible 
111                      Skip=TRUE;          //Si c'est le cas, cette région n'est pas un minimum 
112   
113          } 
114          while(!Fifo.empty()); 
115   
116          while(!FifoSave.empty()) 
117          { 
118            Pt=FifoSave.front(); 
119            FifoSave.pop(); 
120   
121            if(!Skip) 
122              ImgDest->SetPixel(Pt.x,Pt.y,255,255,255);//Si c'est un minimum, on le marque 
123   
124          } 
125        } 
126   
127    SetBitmapBits (ImgDest->hBmp,(Width*Height)*4,ImgDest->ucBits); 
128    ImgDest->ImgType=BIN; 
129    DesAllocT_bool(Buffer,Width); 
130   
131    return true; 
132  } 
133   
134   
135  bool CImage::Superposition(CImage *ImgFond) 
136  { 
137    if(hBmp==0){ 
138      MessageBox(NULL,"Superposition: L'image source est vide", 
139        NULL,MB_OK|MB_ICONWARNING); 
140      return 0; 
141    } 
142   
143    if(ImgFond==0){ 
144      MessageBox(NULL,"Superposition: L'image du fond est vide", 
145        NULL,MB_OK|MB_ICONWARNING); 
146      return 0; 
147    } 
148    if(ImgFond->Width != Width || ImgFond->Height!=Height){ 
149      MessageBox(NULL,"Superposition: Les deux images doivent avoir les mêmes dimensions", 
150        NULL,MB_OK|MB_ICONWARNING); 
151      return 0; 
152    } 
153    for(int i=0;i<4*Width*Height;i+=4) 
154    { 
155      if(ucBits[i]==0 && ucBits[i+1]==0 && ucBits[i+2]==0) 
156      { 
157        ucBits[i]=ImgFond->ucBits[i]; 
158        ucBits[i+1]=ImgFond->ucBits[i+1]; 
159        ucBits[i+2]=ImgFond->ucBits[i+2]; 
160      } 
161    } 
162    SetBitmapBits (hBmp,(Width*Height)*4,ucBits); 
163   
164    return 1; 
165  } 

lien1 lien2 lien3