From d2880a6406a887a1e14ea0ce72fa7009add577c2 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 23 Jun 2020 13:04:48 +0100 Subject: [PATCH] Fix clipping on linear equalise --- image.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/image.c b/image.c index 6eb4bff..c5a99ec 100644 --- a/image.c +++ b/image.c @@ -90,16 +90,19 @@ void linearEnhance(float **prow, int nrow, int offset, int width){ // Find min/max points int min = -1, max = -1; for(int i = 5; i < 250; i++){ - if(histogram[i]/width/(nrow/255.0) > 0.25){ + if(histogram[i]/width/(nrow/255.0) > 0.1){ if(min == -1) min = i; max = i; } } // Stretch the brightness into the new range - for(int y = 0; y < nrow; y++) - for(int x = 0; x < width; x++) + for(int y = 0; y < nrow; y++){ + for(int x = 0; x < width; x++){ prow[y][x+offset] = (prow[y][x+offset]-min) / (max-min) * 255.0; + prow[y][x+offset] = CLIP(prow[y][x+offset], 0.0, 255.0); + } + } } // Brightness calibrate, including telemetry @@ -397,4 +400,4 @@ void temperature(options_t *opts, image_t *img, int offset, int width){ } } printf("Done\n"); -} \ No newline at end of file +}