The basic operation of images

Coordinates

Get /Set pixel points

We can get the value of a pixel point through image.get_pixel(x, y)

  • image.get_pixel(x, y)
    • For grayscale map: return to the grayscale of (x,y)
    • For color map: return to the tuple of (r,g,b) of (x,y)

In the same way can we set the value of a pixel point through image.set_pixel(x, y, pixel).

  • image.set_pixel(x, y, pixel)
    • For grayscale map: set the grayscale of (x,y)
    • For color map: set the value of (r,g,b) of (x,y)

For example:

img = sensor.snapshot()
img.get_pixel(10,10)
img.set_pixcel(10,10,(255,0,0))#set the pixel point of which the coordinate is (10,10) as red(255,0,0)

Get the width and height of images

  • image.width()
    return to the width of the image(pixel)

  • image.height()
    return to the height of the image(pixel)

  • image.format()
    return to sensor.GRAYSCALE when it is grayscale map and sensor.RGB565 when color map

  • image.size()
    return to the size of the image(byte)

Operation of the image

  • image.invert()

Invert, for binary images, means inverting 0(black) to 1(white) and 1(white) to 0(black).

Note: The image can be another object or an image read-in from (bmp/pgm/ppm) documents. In addition, the two images have to be in same size and type (grayscale/color map).

  • image.nand(image)
    Execute NAND with another image.

  • image.nor(image)
    Execute NOR with another image.

  • image.xor(image)
    Execute XOR with another image.

  • image.xnor(image)
    Execute XNOR with another image.

  • image.difference(image)
    Subtract another image from this image. For example, take negative absolute value to each pixel point in each channel. This function is always used to do mobile detection.

results matching ""

    No results matching ""