aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-07-13 20:57:06 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:33 +0100
commit7447a444908886a818d1ed80da7ebd52161b375e (patch)
treecc996e8f99fd8419127a8627d8c08eb562e65632
parent9444799ba6a30d2dc43b15320ef3e83943c29546 (diff)
Heuristic to prevent silly histogram axes
-rw-r--r--src/scaling-report.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/scaling-report.c b/src/scaling-report.c
index 330f9757..197f72f9 100644
--- a/src/scaling-report.c
+++ b/src/scaling-report.c
@@ -373,6 +373,7 @@ static void scale_factor_histogram(cairo_t *cr, const struct image *images,
const double g_width = 320.0;
const double g_height = 180.0;
char tmp[32];
+ int n_zero, n_half;
show_text_simple(cr, title, g_width/2.0, -18.0,
"Sans Bold 10", 0.0, J_CENTER);
@@ -388,25 +389,44 @@ static void scale_factor_histogram(cairo_t *cr, const struct image *images,
if ( osf > osf_max ) osf_max = osf;
}
osf_max = ceil(osf_max);
- osf_inc = osf_max / nbins;
- for ( b=0; b<nbins; b++ ) {
- osf_low[b] = b*osf_inc;
- osf_high[b] = (b+1)*osf_inc;
- counts[b] = 0;
- }
+ do {
- for ( i=0; i<n; i++ ) {
-
- double osf = images[i].osf;
+ osf_inc = osf_max / nbins;
for ( b=0; b<nbins; b++ ) {
- if ( (osf >= osf_low[b]) && (osf < osf_high[b]) ) {
- counts[b]++;
- break;
+ osf_low[b] = b*osf_inc;
+ osf_high[b] = (b+1)*osf_inc;
+ counts[b] = 0;
+ }
+
+ for ( i=0; i<n; i++ ) {
+
+ double osf = images[i].osf;
+
+ for ( b=0; b<nbins; b++ ) {
+ if ( (osf >= osf_low[b])
+ && (osf < osf_high[b]) )
+ {
+ counts[b]++;
+ break;
+ }
}
}
- }
+
+ /* Count the number of bins with no counts, subtract 1 from
+ * the maximum value until this isn't the case */
+ n_zero = 0;
+ n_half = 0;
+ for ( b=0; b<nbins; b++ ) {
+ if ( counts[b] == 0 ) n_zero++;
+ n_half++;
+ }
+ n_half /= 2;
+
+ if ( n_zero > n_half ) osf_max -= 1.0;
+
+ } while ( n_zero > n_half );
f_max = 0;
for ( b=0; b<nbins; b++ ) {