basic operations of the image
We can get the value of a pixel through the image.get_pixel(x, y) method.
For grayscale image: Return the grayscale value of (x,y) coordinates. For color images: return the (r, g, b) tuple of (x, y) coordinates.
Similarly, we can use the image.set_pixel(x, y, pixel) method to set the value of a pixel.
-image.set_pixel(x, y, pixel)
For grayscale image: Set the grayscale value of (x,y) coordinates. For color images: Set the (r, g, b) value of (x, y) coordinates.
img = sensor.snapshot() img.get_pixel(10,10) img.set_pixcel(10,10,(255,0,0))#Set the pixel of coordinate (10,10) to red (255,0,0)
Get the width and height of the image
Returns the width of the image (pixels)
Returns the height of the image (pixels)
The grayscale image will return sensor.GRAYSCALE, and the color image will return sensor.RGB565.
Returns the size of the image (byte)
Inversely, for a binarized image, 0 (black) becomes 1 (white), and 1 (white) becomes 0 (black). Note: The image can be another image object, or an image object read in from a (bmp/pgm/ppm) file. Both images must be the same size and type (grayscale image/color image).
Perform NAND operation with another picture.
Perform a NOR operation with another picture.
Perform an exclusive OR (XOR) operation with another picture.
Perform XNOR operation with another image.
Subtract another picture from this picture. For example, for each pixel of each channel, subtract the absolute value operation. This function is often used for motion detection.