ofImage normalizeROI(vector<vector<pos>> i, ofImage inROI){ //Output image ofImage outROI=inROI; //Loop through each position pair for(int j = 0; j < i.size(); j++){ //Get the two positions pos upperleft = i[j][0], lowerright = i[j][1]; //Get width and height of the current ROI int ROIwidth = lowerright.getX() - upperleft.getX(); int ROIheight = lowerright.getY() - upperleft.getY(); //Loop through each pixel in the ROI and convert pixels to chromatic rg for(int p = 0;p < ROIheight;p++){ for(int q = 0; q < ROIwidth;q++){ pos tempPos(upperleft.getX()+q,upperleft.getY()+p,0); outROI.setColor(tempPos.getX(), tempPos.getY(), RGB2rgb(tempPos, inROI)); } } } //Return output return outROI; }
bool IsColorConflict(DWORD dwClr1, DWORD dwClr2) // return whether dwClr1 and dwClr2 are closely together { // NEW COLOR CONFLICT METHOD: u'v'-distance int R1 = 0xff & (dwClr1 >> 16); int G1 = 0xff & (dwClr1 >> 8); int B1 = 0xff & (dwClr1 ); int R2 = 0xff & (dwClr2 >> 16); int G2 = 0xff & (dwClr2 >> 8); int B2 = 0xff & (dwClr2 ); double r1=0,g1=0,b1=0,r2=0,g2=0,b2=0,x1=0,y1=0,Y1=0,x2=0,y2=0,Y2=0,u1=0,v1=0,u2=0,v2=0; RGB2rgb(R1, G1, B1, &r1, &g1, &b1); RGB2rgb(R2, G2, B2, &r2, &g2, &b2); rgb2xyY(r1, g1, b1, &x1, &y1, &Y1); rgb2xyY(r2, g2, b2, &x2, &y2, &Y2); xy2upvp(x1, y1, &u1, &v1); xy2upvp(x2, y2, &u2, &v2); double Y = (Y1+Y2)/2.0; double clrdiff = sqrt((u2-u1)*(u2-u1) + (v2-v1)*(v2-v1)) * Y*Y * 150; double lumdiff = (Abs<double>(Y2-Y1) / std::max<double>(Y*Y*5, 0.5)) / 0.10; return clrdiff + lumdiff < 1.0; }
SEXP do_gray(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP lev, ans; double level; int i, ilevel, nlev; checkArity(op, args); PROTECT(lev = coerceVector(CAR(args),REALSXP)); nlev = LENGTH(lev); PROTECT(ans = allocVector(STRSXP, nlev)); for (i = 0; i < nlev; i++) { level = REAL(lev)[i]; if (ISNAN(level) || level < 0 || level > 1) errorcall(call, _("invalid gray level, must be in [0,1].")); ilevel = 255 * level + 0.5; SET_STRING_ELT(ans, i, mkChar(RGB2rgb(ilevel, ilevel, ilevel))); } UNPROTECT(2); return ans; }