I made this code to cycle through every pixel in an image and output its RGBA value to the console. Why doesn't it work as intended? I seem to be getting all [0,0,0,0]s for PixelData. I tried several pieces of code from stackoverflow.com but they didn't help. My ultimate goal is to compare these colors to a list of other colors and pick the closest one for each pixel, but I should be able to do that alone once I get this part answered.
<!doctype html>
<html>
<head>
<img id="myImage" src="img.png" width="64px" height="64px"></img>
<script>
var img = document.getElementById('myImage');
var mycanvas = document.createElement('canvas');
mycanvas.width = img.width;
mycanvas.height = img.height;
var context = mycanvas.getContext('2d');
context.drawImage(img, 0, 0, img.width, img.height);
for(var x=1;x<=16;x++){
for(var y=1;y<=16;y++){
var pixelData = context.getImageData(x, y, 1, 1).data;
console.log("x="+x.toString()+" y="+y.toString()+" pD="+pixelData.toString()+" ");
}}
</script></head>
<body></body>
</html>