Now you can download a copy of these docs so you can use them offline! Download now
ColorImage.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "ColorImage.h"
8 
9 #include "WPIErrors.h"
10 
11 ColorImage::ColorImage(ImageType type) : ImageBase(type)
12 {
13 }
14 
15 ColorImage::~ColorImage()
16 {
17 }
18 
26 BinaryImage *ColorImage::ComputeThreshold(ColorMode colorMode,
27  int low1, int high1,
28  int low2, int high2,
29  int low3, int high3)
30 {
31  BinaryImage *result = new BinaryImage();
32  Range range1 = {low1, high1},
33  range2 = {low2, high2},
34  range3 = {low3, high3};
35 
36  int success = imaqColorThreshold(result->GetImaqImage(), m_imaqImage, 1, colorMode, &range1, &range2, &range3);
37  wpi_setImaqErrorWithContext(success, "ImaqThreshold error");
38  return result;
39 }
40 
51 BinaryImage *ColorImage::ThresholdRGB(int redLow, int redHigh, int greenLow, int greenHigh, int blueLow, int blueHigh)
52 {
53  return ComputeThreshold(IMAQ_RGB, redLow, redHigh, greenLow, greenHigh, blueLow, blueHigh);
54 }
55 
62 {
63  return ComputeThreshold(IMAQ_RGB, t.plane1Low, t.plane1High,
64  t.plane2Low, t.plane2High,
65  t.plane3Low, t.plane3High);
66 }
67 
78 BinaryImage *ColorImage::ThresholdHSL(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int luminenceLow, int luminenceHigh)
79 {
80  return ComputeThreshold(IMAQ_HSL, hueLow, hueHigh, saturationLow, saturationHigh, luminenceLow, luminenceHigh);
81 }
82 
89 {
90  return ComputeThreshold(IMAQ_HSL, t.plane1Low, t.plane1High,
91  t.plane2Low, t.plane2High,
92  t.plane3Low, t.plane3High);
93 }
94 
105 BinaryImage *ColorImage::ThresholdHSV(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int valueLow, int valueHigh)
106 {
107  return ComputeThreshold(IMAQ_HSV, hueLow, hueHigh, saturationLow, saturationHigh, valueLow, valueHigh);
108 }
109 
116 {
117  return ComputeThreshold(IMAQ_HSV, t.plane1Low, t.plane1High,
118  t.plane2Low, t.plane2High,
119  t.plane3Low, t.plane3High);
120 }
121 
132 BinaryImage *ColorImage::ThresholdHSI(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int intensityLow, int intensityHigh)
133 {
134  return ComputeThreshold(IMAQ_HSI, hueLow, hueHigh, saturationLow, saturationHigh, intensityLow, intensityHigh);
135 }
136 
143 {
144  return ComputeThreshold(IMAQ_HSI, t.plane1Low, t.plane1High,
145  t.plane2Low, t.plane2High,
146  t.plane3Low, t.plane3High);
147 }
148 
155 MonoImage *ColorImage::ExtractColorPlane(ColorMode mode, int planeNumber)
156 {
157  MonoImage *result = new MonoImage();
158  if (m_imaqImage == NULL)
159  wpi_setWPIError(NullParameter);
160  int success = imaqExtractColorPlanes(m_imaqImage,
161  mode,
162  (planeNumber == 1) ? result->GetImaqImage() : NULL,
163  (planeNumber == 2) ? result->GetImaqImage() : NULL,
164  (planeNumber == 3) ? result->GetImaqImage() : NULL);
165  wpi_setImaqErrorWithContext(success, "Imaq ExtractColorPlanes failed");
166  return result;
167 }
168 
169 /*
170  * Extract the first color plane for an image.
171  * @param mode The color mode in which to operate
172  * @returns a pointer to a MonoImage that is the extracted plane.
173  */
174 MonoImage *ColorImage::ExtractFirstColorPlane(ColorMode mode)
175 {
176  return ExtractColorPlane(mode, 1);
177 }
178 
179 /*
180  * Extract the second color plane for an image.
181  * @param mode The color mode in which to operate
182  * @returns a pointer to a MonoImage that is the extracted plane.
183  */
184 MonoImage *ColorImage::ExtractSecondColorPlane(ColorMode mode)
185 {
186  return ExtractColorPlane(mode, 2);
187 }
188 
189 /*
190  * Extract the third color plane for an image.
191  * @param mode The color mode in which to operate
192  * @returns a pointer to a MonoImage that is the extracted plane.
193  */
194 MonoImage *ColorImage::ExtractThirdColorPlane(ColorMode mode)
195 {
196  return ExtractColorPlane(mode, 3);
197 }
198 
199 /*
200  * Extract the red plane from an RGB image.
201  * @returns a pointer to a MonoImage that is the extraced plane.
202  */
203 MonoImage *ColorImage::GetRedPlane()
204 {
205  return ExtractFirstColorPlane(IMAQ_RGB);
206 }
207 
208 /*
209  * Extract the green plane from an RGB image.
210  * @returns a pointer to a MonoImage that is the extraced plane.
211  */
212 MonoImage *ColorImage::GetGreenPlane()
213 {
214  return ExtractSecondColorPlane(IMAQ_RGB);
215 }
216 
217 /*
218  * Extract the blue plane from an RGB image.
219  * @returns a pointer to a MonoImage that is the extraced plane.
220  */
221 MonoImage *ColorImage::GetBluePlane()
222 {
223  return ExtractThirdColorPlane(IMAQ_RGB);
224 }
225 
226 /*
227  * Extract the Hue plane from an HSL image.
228  * @returns a pointer to a MonoImage that is the extraced plane.
229  */
230 MonoImage *ColorImage::GetHSLHuePlane()
231 {
232  return ExtractFirstColorPlane(IMAQ_HSL);
233 }
234 
235 /*
236  * Extract the Hue plane from an HSV image.
237  * @returns a pointer to a MonoImage that is the extraced plane.
238  */
239 MonoImage *ColorImage::GetHSVHuePlane()
240 {
241  return ExtractFirstColorPlane(IMAQ_HSV);
242 }
243 
244 /*
245  * Extract the Hue plane from an HSI image.
246  * @returns a pointer to a MonoImage that is the extraced plane.
247  */
248 MonoImage *ColorImage::GetHSIHuePlane()
249 {
250  return ExtractFirstColorPlane(IMAQ_HSI);
251 }
252 
253 /*
254  * Extract the Luminance plane from an HSL image.
255  * @returns a pointer to a MonoImage that is the extraced plane.
256  */
257 MonoImage *ColorImage::GetLuminancePlane()
258 {
259  return ExtractThirdColorPlane(IMAQ_HSL);
260 }
261 
262 /*
263  * Extract the Value plane from an HSV image.
264  * @returns a pointer to a MonoImage that is the extraced plane.
265  */
266 MonoImage *ColorImage::GetValuePlane()
267 {
268  return ExtractThirdColorPlane(IMAQ_HSV);
269 }
270 
271 /*
272  * Extract the Intensity plane from an HSI image.
273  * @returns a pointer to a MonoImage that is the extraced plane.
274  */
275 MonoImage *ColorImage::GetIntensityPlane()
276 {
277  return ExtractThirdColorPlane(IMAQ_HSI);
278 }
279 
287 void ColorImage::ReplacePlane(ColorMode mode, MonoImage *plane, int planeNumber) {
288  int success = imaqReplaceColorPlanes(m_imaqImage,
289  (const Image*) m_imaqImage,
290  mode,
291  (planeNumber == 1) ? plane->GetImaqImage() : NULL,
292  (planeNumber == 2) ? plane->GetImaqImage() : NULL,
293  (planeNumber == 3) ? plane->GetImaqImage() : NULL);
294  wpi_setImaqErrorWithContext(success, "Imaq ReplaceColorPlanes failed");
295 }
296 
302 void ColorImage::ReplaceFirstColorPlane(ColorMode mode, MonoImage *plane)
303 {
304  ReplacePlane(mode, plane, 1);
305 }
306 
312 void ColorImage::ReplaceSecondColorPlane(ColorMode mode, MonoImage *plane)
313 {
314  ReplacePlane(mode, plane, 2);
315 }
316 
322 void ColorImage::ReplaceThirdColorPlane(ColorMode mode, MonoImage *plane)
323 {
324  ReplacePlane(mode, plane, 3);
325 }
326 
333 {
334  ReplaceFirstColorPlane(IMAQ_RGB, plane);
335 }
336 
343 {
344  ReplaceSecondColorPlane(IMAQ_RGB, plane);
345 }
346 
353 {
354  ReplaceThirdColorPlane(IMAQ_RGB, plane);
355 }
356 
357 
364 {
365  return ReplaceFirstColorPlane(IMAQ_HSL, plane);
366 }
367 
374 {
375  return ReplaceFirstColorPlane(IMAQ_HSV, plane);
376 }
377 
384 {
385  return ReplaceFirstColorPlane(IMAQ_HSI, plane);
386 }
387 
394 {
395  return ReplaceSecondColorPlane(IMAQ_HSL, plane);
396 }
397 
404 {
405  return ReplaceSecondColorPlane(IMAQ_HSV, plane);
406 }
407 
414 {
415  return ReplaceSecondColorPlane(IMAQ_HSI, plane);
416 }
417 
424 {
425  return ReplaceThirdColorPlane(IMAQ_HSL, plane);
426 }
427 
434 {
435  return ReplaceThirdColorPlane(IMAQ_HSV, plane);
436 }
437 
444 {
445  return ReplaceThirdColorPlane(IMAQ_HSI, plane);
446 }
447 
448 //TODO: frcColorEqualize(Image* dest, const Image* source, int colorEqualization) needs to be modified
449 //The colorEqualization parameter is discarded and is set to TRUE in the call to imaqColorEqualize.
450 void ColorImage::Equalize(bool allPlanes)
451 {
452  // Note that this call uses NI-defined TRUE and FALSE
453  int success = imaqColorEqualize(m_imaqImage, (const Image*) m_imaqImage, (allPlanes) ? TRUE : FALSE);
454  wpi_setImaqErrorWithContext(success, "Imaq ColorEqualize error");
455 }
456 
457 void ColorImage::ColorEqualize()
458 {
459  Equalize(true);
460 }
461 
462 void ColorImage::LuminanceEqualize()
463 {
464  Equalize(false);
465 }
void ReplaceGreenPlane(MonoImage *plane)
Definition: ColorImage.cpp:342
void ReplaceLuminancePlane(MonoImage *plane)
Definition: ColorImage.cpp:423
void ReplaceHSIHuePlane(MonoImage *plane)
Definition: ColorImage.cpp:383
void ReplaceHSVSaturationPlane(MonoImage *plane)
Definition: ColorImage.cpp:403
BinaryImage * ThresholdHSI(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int intensityLow, int intensityHigh)
Definition: ColorImage.cpp:132
BinaryImage * ThresholdHSV(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int valueHigh, int valueLow)
Definition: ColorImage.cpp:105
void ReplaceHSLHuePlane(MonoImage *plane)
Definition: ColorImage.cpp:363
void ReplaceHSLSaturationPlane(MonoImage *plane)
Definition: ColorImage.cpp:393
void ReplaceBluePlane(MonoImage *plane)
Definition: ColorImage.cpp:352
BinaryImage * ThresholdHSL(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int luminenceLow, int luminenceHigh)
Definition: ColorImage.cpp:78
void ReplaceHSISaturationPlane(MonoImage *plane)
Definition: ColorImage.cpp:413
Image * GetImaqImage()
Definition: ImageBase.cpp:73
void ReplaceValuePlane(MonoImage *plane)
Definition: ColorImage.cpp:433
void ReplaceIntensityPlane(MonoImage *plane)
Definition: ColorImage.cpp:443
void ReplaceHSVHuePlane(MonoImage *plane)
Definition: ColorImage.cpp:373
BinaryImage * ThresholdRGB(int redLow, int redHigh, int greenLow, int greenHigh, int blueLow, int blueHigh)
Definition: ColorImage.cpp:51
void ReplaceRedPlane(MonoImage *plane)
Definition: ColorImage.cpp:332

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6