BAYER image scaling

Hi, I bought an OpenMV H7 and i’m using a color global shutter sensor (MT9V034-C), I was wandering if i could downsample the image (instead of using full VGA I’d like to “drop” half of the rows and half of the columns) or get a snapshot in QVGA without cropping the sensor (something like pixel binning). As of now I’m snapping in VGA, then using to_rgb565(x_scale=0.5,y_scale0.5) I’m getting the image, but part of it is corrupted due to out of memory (I’m guessing that it returns the rgb image before the downsample) and I don’t really need all that resolution

Hi there,
did you try the sensor.set_windowing ?

Yeah, actually i’m already using it, but sensor.set_windowing() returns a cropped image, not a scaled one, the thing that I’m trying to accomplish is to reduce resolution without reducing “apparent” sensor area (thus, FOV). Taking a look at FW sources rn, I think that i can drop some rows and columns from “bayer.c”, not completely sure how though

but windowing do this. in fact does a digital zoom which is what you want.
DO you want a larger fov? If yes why dont you move your camera?

Hi, think about what you are asking.

You want a downsampled image on a bayer sensor. If you ask the sensor to bin it’s pixels then that will produce a grayscale image since you are binning R/G/G/B.

The MT9V034 doesn’t have an ISP. So, you have to recieve the full image, debayer, and then scale down.

And I’m telling you that I don’t want a digital zoom, I don’t want to crop the sensor
Let’s assume the sensor is 8x4 and looks like this:

--------------------------------------
| rg | rg |rg | rg |rg | rg |rg | rg |
| gb | gb |gb | gb |gb | gb |gb | gb |
--------------------------------------
| rg | rg |rg | rg |rg | rg |rg | rg |
| gb | gb |gb | gb |gb | gb |gb | gb |
--------------------------------------
| rg | rg |rg | rg |rg | rg |rg | rg |
| gb | gb |gb | gb |gb | gb |gb | gb |
--------------------------------------
| rg | rg |rg | rg |rg | rg |rg | rg |
| gb | gb |gb | gb |gb | gb |gb | gb |
--------------------------------------

Now, cropping the sensor means doing something like this:

| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
--------------------------------------
| 00 | rg | rg | rg | rg | rg | rg | 00 |
| 00 | gb | gb | gb | gb | gb | gb | 00 |
--------------------------------------
| 00 | rg | rg | rg | rg | rg | rg | 00 |
| 00 | gb | gb | gb | gb | gb | gb | 00 |
--------------------------------------
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
-----------------------------------------

where “0” means that that pixel is not used

What i want instead is:

--------------------------------------
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
--------------------------------------
| rg | 00 | rg | 00 | rg | 00 | rg | 00 |
| gb | 00 | gb | 00 | gb | 00 | gb | 00 |
--------------------------------------
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
--------------------------------------
| rg | 00 | rg | 00 | rg | 00 | rg | 00 |
| gb | 00 | gb | 00 | gb | 00 | gb | 00 |
--------------------------------------

making use of 1/4 of the sensor but keeping the same FOV (because there’s minimal cropping)

And there is not a way to read sensor’s rows like:

--------------------------------------------------------
| rg | skip col_1 | rg | skip col_3 | rg | skip col_5...
| gb | skip col_1 | gb | skip col_3 | gb | skip col_5...
--------------------------------------------------------

?

croping doesnt keep the spartial resolution of the default image.
Instead it does binning and reduse the resolution of your image.
If you want larger field of you use another lens or go back with the camera.
See this also:

Yeah, on monochrome sensor, color sensor on the other hand doesn’t allow binning (as kwagyeman rightfully said)

1 Like

As mentioned in my last post. The sensor itself doesn’t have an ISP. If you ask it to Bin the pixels it will just average R/G/G/B into a grayscale value. It will not average the components into 3 separate values. Only sensors with an ISP onboard do that like the OV5640.

As such, I disabled binning in the driver if it detects a colored camera and it just crops instead.

If you modify the driver and disable that check it will bin the image then and the image will be grayscale.

If that is okay with you then I’d modify the driver code to skip checking if the sensor has a CFA (color filter array) and our driver will treat it like the grayscale global shutter sensors.

The image will look fine in this case as long as you are binning. If you use a non binned resolution and treat it like a grayscale image you’ll see a checkerboard pattern on the image.

1 Like

No I don’t want to bin it, I just need to know if at least in theory there is a way to eliminate certain rows and columns from the Bayer image read, and maybe return it into an object 1/4 of the Bayer image resolution

There’s a way to do that but you have to modify our driver code.

You’d need to modify our MDMA driver to skip columns and rows. It’s possible, but, this isn’t really something we’ll support in our firmware by default. You’ll find the result produces an absolutely terrible image. This is called decimation. But, it’s not low pass filtered (binning) so it results in a lot of jaggies.

1 Like