Version: 1.0
Loading...
Searching...
No Matches
Auto White Balance Example

#include <stdio.h>
#include <stdlib.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image/stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image/stb_image_write.h"
int main(void) {
int width, height, channels;
unsigned char* inputImage = stbi_load("test.jpg", &width, &height, &channels, 0);
if (inputImage) {
unsigned char* outputImage = (unsigned char*)calloc(width * channels * height * sizeof(unsigned char), 1);
if (outputImage) {
int stride = width * channels;
int colorCoeff = 15;
float cutLimit = 0.01;
float contrast = 0.9;
bool colorCast = false;
OC_STATUS status = ocularAutoWhiteBalance(inputImage, outputImage, width, height, channels, stride, colorCoeff, cutLimit, contrast, &colorCast);
if (status == OC_STATUS_OK) {
if (colorCast) {
printf("[✓] ColorCast\n");
} else {
printf("[x] ColorCast\n");
}
stbi_write_jpg("test_out.jpg", width, height, channels, outputImage, 100);
}
}
free(outputImage);
}
stbi_image_free(inputImage);
}
OC_STATUS ocularAutoWhiteBalance(unsigned char *input, unsigned char *output, int Width, int height, int stride, int colorCoeff, float cutLimit, float contrast, bool *hasColorCast)
Automatically applies a neutral white balance to an image.

Before

After