Skip to content

Commit e487958

Browse files
committed
Tried Human Skin Colour Clustering for Face Detection, a bit faster but binary
1 parent 7171e9d commit e487958

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

smartcrop.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ SmartCrop.DEFAULTS = {
3636
cropWidth: 0,
3737
cropHeight: 0,
3838
detailWeight: 0.2,
39-
skinColor: [0.78, 0.57, 0.44],
4039
skinBias: 0.01,
41-
skinBrightnessMin: 0.2,
42-
skinBrightnessMax: 1.0,
43-
skinThreshold: 0.8,
44-
skinWeight: 1.8,
40+
skinWeight: 1.0,
4541
saturationBrightnessMin: 0.05,
4642
saturationBrightnessMax: 0.9,
4743
saturationThreshold: 0.4,
@@ -166,10 +162,15 @@ SmartCrop.prototype = {
166162
for(var y = 0; y < h; y++) {
167163
for(var x = 0; x < w; x++) {
168164
var p = (y*w+x)*4,
169-
lightness = cie(id[p], id[p+1], id[p+2])/255,
170-
skin = this.skinColor(id[p], id[p+1], id[p+2]);
171-
if(skin > options.skinThreshold && lightness >= options.skinBrightnessMin && lightness <= options.skinBrightnessMax){
172-
od[p] = (skin-options.skinThreshold)*(255/(1-options.skinThreshold));
165+
r = id[p],
166+
g = id[p+1],
167+
b = id[p+2],
168+
abs_rg = Math.abs(r-g);
169+
// Human Skin Colour Clustering for Face Detection
170+
// Jure Kovac, Peter Peer, and Franc Solina
171+
// http://eprints.fri.uni-lj.si/2113/1/Human_Skin_Colour_Clustering_for_Face_Detection.pdf
172+
if((r > 95 && g > 40 && b > 20 && Math.max(r,g,b)-Math.min(r,g,b) > 15 && abs_rg > 15 && r > g && r > b) || (r > 220 && g > 210 && b > 170 && abs_rg <= 15 && r > b && g > b)){
173+
od[p] = 255;
173174
}
174175
else {
175176
od[p] = 0;
@@ -265,15 +266,6 @@ SmartCrop.prototype = {
265266
}
266267
return s+d;
267268
},
268-
skinColor: function(r, g, b){
269-
var mag = sqrt(r*r+g*g+b*b),
270-
options = this.options,
271-
rd = (r/mag-options.skinColor[0]),
272-
gd = (g/mag-options.skinColor[1]),
273-
bd = (b/mag-options.skinColor[2]),
274-
d = sqrt(rd*rd+gd*gd+bd*bd);
275-
return 1-d;
276-
},
277269
analyse: function(image){
278270
var result = {},
279271
options = this.options,

0 commit comments

Comments
 (0)