int StackPrint(void) { if(curstksize < 1){ return 0; } for(int i = curstksize - 1; i >= 0; --i){ printf("%s\n", r2s(stack[i])); } return 0; }
static window_regression_stats *get_window_regression_stats( const grid<pixel_t> &red, const grid<pixel_t> &nir, size_t size, bool force) { size_t output_block = 100; size_t row_count = (red.height() / size); IF_NORMAL(std::cout << row_count << " rows" << std::endl); size_t window_count = (red.width() / size) * row_count; array<numeric_t> slopes(window_count); array<numeric_t> intercepts(window_count); array<numeric_t> r2s(window_count); array<bool> goodness(window_count); numeric_t *slopes_ptr = slopes.data(); numeric_t *intercepts_ptr = intercepts.data(); numeric_t *r2s_ptr = r2s.data(); bool *ptr_goodness = goodness.data(); size_t good_count = 0; rect<size_t> subr = {0, 0, size, size}; for (subr.y = 0; subr.y + size <= red.height() && subr.y + size <= nir.height(); subr.y += size) { for (subr.x = 0; subr.x + size <= red.width() && subr.x + size <= nir.width(); subr.x += size) { const grid<pixel_t> red_sub( const_cast<grid<pixel_t>*>(&red), subr); const grid<pixel_t> nir_sub( const_cast<grid<pixel_t>*>(&nir), subr); if (force || is_good_data(red_sub, nir_sub)) { linear_regression *reg = stats_find_linear_regression(red_sub, nir_sub); *slopes_ptr = reg->eq.slope; *intercepts_ptr = reg->eq.intercept; *r2s_ptr = reg->r2; *ptr_goodness = true; good_count++; delete reg; } else { IF_VERBOSE(std::cout << "Bad sector: "); IF_VERBOSE(std::cout << "(" << subr.x); IF_VERBOSE(std::cout << ", " << subr.y); IF_VERBOSE(std::cout << ") "); *ptr_goodness = false; } slopes_ptr++; intercepts_ptr++; r2s_ptr++; ptr_goodness++; } if ((subr.y / size) % output_block == 0) { IF_NORMAL(std::cout << "\ranalyzing rows " "starting at " << (subr.y / size) << "..."); IF_NORMAL(std::cout.flush()); } } IF_NORMAL(std::cout << std::endl); // okay, we have slope data, now find statistics window_regression_stats *stats = new window_regression_stats; // first, filter out the bad ones IF_VERBOSE(std::cout << "Found " << good_count); IF_VERBOSE(std::cout << " good sectors out of "); IF_VERBOSE(std::cout << window_count << std::endl); array<numeric_t> good_slope_data(good_count); array<numeric_t> good_intercept_data(good_count); array<numeric_t> good_r2_data(good_count); size_t good_data_cur = 0; for (size_t i = 0; i < window_count; i++) { if (goodness[i]) { good_slope_data[good_data_cur] = slopes[i]; good_intercept_data[good_data_cur] = intercepts[i]; good_r2_data[good_data_cur] = r2s[i]; good_data_cur++; } } stats->slope_mean = numeric_mean(good_slope_data); stats->slope_stddev = numeric_stddev(good_slope_data); stats->intercept_mean = numeric_mean(good_intercept_data); stats->intercept_stddev = numeric_stddev(good_intercept_data); stats->r2_mean = numeric_mean(good_r2_data); stats->r2_stddev = numeric_stddev(good_r2_data); stats->window_size = size; return stats; }