#include #include #include #include #include "haader.h" using namespace std; using namespace haader; HdrImageStack::HdrImageStack() { } bool HdrImageStack::read_from_files(char * const* file_paths, int number_of_paths) { m_images.clear(); if (number_of_paths < 0) { cerr << "HdrImageStack::read_from_files: number_of_paths is negative" << endl; return false; } for (int i = 0; i < number_of_paths; i++) { m_images.push_back(Image()); if (m_images[i].read_from_file(file_paths[i])) { cout << "Read \"" << file_paths[i] << "\"" << endl; if (!m_images[0].has_equal_dimensions(m_images[i])) { cerr << "HdrImageStack::read_from_files: Dimensions do not match (\"" << file_paths[i] << "\")" << endl; return false; } } else { return false; } } return true; } bool HdrImageStack::get_average_image_slow(Image &output) { if (m_images.size() == 0) { return false; } output.m_image_data.resize(m_images[0].m_image_data.size()); output.m_width = m_images[0].m_width; output.m_height = m_images[0].m_height; output.m_components = m_images[0].m_components; unsigned int bytes_size = m_images[0].m_image_data.size(); unsigned int images_size = m_images.size(); for (unsigned int i = 0; i < bytes_size; i++) { int v = 0; for (unsigned int k = 0; k < images_size; k++) { v += m_images[k].m_image_data[i]; } output.m_image_data[i] = v / (int)images_size; } return true; } bool HdrImageStack::get_average_image(Image &output) { if (m_images.size() == 0) { return false; } output.m_image_data.resize(m_images[0].m_image_data.size()); output.m_width = m_images[0].m_width; output.m_height = m_images[0].m_height; output.m_components = m_images[0].m_components; unsigned int bytes_size = m_images[0].m_image_data.size(); unsigned int images_size = m_images.size(); const unsigned int buf_size = 128; int buf[buf_size]; for (unsigned int i = 0; i + buf_size <= bytes_size; i += buf_size) { for (unsigned int m = 0; m < buf_size; m++) { buf[m] = m_images[0].m_image_data[i + m]; } for (unsigned int k = 1; k < images_size; k++) { for (unsigned int m = 0; m < buf_size; m++) { buf[m] += m_images[k].m_image_data[i + m]; } } for (unsigned int m = 0; m < buf_size; m++) { output.m_image_data[i + m] = buf[m] / images_size; } } // TODO test this with an image that is prime numbered dimensions unsigned int rest = bytes_size % buf_size; for (unsigned int i = bytes_size - rest; i < bytes_size; i++) { int v = 0; for (unsigned int k = 0; k < images_size; k++) { v += m_images[k].m_image_data[i]; } output.m_image_data[i] = v / (int)images_size; } return true; } bool HdrImageStack::samples_to_csv(const char *file_path) { if (m_images.size() == 0) { return false; } srand(time(0)); ofstream output(file_path); if (output.is_open()) { unsigned int images_size = m_images.size(); unsigned int c = m_images[0].m_components; unsigned int width = m_images[0].m_width; unsigned int height = m_images[0].m_height; for (unsigned int i = 0; i < 100; i++) { unsigned int x = rand() % width; unsigned int y = rand() % height; unsigned int index = (y * width + x) * c; for (unsigned int k = 0; k < images_size; k++) { int val = m_images[k].m_image_data[index]; output << val; if (k + 1 < images_size) { output << ','; } else { output << '\n'; } } } return true; } else { return false; } } bool HdrImageStack::recover_response_function(ResponseFunction &respFunc) { //TODO implement return false; }