summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/photo.js33
-rw-r--r--webcam.html2
2 files changed, 33 insertions, 2 deletions
diff --git a/js/photo.js b/js/photo.js
index e1b8079..566a50d 100644
--- a/js/photo.js
+++ b/js/photo.js
@@ -154,13 +154,40 @@ var Photo = (function(){
pixel[1] = data[t+1]
pixel[2] = data[t+2]
pixel[3] = data[t+3]
+ // if (Photo.denoise) { denoise_pixel(data, w, h, x, y, pixel, Photo.denoise) }
row[j] = closest_to(pixel)
}
}
if (! cb) return rows
else cb (rows)
}
-
+ function denoise_pixel (d, w, h, x, y, pixel, exponent){
+ var rr = r, gg = g, bb = b;
+ var color = [0,0,0]
+ var total = 0.0
+ var xx, yy, x0, y0, weight, r, g, b, t
+ for (xx = -4.0; xx <= 4.0; xx += 1.0) {
+ x0 = x+xx
+ if (x0 < 0 || x0 >= w) continue
+ for (yy = -4.0; yy <= 4.0; yy += 1.0) {
+ y0 = y+yy
+ if (y0 < 0 || y0 >= h) continue
+ t = (x+xx + w*(y+yy)) * 4
+ r = d[ t ]
+ g = d[ t+1 ]
+ b = d[ t+2 ]
+ weight = 1.0 - Math.abs( 0.25 * ((rr-r)/255 + (gg-g)/255 + (bb-b)/255) )
+ weight = pow( weight, exponent )
+ color[0] += r * weight
+ color[1] += g * weight
+ color[2] += b * weight
+ total += weight
+ }
+ }
+ pixel[0] = color[0] * 255 / total
+ pixel[1] = color[1] * 255 / total
+ pixel[2] = color[2] * 255 / total
+ }
function getNaturalDimensions (img) {
if (img.naturalWidth) {
return { naturalWidth: img.naturalWidth, naturalHeight: img.naturalHeight }
@@ -255,7 +282,7 @@ var Photo = (function(){
}, width)
}
- return {
+ var Photo = {
colors: COLORS,
hues: HUES,
grays: GRAYS,
@@ -273,7 +300,9 @@ var Photo = (function(){
asciiFromUrl: asciiFromUrl,
ascii: ascii,
neighbor: neighbor,
+ denoise: 0,
}
+ return Photo
})()
diff --git a/webcam.html b/webcam.html
index 49abe81..7f76131 100644
--- a/webcam.html
+++ b/webcam.html
@@ -99,6 +99,8 @@ Photo.set_recolor_fn(function(rgb){
return rgb
})
+// Photo.denoise = 2
+
var hue = 0, sat = 0, lum = 0, quant = 1
listen(hue_el, window, "hue")
listen(sat_el, window, "sat")