Excess green preprocessing


I want to convert an image to greyscale with the following formula: result_img = 2 * snapshot[‘green’] - snapshot[‘red’] - snapshot[‘blue’]
Is there any way i can manipulate an array direcly (numpy style)? If not, are there any library functions that can help me do this?

There’s a .to_grayscale() method which will make an RGB565 image grayscale.

What you are trying to do though isn’t exactly in the API. However it can be done…

You need to:

fb_r = sensor.alloc_extra_fb(...)
fb_b = sensor.alloc_extra_fb(...)
img.to_grayscale(copy=fb_r, rgb_channel=0) # extract red
img.to_grayscale(copy=fb_b, rgb_channel=2) # extract blue
img.to_grayscale(rgb_channel=1) # extract green

The above will clip all over the place however since each operation will try to scale results. We don’t allow general purpose math to be done on arrays. We do have something called ulab (np on micropython) which allows for operations like this… But, it’s not so well built out for what you want.

Can you describe more what you are trying to do? We could put some more work into the image module to enable ulab to do what you need. It right now allows you to cast images into objects you can use np like math on. However, I think our cast operation is not memory efficient right now.