white level, black level

main
Xiao Song 3 years ago
parent 0fcb8e6e63
commit 71c1ca9491

@ -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(

@ -1,6 +1,8 @@
#pragma once
#include <string>
#include <vector>
#include <utility> // std::pair
#include <memory> // std::shared_ptr
#include <opencv2/opencv.hpp> // all opencv header
#include <libraw/libraw.h>
@ -14,12 +16,16 @@ class bayer_image
explicit bayer_image( const std::string& bayer_image_path );
~bayer_image() = default;
std::pair<double, double> get_noise_params() const;
std::shared_ptr<LibRaw> libraw_processor;
cv::Mat raw_image;
cv::Mat grayscale_image;
int width;
int height;
int white_level;
std::vector<int> black_level_per_channel;
float iso;
};
} // namespace hdrplus

@ -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<std::string> bayer_image_paths;
};
} // namespace hdrplus

@ -200,6 +200,7 @@ void align::process( const hdrplus::burst& burst_images, \
std::vector<std::pair<int, int>> 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,6 +212,7 @@ 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 );

@ -1,5 +1,6 @@
#include <string>
#include <cstdio>
#include <utility> // std::pair, std::makr_pair
#include <memory> // std::shared_ptr
#include <stdexcept> // std::runtime_error
#include <opencv2/opencv.hpp> // 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<uint16_t>( 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<double, double> 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<int, int>(lambdas, lambdar);
}
}

@ -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<cv::String> bayer_image_paths;
// Search through the input path directory to get all input image path
cv::glob( burst_path + "/*.dng", bayer_image_paths, false );

@ -1,4 +1,5 @@
#include <cstdio>
#include <utility> // 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<double, double> 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] );
}
Loading…
Cancel
Save