void Rgb_to_sv_New(Mat &samples, Mat &perPixelS, Mat &perPixelC)
{
int a = 0, b = 0, c = 0;
int cmax = 0, cmin = 0;
float saturation = 0.0,cvalue=0.0;
assert(perPixelC.total() == perPixelS.total());
assert(perPixelC.channels() == perPixelS.channels());
for (int i = 0;i < samples.rows;i++)
{
uchar* srcP = samples.ptr<uchar>(i);
float* dstS = perPixelS.ptr<float>(i);
float* dstC = perPixelC.ptr<float>(i);
for (int j = 0,k=0;j < samples.cols*CHANNELS,k< perPixelS.cols*perPixelS.channels();k++,j=j+3)
{
cmax = max(srcP[j], max(srcP[j + 1], srcP[j + 2]));
cmin = min(srcP[j], min(srcP[j + 1], srcP[j + 2]));
saturation = cmax == 0 ? 0.0 : (float)(cmax - cmin) / (float)cmax;
cvalue = (float)cmax / 255.0;
dstS[k] = saturation;
dstC[k] = cvalue;
}
}
}
代码为本人原创,转载请注明出处。