Use libmpix to collect statistics about the image.
In order to apply various color and contrast correction to an image or other purposes, it is useful to collect statistics from the image.
How to collect statistics with libmpix
First load a buffer into an image struct, specifying the pixel format:
static void mpix_image_from_buf(struct mpix_image *img, const uint8_t *buffer, size_t size, const struct mpix_format *fmt)
Initialize an image from a memory buffer.
Definition image.h:30
Represent the image currently being processed.
Definition types.h:136
Then several types of statistics can be gathered from the image in one function call.
This will sample the specified number of values from the image, and accumulate the information into the statistics struct. For instance here for 1000
values.
void mpix_stats_from_buf(struct mpix_stats *stats, const uint8_t *buf, struct mpix_format *fmt)
Collect red, green, blue channel averages of all pixels in an RGB24 frame.
uint16_t nvals
Definition types.h:182
The content of mpix_stats can be browsed directly for any purpose.
- Note
- Statistics collection must be done before any other operation.
Then derived statistics can optionally be computed out of the generated histograms:
uint8_t mpix_stats_get_y_mean(struct mpix_stats *stats)
Get the mean value from a histogram.
How to support more statistics?
The statistics collection is somewhat minimal at the moment, as focused on providing the minimum.
- Applications will needvery different statistics depending on their goal. For custom statistics, refer to How to sample pixels for directly collecting pixel values from the image.
- libmpix strives to integrate classical computer vision building blocks including statistics, let us know what you needed!