double Hsl::calcLum(double red, double green, double blue) { double r,g,b; double min, max; double lum; r = red/255; g = green/255; b = blue/255; min = minRGB(r,g,b); max = maxRGB(r,g,b); lum = (max+min)/2; return lum; }
//converts rgb values to Hsl values vector<double> Hsl::rgb2hsl(double red, double green, double blue) { double r,g,b; double min, max; double delta; vector<double> HSL(3,0); r = red/255; g = green/255; b = blue/255; min = minRGB(r,g,b); max = maxRGB(r,g,b); L = (max+min)/2; delta = max-min; if(delta==0) { H=0; S=0; } else { if(L>0.5) { S = (max-min)/(2.0-max-min); } else { S = (max-min)/(max+min); } if(max==r) { H = ((g-b)/delta); } else if(max==g) { H = ((b-r)/delta) + 2; } else { H = ((r-g)/delta) + 4; } H *= 60; if(H<0) H+=360; } HSL[0] = round(H); HSL[1] = S; HSL[2] = L; return HSL; }
void ImageProcessor::grayscaleMax(cv::Mat &img) { unsigned char *data = (unsigned char*) (img.data); int r,g,b,gray; for(int y=0; y<img.rows; y++) { for(int x=0; x<img.cols; x++) { b = data[y*img.step + x*img.channels()]; g = data[y*img.step + x*img.channels() + 1]; r = data[y*img.step + x*img.channels() + 2]; gray = maxRGB(r, g ,b); data[y*img.step + x*img.channels()] = gray; data[y*img.step + x*img.channels() + 1] = gray; data[y*img.step + x*img.channels() + 2] = gray; } } }