     ctx = canvas.getContext '2d'
     imageData = ctx.getImageData 0, 0, canvas.width, canvas.height
     data = imageData.data
-    c.params.mean = 0.5 unless c.params.mean
+    c.params.mean = 2 unless c.params.mean
     c.params.max = 10 unless c.params.max
     c.params.avg = 10 unless c.params.avg
     threshold = c.params


    # Iterate through the upper lines
    prev = gray.slice 0, canvas.width
    for i in [0...gray.length] by canvas.width
      line = gray.slice i, i + canvas.width
      if isBorder line, prev, threshold
        bbox.y += 1
        prev = line
      else
        break

    # Iterate through the bottom lines
    prev = gray.slice gray.length - canvas.width, gray.length
    for i in [gray.length...0] by -canvas.width
      line = gray.slice i - canvas.width, i
      if isBorder line, prev, threshold
        bbox.height -= 1
        prev = line
      else
        break

    # Iterate through the left columns
    for line in [0...canvas.width]
      column = []
      for col in [line...gray.length] by canvas.width
        column.push gray[col]
      if line == 0
        prev = column
      if isBorder column, prev, threshold
        bbox.x += 1
        prev = column
      else
        break

    # Iterate through the right columns
    for line in [0...canvas.width]
      column = []
      for col in [gray.length - 1 - line..0] by -canvas.width
        column.push gray[col]
      if line == canvas.width
        prev = column
      if isBorder column, prev, threshold
        bbox.width -= 1
        prev = column
      else
        break

    bbox.height -= bbox.y
    bbox.width -= bbox.x
    out.send bbox
    do callback
  c

  sum = array.reduce (s,i) -> s += i
  sum / array.length

isHomogeneous = (array, threshold) ->
  diff = diffBetweenNeighbourPixels array
  if diff.mean <= threshold.mean and
  diff.max <= threshold.max
    true
  else
    false

isBorder = (array, prev, threshold) ->
  avg = Math.abs average(array) - average(prev)
  if avg > threshold.avg
    true
  else
    false
