Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TiffImage NDWICalculator::generate_ndwi_layer_green_nir_high_performance(
- const TiffImage &green_layer, const TiffImage &nir_layer, unsigned int cores) {
- std::vector<std::thread> thread_pool;
- TiffImage result(green_layer.width(), green_layer.height(), 1, 1);
- for (unsigned int i = 0UL; i < cores; ++i) {
- thread_pool.emplace_back(
- std::thread([i, cores, &result, &green_layer, &nir_layer]() {
- unsigned int height = green_layer.height() / cores;
- unsigned int start = i > 0 ? height * i : height * i + 1;
- unsigned int stop = i < cores - 1 ? height * (i + 1) + 1 : (height * (i + 1));
- for (unsigned int y = start; y < stop - 1; ++y) {
- for (unsigned int x = 0; x < static_cast<unsigned int>(green_layer.width()); ++x) {
- float green_value = green_layer(x, y);
- float nir_value = nir_layer(x, y);
- if (green_value > 1.f && nir_value > 1.f) {
- float ndwi_level = (green_value - nir_value) / (green_value + nir_value);
- result(x, y) = static_cast<unsigned char>(ndwi_level >= 0.33f ? 255 : 0);
- }
- }
- }
- }));
- }
- for (auto &&thread : thread_pool) {
- thread.join();
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement