Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NxM image support #3

Open
ransnir opened this issue Oct 24, 2013 · 0 comments
Open

NxM image support #3

ransnir opened this issue Oct 24, 2013 · 0 comments

Comments

@ransnir
Copy link

ransnir commented Oct 24, 2013

Hi,
Great work! I work with it a bit and found that you are not supporting NxM images.
I think that you have a small logic error in the intensities function (pricessing.js file). The inner loop working on the "imagedata.height", as well the outer loop. Moreover the calculation of "i" seems to be different from the other functions.

I suggest this fix, it worked well on NxM images.

intensities: function(imagedata) {
if (!imagedata.data) {
// it's a canvas, extract the imagedata
var canvas = imagedata;
var context = canvas.getContext("2d");
imagedata = context.getImageData(0, 0, canvas.width, canvas.height);
}

var lumas = new Array(imagedata.height);

for (var y = 0; y < imagedata.height; y++) {
  lumas[y] = new Array(imagedata.width);

  for (var x = 0; x < imagedata.width; x++) {
    //var i = x * 4 + y * 4 * imagedata.width;
    var i = (y * 4) * imagedata.width + x * 4;
    var r = imagedata.data[i],
        g = imagedata.data[i + 1],
        b = imagedata.data[i + 2],
        a = imagedata.data[i + 3];

    var luma = a == 0 ? 1 : (r * 299/1000 + g * 587/1000
      + b * 114/1000) / 255;

    lumas[y][x] = luma;
  }
}

return lumas;

}

pnidl pushed a commit to pnidl/hog-descriptor that referenced this issue Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant