Now you can download a copy of these docs so you can use them offline! Download now
ColorImage.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "ColorImage.h" 00008 00009 #include "WPIErrors.h" 00010 00011 ColorImage::ColorImage(ImageType type) : ImageBase(type) 00012 { 00013 } 00014 00015 ColorImage::~ColorImage() 00016 { 00017 } 00018 00026 BinaryImage *ColorImage::ComputeThreshold(ColorMode colorMode, 00027 int low1, int high1, 00028 int low2, int high2, 00029 int low3, int high3) 00030 { 00031 BinaryImage *result = new BinaryImage(); 00032 Range range1 = {low1, high1}, 00033 range2 = {low2, high2}, 00034 range3 = {low3, high3}; 00035 00036 int success = imaqColorThreshold(result->GetImaqImage(), m_imaqImage, 1, colorMode, &range1, &range2, &range3); 00037 wpi_setImaqErrorWithContext(success, "ImaqThreshold error"); 00038 return result; 00039 } 00040 00051 BinaryImage *ColorImage::ThresholdRGB(int redLow, int redHigh, int greenLow, int greenHigh, int blueLow, int blueHigh) 00052 { 00053 return ComputeThreshold(IMAQ_RGB, redLow, redHigh, greenLow, greenHigh, blueLow, blueHigh); 00054 } 00055 00061 BinaryImage *ColorImage::ThresholdRGB(Threshold &t) 00062 { 00063 return ComputeThreshold(IMAQ_RGB, t.plane1Low, t.plane1High, 00064 t.plane2Low, t.plane2High, 00065 t.plane3Low, t.plane3High); 00066 } 00067 00078 BinaryImage *ColorImage::ThresholdHSL(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int luminenceLow, int luminenceHigh) 00079 { 00080 return ComputeThreshold(IMAQ_HSL, hueLow, hueHigh, saturationLow, saturationHigh, luminenceLow, luminenceHigh); 00081 } 00082 00088 BinaryImage *ColorImage::ThresholdHSL(Threshold &t) 00089 { 00090 return ComputeThreshold(IMAQ_HSL, t.plane1Low, t.plane1High, 00091 t.plane2Low, t.plane2High, 00092 t.plane3Low, t.plane3High); 00093 } 00094 00105 BinaryImage *ColorImage::ThresholdHSV(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int valueLow, int valueHigh) 00106 { 00107 return ComputeThreshold(IMAQ_HSV, hueLow, hueHigh, saturationLow, saturationHigh, valueLow, valueHigh); 00108 } 00109 00115 BinaryImage *ColorImage::ThresholdHSV(Threshold &t) 00116 { 00117 return ComputeThreshold(IMAQ_HSV, t.plane1Low, t.plane1High, 00118 t.plane2Low, t.plane2High, 00119 t.plane3Low, t.plane3High); 00120 } 00121 00132 BinaryImage *ColorImage::ThresholdHSI(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int intensityLow, int intensityHigh) 00133 { 00134 return ComputeThreshold(IMAQ_HSI, hueLow, hueHigh, saturationLow, saturationHigh, intensityLow, intensityHigh); 00135 } 00136 00142 BinaryImage *ColorImage::ThresholdHSI(Threshold &t) 00143 { 00144 return ComputeThreshold(IMAQ_HSI, t.plane1Low, t.plane1High, 00145 t.plane2Low, t.plane2High, 00146 t.plane3Low, t.plane3High); 00147 } 00148 00155 MonoImage *ColorImage::ExtractColorPlane(ColorMode mode, int planeNumber) 00156 { 00157 MonoImage *result = new MonoImage(); 00158 if (m_imaqImage == NULL) 00159 wpi_setWPIError(NullParameter); 00160 int success = imaqExtractColorPlanes(m_imaqImage, 00161 mode, 00162 (planeNumber == 1) ? result->GetImaqImage() : NULL, 00163 (planeNumber == 2) ? result->GetImaqImage() : NULL, 00164 (planeNumber == 3) ? result->GetImaqImage() : NULL); 00165 wpi_setImaqErrorWithContext(success, "Imaq ExtractColorPlanes failed"); 00166 return result; 00167 } 00168 00169 /* 00170 * Extract the first color plane for an image. 00171 * @param mode The color mode in which to operate 00172 * @returns a pointer to a MonoImage that is the extracted plane. 00173 */ 00174 MonoImage *ColorImage::ExtractFirstColorPlane(ColorMode mode) 00175 { 00176 return ExtractColorPlane(mode, 1); 00177 } 00178 00179 /* 00180 * Extract the second color plane for an image. 00181 * @param mode The color mode in which to operate 00182 * @returns a pointer to a MonoImage that is the extracted plane. 00183 */ 00184 MonoImage *ColorImage::ExtractSecondColorPlane(ColorMode mode) 00185 { 00186 return ExtractColorPlane(mode, 2); 00187 } 00188 00189 /* 00190 * Extract the third color plane for an image. 00191 * @param mode The color mode in which to operate 00192 * @returns a pointer to a MonoImage that is the extracted plane. 00193 */ 00194 MonoImage *ColorImage::ExtractThirdColorPlane(ColorMode mode) 00195 { 00196 return ExtractColorPlane(mode, 3); 00197 } 00198 00199 /* 00200 * Extract the red plane from an RGB image. 00201 * @returns a pointer to a MonoImage that is the extraced plane. 00202 */ 00203 MonoImage *ColorImage::GetRedPlane() 00204 { 00205 return ExtractFirstColorPlane(IMAQ_RGB); 00206 } 00207 00208 /* 00209 * Extract the green plane from an RGB image. 00210 * @returns a pointer to a MonoImage that is the extraced plane. 00211 */ 00212 MonoImage *ColorImage::GetGreenPlane() 00213 { 00214 return ExtractSecondColorPlane(IMAQ_RGB); 00215 } 00216 00217 /* 00218 * Extract the blue plane from an RGB image. 00219 * @returns a pointer to a MonoImage that is the extraced plane. 00220 */ 00221 MonoImage *ColorImage::GetBluePlane() 00222 { 00223 return ExtractThirdColorPlane(IMAQ_RGB); 00224 } 00225 00226 /* 00227 * Extract the Hue plane from an HSL image. 00228 * @returns a pointer to a MonoImage that is the extraced plane. 00229 */ 00230 MonoImage *ColorImage::GetHSLHuePlane() 00231 { 00232 return ExtractFirstColorPlane(IMAQ_HSL); 00233 } 00234 00235 /* 00236 * Extract the Hue plane from an HSV image. 00237 * @returns a pointer to a MonoImage that is the extraced plane. 00238 */ 00239 MonoImage *ColorImage::GetHSVHuePlane() 00240 { 00241 return ExtractFirstColorPlane(IMAQ_HSV); 00242 } 00243 00244 /* 00245 * Extract the Hue plane from an HSI image. 00246 * @returns a pointer to a MonoImage that is the extraced plane. 00247 */ 00248 MonoImage *ColorImage::GetHSIHuePlane() 00249 { 00250 return ExtractFirstColorPlane(IMAQ_HSI); 00251 } 00252 00253 /* 00254 * Extract the Luminance plane from an HSL image. 00255 * @returns a pointer to a MonoImage that is the extraced plane. 00256 */ 00257 MonoImage *ColorImage::GetLuminancePlane() 00258 { 00259 return ExtractThirdColorPlane(IMAQ_HSL); 00260 } 00261 00262 /* 00263 * Extract the Value plane from an HSV image. 00264 * @returns a pointer to a MonoImage that is the extraced plane. 00265 */ 00266 MonoImage *ColorImage::GetValuePlane() 00267 { 00268 return ExtractThirdColorPlane(IMAQ_HSV); 00269 } 00270 00271 /* 00272 * Extract the Intensity plane from an HSI image. 00273 * @returns a pointer to a MonoImage that is the extraced plane. 00274 */ 00275 MonoImage *ColorImage::GetIntensityPlane() 00276 { 00277 return ExtractThirdColorPlane(IMAQ_HSI); 00278 } 00279 00287 void ColorImage::ReplacePlane(ColorMode mode, MonoImage *plane, int planeNumber) { 00288 int success = imaqReplaceColorPlanes(m_imaqImage, 00289 (const Image*) m_imaqImage, 00290 mode, 00291 (planeNumber == 1) ? plane->GetImaqImage() : NULL, 00292 (planeNumber == 2) ? plane->GetImaqImage() : NULL, 00293 (planeNumber == 3) ? plane->GetImaqImage() : NULL); 00294 wpi_setImaqErrorWithContext(success, "Imaq ReplaceColorPlanes failed"); 00295 } 00296 00302 void ColorImage::ReplaceFirstColorPlane(ColorMode mode, MonoImage *plane) 00303 { 00304 ReplacePlane(mode, plane, 1); 00305 } 00306 00312 void ColorImage::ReplaceSecondColorPlane(ColorMode mode, MonoImage *plane) 00313 { 00314 ReplacePlane(mode, plane, 2); 00315 } 00316 00322 void ColorImage::ReplaceThirdColorPlane(ColorMode mode, MonoImage *plane) 00323 { 00324 ReplacePlane(mode, plane, 3); 00325 } 00326 00332 void ColorImage::ReplaceRedPlane(MonoImage *plane) 00333 { 00334 ReplaceFirstColorPlane(IMAQ_RGB, plane); 00335 } 00336 00342 void ColorImage::ReplaceGreenPlane(MonoImage *plane) 00343 { 00344 ReplaceSecondColorPlane(IMAQ_RGB, plane); 00345 } 00346 00352 void ColorImage::ReplaceBluePlane(MonoImage *plane) 00353 { 00354 ReplaceThirdColorPlane(IMAQ_RGB, plane); 00355 } 00356 00357 00363 void ColorImage::ReplaceHSLHuePlane(MonoImage *plane) 00364 { 00365 return ReplaceFirstColorPlane(IMAQ_HSL, plane); 00366 } 00367 00373 void ColorImage::ReplaceHSVHuePlane(MonoImage *plane) 00374 { 00375 return ReplaceFirstColorPlane(IMAQ_HSV, plane); 00376 } 00377 00383 void ColorImage::ReplaceHSIHuePlane(MonoImage *plane) 00384 { 00385 return ReplaceFirstColorPlane(IMAQ_HSI, plane); 00386 } 00387 00393 void ColorImage::ReplaceHSLSaturationPlane(MonoImage *plane) 00394 { 00395 return ReplaceSecondColorPlane(IMAQ_HSL, plane); 00396 } 00397 00403 void ColorImage::ReplaceHSVSaturationPlane(MonoImage *plane) 00404 { 00405 return ReplaceSecondColorPlane(IMAQ_HSV, plane); 00406 } 00407 00413 void ColorImage::ReplaceHSISaturationPlane(MonoImage *plane) 00414 { 00415 return ReplaceSecondColorPlane(IMAQ_HSI, plane); 00416 } 00417 00423 void ColorImage::ReplaceLuminancePlane(MonoImage *plane) 00424 { 00425 return ReplaceThirdColorPlane(IMAQ_HSL, plane); 00426 } 00427 00433 void ColorImage::ReplaceValuePlane(MonoImage *plane) 00434 { 00435 return ReplaceThirdColorPlane(IMAQ_HSV, plane); 00436 } 00437 00443 void ColorImage::ReplaceIntensityPlane(MonoImage *plane) 00444 { 00445 return ReplaceThirdColorPlane(IMAQ_HSI, plane); 00446 } 00447 00448 //TODO: frcColorEqualize(Image* dest, const Image* source, int colorEqualization) needs to be modified 00449 //The colorEqualization parameter is discarded and is set to TRUE in the call to imaqColorEqualize. 00450 void ColorImage::Equalize(bool allPlanes) 00451 { 00452 // Note that this call uses NI-defined TRUE and FALSE 00453 int success = imaqColorEqualize(m_imaqImage, (const Image*) m_imaqImage, (allPlanes) ? TRUE : FALSE); 00454 wpi_setImaqErrorWithContext(success, "Imaq ColorEqualize error"); 00455 } 00456 00457 void ColorImage::ColorEqualize() 00458 { 00459 Equalize(true); 00460 } 00461 00462 void ColorImage::LuminanceEqualize() 00463 { 00464 Equalize(false); 00465 }
Generated on Thu Jan 12 2012 22:35:18 for WPILibC++ by
1.7.1