From 71c1ca94910a6a5867a9640ad2af88a320f294f3 Mon Sep 17 00:00:00 2001 From: Xiao Song Date: Sun, 17 Apr 2022 16:59:20 -0700 Subject: [PATCH] white level, black level --- CMakeLists.txt | 5 +++-- include/hdrplus/bayer_image.h | 6 ++++++ include/hdrplus/burst.h | 5 ----- src/align.cpp | 4 +++- src/bayer_image.cpp | 30 ++++++++++++++++++++++++------ src/burst.cpp | 2 +- tests/test_bayer_image.cpp | 20 ++++++++++++++++++++ 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4abe670..73d22e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.0) project(hdrplus) # set c++ standard -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -march=native -O3 -funroll-loops") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -funroll-loops") @@ -29,8 +29,9 @@ include_directories( BEFORE "/usr/local/include/") message(STATUS "Found LIBRAW_LIBRARY to be ${LIBRAW_LIBRARY}" ) # dependency opencv -find_package( OpenCV REQUIRED ) +find_package( OpenCV 4.5.5 REQUIRED ) include_directories( BEFORE ${OpenCV_INCLUDE_DIRS}) +message(STATUS "Found OpenCV ${OpenCV_INCLUDE_DIRS} ${OpenCV_LIBS}") # library include_directories( diff --git a/include/hdrplus/bayer_image.h b/include/hdrplus/bayer_image.h index 57f7370..81b30ef 100644 --- a/include/hdrplus/bayer_image.h +++ b/include/hdrplus/bayer_image.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include // std::pair #include // std::shared_ptr #include // all opencv header #include @@ -14,12 +16,16 @@ class bayer_image explicit bayer_image( const std::string& bayer_image_path ); ~bayer_image() = default; + std::pair get_noise_params() const; + std::shared_ptr libraw_processor; cv::Mat raw_image; cv::Mat grayscale_image; int width; int height; int white_level; + std::vector black_level_per_channel; + float iso; }; } // namespace hdrplus diff --git a/include/hdrplus/burst.h b/include/hdrplus/burst.h index 941722c..8a1b0a1 100644 --- a/include/hdrplus/burst.h +++ b/include/hdrplus/burst.h @@ -26,11 +26,6 @@ class burst // number of image (including reference) in burst int num_images; - - private: - std::string reference_image_path; - std::string burst_path; - std::vector bayer_image_paths; }; } // namespace hdrplus diff --git a/src/align.cpp b/src/align.cpp index f15ab4a..707b914 100644 --- a/src/align.cpp +++ b/src/align.cpp @@ -200,6 +200,7 @@ void align::process( const hdrplus::burst& burst_images, \ std::vector> prev_alignment; for ( int level_i = num_levels - 1; level_i >= 0; level_i-- ) { + /* align_image_level( ref_imgs_pyramid[ level_i ], // reference image at current level alt_imgs_pyramid[ level_i ], // alternative image at current level @@ -211,7 +212,8 @@ void align::process( const hdrplus::burst& burst_images, \ ( level_i == ( num_levels - 1 ) ? -1 : tile_sizes[ level_i + 1] ), // previous level tile size search_radious[ level_i ], // search radious distances[ level_i ] ); // L1/L2 distance - + */ + // make curr alignment as previous alignment prev_alignment.swap( curr_alignment ); curr_alignment.clear(); diff --git a/src/bayer_image.cpp b/src/bayer_image.cpp index a8be486..c57b02e 100644 --- a/src/bayer_image.cpp +++ b/src/bayer_image.cpp @@ -1,5 +1,6 @@ #include #include +#include // std::pair, std::makr_pair #include // std::shared_ptr #include // std::runtime_error #include // all opencv header @@ -31,12 +32,11 @@ bayer_image::bayer_image( const std::string& bayer_image_path ) width = int( libraw_processor->imgdata.rawdata.sizes.raw_width ); height = int( libraw_processor->imgdata.rawdata.sizes.raw_height ); white_level = int( libraw_processor->imgdata.rawdata.color.maximum ); - - #ifndef NDEBUG - printf("%s::%s read bayer image %s with width %zu height %zu\n", \ - __FILE__, __func__, bayer_image_path.c_str(), width, height ); - fflush( stdout ); - #endif + black_level_per_channel[ 0 ] = int( libraw_processor->imgdata.rawdata.color.cblack[ 0 ] + libraw_processor->imgdata.rawdata.color.black ); + black_level_per_channel[ 1 ] = int( libraw_processor->imgdata.rawdata.color.cblack[ 1 ] + libraw_processor->imgdata.rawdata.color.black ); + black_level_per_channel[ 2 ] = int( libraw_processor->imgdata.rawdata.color.cblack[ 2 ] + libraw_processor->imgdata.rawdata.color.black ); + black_level_per_channel[ 3 ] = int( libraw_processor->imgdata.rawdata.color.cblack[ 3 ] + libraw_processor->imgdata.rawdata.color.black ); + iso = float( libraw_processor->imgdata.other.iso_speed ); // Create CV mat // https://answers.opencv.org/question/105972/de-bayering-a-cr2-image/ @@ -45,6 +45,24 @@ bayer_image::bayer_image( const std::string& bayer_image_path ) // 2x2 box filter grayscale_image = box_filter_2x2( raw_image ); + + #ifndef NDEBUG + printf("%s::%s read bayer image %s with width %zu, height %zu, iso %.3f, white level %d, black level %d %d %d %d\n", \ + __FILE__, __func__, bayer_image_path.c_str(), width, height, iso, white_level, \ + black_level_per_channel[0], black_level_per_channel[1], black_level_per_channel[2], black_level_per_channel[3] ); + fflush( stdout ); + #endif +} + +std::pair bayer_image::get_noise_params() const +{ + double iso100_lambdas = 3.24 * 0.0001; + double iso100_lambdar = 4.3 * 0.000001; + + double lambdas = iso / 100 * iso100_lambdas; + double lambdar = ( iso / 100 ) * ( iso / 100 ) * iso100_lambdar; + + return std::make_pair(lambdas, lambdar); } } diff --git a/src/burst.cpp b/src/burst.cpp index 650e96f..109ddb2 100644 --- a/src/burst.cpp +++ b/src/burst.cpp @@ -7,8 +7,8 @@ namespace hdrplus { burst::burst( const std::string& burst_path, const std::string& reference_image_path ) - : reference_image_path( reference_image_path ), burst_path( burst_path ) { + std::vector bayer_image_paths; // Search through the input path directory to get all input image path cv::glob( burst_path + "/*.dng", bayer_image_paths, false ); diff --git a/tests/test_bayer_image.cpp b/tests/test_bayer_image.cpp index f908751..2a7ef74 100644 --- a/tests/test_bayer_image.cpp +++ b/tests/test_bayer_image.cpp @@ -1,4 +1,5 @@ #include +#include // std::pair #include "hdrplus/bayer_image.h" int main( int argc, char** argv ) @@ -18,4 +19,23 @@ int main( int argc, char** argv ) printf("Gray image of shape h=%d, w=%d\n", \ raw_bayer_image.grayscale_image.size().height, \ raw_bayer_image.grayscale_image.size().width ); + + // 1143 + printf("Image ISO level %.3f\n", raw_bayer_image.iso ); + + // 0.00370332, 0.0005617730699999999 + // 3.55148388, 516.6520187906699 + std::pair noise_param = raw_bayer_image.get_noise_params(); + printf("Image Noise Param lambda_s %.10f lambda_r %.10f\n", \ + noise_param.first, noise_param.second ); + + // 1023 + printf("Image white level %d\n", raw_bayer_image.white_level ); + + // [64, 64, 64, 64] + printf("Image black level %d %d %d %d\n", \ + raw_bayer_image.black_level_per_channel[0], \ + raw_bayer_image.black_level_per_channel[1], \ + raw_bayer_image.black_level_per_channel[2], \ + raw_bayer_image.black_level_per_channel[3] ); } \ No newline at end of file