我用了那个椭圆聚类,转成YCb’Cr’,为了取得更好的效果,取它和rgb肤色空间点的交。 整个处理在读入中进行,二值图结果用Seg导出。 double Y = r * 0.256789 + g * 0.504129 + b * 0.097906+ 16; double Cb = r *-0.148223 + g * -0.290992 + b * 0.439215+ 128; double Cr = r * 0.439215 + g * -0.367789 + b *-0.071426+ 128; double cb1, cr1, wcb, wcr, x1, y1; if (Y < 125) { cb1 = 108 + (125 - Y) * 10 / 109; cr1 = 154 - (125 - Y) * 10 / 109; wcb = 23 + (Y - 16) * 23.97 / 109; wcr = 20 + (Y - 16) * 18.76 / 109; cb1 = (Cb - cb1) * 46.97 / wcb + cb1; cr1 = (Cr - cr1) * 38.76 / wcr + cr1; } else if (Y > 188) { cb1 = 108 + (Y - 188) * 10 / 47; cr1 = 154 + (Y - 188) * 22 / 47; wcb = 14 + (235 - Y) * 32.97 / 47; wcr = 10 + (235 - Y) * 28.76 / 47; cb1 = (Cb - cb1) * 46.97 / wcb + cb1; cr1 = (Cr - cr1) * 38.76 / wcr + cr1; } else { cb1 = Cb; cr1 = Cr; } x1 = -0.819 * (cb1 - 109.38) + 0.574 * (cr1 - 152.02); y1 = -0.574 * (cb1 - 109.38) - 0.819 * (cr1 - 152.02); if ((((x1 - 1.6) * (x1 - 1.6) / 644.6521 + (y1 - 2.41) * (y1 - 2.41) / 196.8409) < 1 && //椭圆拟合 (r > 95 && g > 80 && b > 80 && (r - g) > 15))) //rgb分布 { Seg[i, j] = 1; } else Seg[i, j] = 0;