Convert image to grayscale strings

I would like to use the node API pointer . I need to convert the image to grayscale and then to arrays containing arrays / strings of pixel values. Where to begin?

These tools take a specific format for images, a list of lists, each sub-list containing a "string" of values ​​corresponding to n pixels in the image.

e.g. [[float, float, float ... *n ], [float, float, float ... *n ], ... *n]

Since pixels are typically represented by RGBA values, you can use the following formula to convert to grayscale.

Y = (0.2126 * R + 0.7152 * G + 0.0722 * B) * A

We are working on automatic scaling of images, but at the moment this is provided to you a square image

+4
source share
2

, node, , , .

get-pixels URL- ndarray, API.

API RGB , get-pixels , , , .

RGB- , . :

Grayscale = 0.2126*R + 0.7152*G + 0.0722*B

API URL-, .

+4

sharp Node.js, , .

input Buffer , .

255 float, , API Indico.

sharp(input)
  .resize(width, height)
  .grayscale()
  .raw()
  .toBuffer(function(err, data) {
    // data is a Buffer containing uint8 values (0-255)
    // with each byte representing one pixel
  });
+3

All Articles