scijs/get-pixels

Retrieve pixel at position x, y of image

slutske22 opened this issue · 2 comments

Hi and thanks for these great tools!

This is less an issue with the actual library than it is with the documentation, both for get-pixels and ndarray. I can't see a clear way to get the 4-channel value of a pixel and its { x, y } position in the image. For example, let's say I transform a 256x256 image with get-pixels. If I want to get the [R,G,B,A] values as position { X: 100, y: 200 }, what is the proper way to do that? Are the values of the pixels laid out in rows, or columns? My inclination would be to try something like

const r = imageAsNdArray.data.get( x, y, 0 ),
  g = imageAsNdArray.data.get( x, y, 1 ),
  b = imageAsNdArray.data.get( x, y, 2 ),
  a = imageAsNdArray.data.get( x, y, 3 )

But this must be wrong, as I see that numbers greater than 3 in the third argument return valid results - clearly the third argument is not the channel. My other inclination was to treat this like a regular array:

It seems that calling .get with anything but 3 arguments gives undefined results. But its really not clear from any of the docs here on in ndarray, how to retrieve the 4 RGBA values of a pixel at given X, Y position.

Am I missing something? What is the magic trick? Can it be added to the README?

Sorry to bother you but do you remember what was the solution? I have the same concern right now. Thanks!

@vkaelin I vaguely recall that instead of doing imageAsNdArray.data.get, you do imageAsNdArray.get(x, y), and that should do it.