diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-07-16 19:36:40 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-07-16 19:36:40 -0400 |
| commit | 4ca3230391b7e01bec07365117511141810f149b (patch) | |
| tree | 24e88576118f82f949f32e7235775f67d80298d3 /js/photo.js | |
| parent | b29a89f620a74ac675da1568494a5111fed63a2d (diff) | |
stub in denoising function. webcam isnt working
Diffstat (limited to 'js/photo.js')
| -rw-r--r-- | js/photo.js | 33 |
1 files changed, 31 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 })() |
