MCPcopy
hub / github.com/ericdrowell/KineticJS / backgroundMask

Function backgroundMask

kinetic.js:4730–4752  ·  view source on GitHub ↗
(idata, threshold)

Source from the content-addressed store, hash-verified

4728 }
4729
4730 function backgroundMask(idata, threshold) {
4731 var rgbv_no = pixelAt(idata, 0, 0);
4732 var rgbv_ne = pixelAt(idata, idata.width - 1, 0);
4733 var rgbv_so = pixelAt(idata, 0, idata.height - 1);
4734 var rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
4735
4736
4737 var thres = threshold || 10;
4738 if (rgbDistance(rgbv_no, rgbv_ne) < thres && rgbDistance(rgbv_ne, rgbv_se) < thres && rgbDistance(rgbv_se, rgbv_so) < thres && rgbDistance(rgbv_so, rgbv_no) < thres) {
4739
4740 // Mean color
4741 var mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
4742
4743 // Mask based on color distance
4744 var mask = [];
4745 for (var i = 0; i < idata.width * idata.height; i++) {
4746 var d = rgbDistance(mean, [idata.data[i * 4], idata.data[i * 4 + 1], idata.data[i * 4 + 2]]);
4747 mask[i] = (d < thres) ? 0 : 255;
4748 }
4749
4750 return mask;
4751 }
4752 }
4753
4754 function applyMask(idata, mask) {
4755 for (var i = 0; i < idata.width * idata.height; i++) {

Callers 1

kinetic.jsFile · 0.70

Calls 3

pixelAtFunction · 0.70
rgbDistanceFunction · 0.70
rgbMeanFunction · 0.70

Tested by

no test coverage detected