code: function(img, convert_grayscale) {
  
      if(typeof(convert_grayscale)==='undefined') var convert_grayscale = false;
  
      var canvas = document.createElement('canvas');
      canvas.width = img.width;
      canvas.height = img.height;
      var ctx = canvas.getContext("2d");
  
      // due to a Firefox bug
      try {
        ctx.drawImage(img, 0, 0);
      } catch (e) {
        if (e.name === "NS_ERROR_NOT_AVAILABLE") {
          // sometimes happens, lets just abort
          return false;
        } else {
          throw e;
        }
      }
  
      try {
        var img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
      } catch (e) {
        if(e.name === 'IndexSizeError') {
          return false; // not sure what causes this sometimes but okay abort
        } else {
          throw e;
        }
      }
  
      // prepare the input: get pixels and normalize them
      var p = img_data.data;
      var W = img.width;
      var H = img.height;
      var pv = []
      for(var i=0;i<p.length;i++) {
        pv.push(p[i]/255.0-0.5); // normalize image pixels to [-0.5, 0.5]
      }
      var x = new Vol(W, H, 4, 0.0); //input volume (image)
      x.w = pv;
  
      if(convert_grayscale) {
        // flatten into depth=1 array
        var x1 = new Vol(W, H, 1, 0.0);
        for(var i=0;i<W;i++) {
          for(var j=0;j<H;j++) {
            x1.set(i,j,0,x.get(i,j,0));
          }
        }
        x = x1;
      }
  
      return x;
    }
docs: img is a DOM element that contains a loaded image returns a Vol of size (W, H, 4). 4 is for RGBA