MinMax.cpp
1 |
/*********************************************************************************** |
2 |
ImAnalyse : software in image processing and image analysis |
3 |
|
4 |
Copyright (C) 10 juillet 2008 <Vincent MORARD> |
5 |
Version: 2.1 |
6 |
Contact: vincent<POINT>morard<AROBAS>cpe<POINT>fr |
7 |
Website: http://ImAnalyse.free.fr |
8 |
Website: http://pistol.petesampras.free.fr |
9 |
|
10 |
This program is free software: you can redistribute it and/or modify |
11 |
it under the terms of the GNU General Public License as published by |
12 |
the Free Software Foundation, either version 3 of the License, or |
13 |
(at your option) any later version. |
14 |
|
15 |
This program is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
GNU General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU General Public License |
21 |
along with this program. If not, see <http://www.gnu.org/licenses/ |
22 |
**********************************************************************************/ |
23 |
#include "../CImage.h" |
24 |
|
25 |
|
26 |
|
27 |
bool CImage::Minimum(int Type,CImage *Other,CImage *ImgDest) |
28 |
{ |
29 |
if(hBmp==0 || Other->hBmp==0){ |
30 |
MessageBox(NULL,"Minimum : L'image source est vide", |
31 |
NULL,MB_OK|MB_ICONWARNING); |
32 |
return 0; |
33 |
} |
34 |
|
35 |
if(Width!=Other->Width || Height!=Other->Height) |
36 |
if(MessageBox(NULL,"Minimum : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
37 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
38 |
return 0; |
39 |
|
40 |
|
41 |
|
42 |
if(ImgDest==0) |
43 |
ImgDest=this; |
44 |
|
45 |
int i,j; |
46 |
int cx,cy,posImg1,posImg2,Pos; |
47 |
cx=min(Width,Other->Width); |
48 |
cy=min(Height,Other->Height); |
49 |
|
50 |
double *Min=new double[cx*cy]; |
51 |
double *Min_Red,*Min_Green; |
52 |
|
53 |
if(Type==RGBi) |
54 |
{ |
55 |
Min_Red=new double[cx*cy]; |
56 |
Min_Green=new double[cx*cy]; |
57 |
} |
58 |
|
59 |
//recupération des pixels |
60 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
61 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
62 |
|
63 |
|
64 |
|
65 |
for(j=0;j<cy;j++) |
66 |
for(i=0;i<cx*4;i+=4) |
67 |
{ |
68 |
posImg1=i+Width*j*4; |
69 |
posImg2=i+Other->Width*j*4; |
70 |
Pos=((i/4)+j*cx); |
71 |
|
72 |
switch(Type) |
73 |
{ |
74 |
case RGBi: |
75 |
Min_Red[Pos]=min(ucBits[posImg1+2],Other->ucBits[posImg2+2]); |
76 |
Min_Green[Pos]=min(ucBits[posImg1+1],Other->ucBits[posImg2+1]); |
77 |
Min[Pos]=min(ucBits[posImg1],Other->ucBits[posImg2]); |
78 |
break; |
79 |
|
80 |
case RED: |
81 |
Min[Pos]=min(ucBits[posImg1+2],Other->ucBits[posImg2+2]); |
82 |
break; |
83 |
case GREEN: |
84 |
Min[Pos]=min(ucBits[posImg1+1],Other->ucBits[posImg2+1]); |
85 |
break; |
86 |
case BLUE: |
87 |
Min[Pos]=min(ucBits[posImg1],Other->ucBits[posImg2]); |
88 |
break; |
89 |
} |
90 |
} |
91 |
|
92 |
|
93 |
ImgDest->Alloc(cx,cy,Planes,BitsPixel); |
94 |
|
95 |
switch(Type) |
96 |
{ |
97 |
case RGBi: |
98 |
ImgDest->ImgType=RGBi; |
99 |
|
100 |
for(i=0,j=0;i<cx*cy*4;i+=4) |
101 |
{ |
102 |
ImgDest->ucBits[i]=(UCHAR)Min[j]; |
103 |
ImgDest->ucBits[i+1]=(UCHAR)Min_Green[j]; |
104 |
ImgDest->ucBits[i+2]=(UCHAR)Min_Red[j++]; |
105 |
} |
106 |
delete []Min_Red; |
107 |
delete []Min_Green; |
108 |
|
109 |
break; |
110 |
|
111 |
default: |
112 |
ImgDest->ImgType=GRAY; |
113 |
for(i=0,j=0;i<Width*Height*4;i+=4,j++) |
114 |
{ |
115 |
ImgDest->ucBits[i]=(UCHAR)Min[j]; |
116 |
ImgDest->ucBits[i+1]=(UCHAR)Min[j]; |
117 |
ImgDest->ucBits[i+2]=(UCHAR)Min[j]; |
118 |
} |
119 |
break; |
120 |
|
121 |
|
122 |
} |
123 |
|
124 |
delete []Min; |
125 |
|
126 |
|
127 |
SetBitmapBits (ImgDest->hBmp,(cx*cy)*4,ImgDest->ucBits); |
128 |
|
129 |
return 1; |
130 |
} |
131 |
|
132 |
|
133 |
bool CImage::Maximum(int Type,CImage *Other,CImage *ImgDest) |
134 |
{ |
135 |
if(hBmp==0 || Other->hBmp==0){ |
136 |
MessageBox(NULL,"Maximum: L'image source est vide", |
137 |
NULL,MB_OK|MB_ICONWARNING); |
138 |
return 0; |
139 |
} |
140 |
|
141 |
if(Width!=Other->Width || Height!=Other->Height) |
142 |
if(MessageBox(NULL,"Maximum : Les images n'ont pas les mêmes dimensions\nVoulez vous continuer?" |
143 |
,"Attention",MB_YESNO|MB_ICONWARNING)==IDNO) |
144 |
return 0; |
145 |
|
146 |
|
147 |
|
148 |
if(ImgDest==0) |
149 |
ImgDest=this; |
150 |
|
151 |
int i,j; |
152 |
int cx,cy,posImg1,posImg2,Pos; |
153 |
cx=min(Width,Other->Width); |
154 |
cy=min(Height,Other->Height); |
155 |
|
156 |
double *Max=new double[cx*cy]; |
157 |
double *Max_Red,*Max_Green; |
158 |
|
159 |
if(Type==RGBi) |
160 |
{ |
161 |
Max_Red=new double[cx*cy]; |
162 |
Max_Green=new double[cx*cy]; |
163 |
} |
164 |
|
165 |
//recupération des pixels |
166 |
GetBitmapBits(hBmp,Width*Height*4,ucBits); |
167 |
GetBitmapBits(Other->hBmp,Other->Width*Other->Height*4,Other->ucBits); |
168 |
|
169 |
|
170 |
|
171 |
for(j=0;j<cy;j++) |
172 |
for(i=0;i<cx*4;i+=4) |
173 |
{ |
174 |
posImg1=i+Width*j*4; |
175 |
posImg2=i+Other->Width*j*4; |
176 |
Pos=((i/4)+j*cx); |
177 |
|
178 |
switch(Type) |
179 |
{ |
180 |
case RGBi: |
181 |
Max_Red[Pos]=max(ucBits[posImg1+2],Other->ucBits[posImg2+2]); |
182 |
Max_Green[Pos]=max(ucBits[posImg1+1],Other->ucBits[posImg2+1]); |
183 |
Max[Pos]=max(ucBits[posImg1],Other->ucBits[posImg2]); |
184 |
break; |
185 |
|
186 |
case RED: |
187 |
Max[Pos]=max(ucBits[posImg1+2],Other->ucBits[posImg2+2]); |
188 |
break; |
189 |
case GREEN: |
190 |
Max[Pos]=max(ucBits[posImg1+1],Other->ucBits[posImg2+1]); |
191 |
break; |
192 |
case BLUE: |
193 |
Max[Pos]=max(ucBits[posImg1],Other->ucBits[posImg2]); |
194 |
break; |
195 |
} |
196 |
} |
197 |
|
198 |
|
199 |
ImgDest->Alloc(cx,cy,Planes,BitsPixel); |
200 |
|
201 |
switch(Type) |
202 |
{ |
203 |
case RGBi: |
204 |
ImgDest->ImgType=RGBi; |
205 |
|
206 |
for(i=0,j=0;i<cx*cy*4;i+=4) |
207 |
{ |
208 |
ImgDest->ucBits[i]=(UCHAR)Max[j]; |
209 |
ImgDest->ucBits[i+1]=(UCHAR)Max_Green[j]; |
210 |
ImgDest->ucBits[i+2]=(UCHAR)Max_Red[j++]; |
211 |
} |
212 |
delete []Max_Red; |
213 |
delete []Max_Green; |
214 |
|
215 |
break; |
216 |
|
217 |
default: |
218 |
ImgDest->ImgType=GRAY; |
219 |
for(i=0,j=0;i<Width*Height*4;i+=4,j++) |
220 |
{ |
221 |
ImgDest->ucBits[i]=(UCHAR)Max[j]; |
222 |
ImgDest->ucBits[i+1]=(UCHAR)Max[j]; |
223 |
ImgDest->ucBits[i+2]=(UCHAR)Max[j]; |
224 |
} |
225 |
break; |
226 |
|
227 |
|
228 |
} |
229 |
|
230 |
delete []Max; |
231 |
|
232 |
|
233 |
SetBitmapBits (ImgDest->hBmp,(cx*cy)*4,ImgDest->ucBits); |
234 |
|
235 |
return 1; |
236 |
} |
lien1 lien2 lien3