Merge branch 'main' of github.com:UCBerkeley-Spring2022-CS284A-Project/HDRplus

main
Xiao Song 3 years ago
commit 9c052a6c75

@ -33,6 +33,11 @@ find_library(LIBRAW_LIBRARY NAMES raw raw_r)
include_directories( BEFORE "/usr/local/include/") include_directories( BEFORE "/usr/local/include/")
message(STATUS "Found LIBRAW_LIBRARY to be ${LIBRAW_LIBRARY}" ) message(STATUS "Found LIBRAW_LIBRARY to be ${LIBRAW_LIBRARY}" )
# Exiv2
find_package(exiv2 REQUIRED CONFIG NAMES exiv2)
link_libraries(exiv2lib)
message(STATUS "Found Exiv2 and linked")
if(NOT APPLE) if(NOT APPLE)
# The clang compiler (on osx) is somehow much more strict # The clang compiler (on osx) is somehow much more strict
# than the compilers on ubuntu and so this does not seem # than the compilers on ubuntu and so this does not seem

@ -26,6 +26,10 @@ class bayer_image
int white_level; int white_level;
std::vector<int> black_level_per_channel; std::vector<int> black_level_per_channel;
float iso; float iso;
private:
float baseline_lambda_shot = 3.24 * pow( 10, -4 );
float baseline_lambda_read = 4.3 * pow( 10, -6 );
}; };
} // namespace hdrplus } // namespace hdrplus

@ -17,12 +17,12 @@ class merge
* @brief Run alignment on burst of images * @brief Run alignment on burst of images
* *
* @param burst_images collection of burst images * @param burst_images collection of burst images
* @param aligements alignment in pixel value pair. * @param alignments alignment in pixel value pair.
* Outer most vector is per alternative image. * Outer most vector is per alternative image.
* Inner most two vector is for horizontle & verticle tiles * Inner most two vector is for horizontal & vertical tiles
*/ */
void process( const hdrplus::burst& burst_images, \ void process( const hdrplus::burst& burst_images, \
std::vector<std::vector<std::vector<std::pair<int, int>>>>& aligements ); std::vector<std::vector<std::vector<std::pair<int, int>>>>& alignments);
}; };
} // namespace hdrplus } // namespace hdrplus

@ -5,6 +5,7 @@
#include <stdexcept> // std::runtime_error #include <stdexcept> // std::runtime_error
#include <opencv2/opencv.hpp> // all opencv header #include <opencv2/opencv.hpp> // all opencv header
#include <libraw/libraw.h> #include <libraw/libraw.h>
#include <exiv2/exiv2.hpp> // exiv2
#include "hdrplus/bayer_image.h" #include "hdrplus/bayer_image.h"
#include "hdrplus/utility.h" // box_filter_2x2 #include "hdrplus/utility.h" // box_filter_2x2
namespace hdrplus namespace hdrplus
@ -31,13 +32,33 @@ bayer_image::bayer_image( const std::string& bayer_image_path )
// Get image basic info // Get image basic info
width = int( libraw_processor->imgdata.rawdata.sizes.raw_width ); width = int( libraw_processor->imgdata.rawdata.sizes.raw_width );
height = int( libraw_processor->imgdata.rawdata.sizes.raw_height ); height = int( libraw_processor->imgdata.rawdata.sizes.raw_height );
white_level = int( libraw_processor->imgdata.rawdata.color.maximum );
// Read exif tags
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(bayer_image_path);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
std::string error(bayer_image_path);
error += ": No Exif data found in the file";
std::cout << error << std::endl;
}
white_level = exifData["Exif.Image.WhiteLevel"].toLong();
black_level_per_channel.resize( 4 ); black_level_per_channel.resize( 4 );
black_level_per_channel.at( 0 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 0 ] + libraw_processor->imgdata.rawdata.color.black ); black_level_per_channel.at(0) = exifData["Exif.Image.BlackLevel"].toLong(0);
black_level_per_channel.at( 1 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 1 ] + libraw_processor->imgdata.rawdata.color.black ); black_level_per_channel.at(1) = exifData["Exif.Image.BlackLevel"].toLong(1);
black_level_per_channel.at( 2 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 2 ] + libraw_processor->imgdata.rawdata.color.black ); black_level_per_channel.at(2) = exifData["Exif.Image.BlackLevel"].toLong(2);
black_level_per_channel.at( 3 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 3 ] + libraw_processor->imgdata.rawdata.color.black ); black_level_per_channel.at(3) = exifData["Exif.Image.BlackLevel"].toLong(3);
iso = float( libraw_processor->imgdata.other.iso_speed ); iso = exifData["Exif.Image.ISOSpeedRatings"].toLong();
// white_level = int( libraw_processor->imgdata.rawdata.color.maximum );
// black_level_per_channel.resize( 4 );
// black_level_per_channel.at( 0 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 0 ] + libraw_processor->imgdata.rawdata.color.black );
// black_level_per_channel.at( 1 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 1 ] + libraw_processor->imgdata.rawdata.color.black );
// black_level_per_channel.at( 2 ) = int( libraw_processor->imgdata.rawdata.color.cblack[ 2 ] + libraw_processor->imgdata.rawdata.color.black );
// black_level_per_channel.at( 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 // Create CV mat
// https://answers.opencv.org/question/105972/de-bayering-a-cr2-image/ // https://answers.opencv.org/question/105972/de-bayering-a-cr2-image/
@ -57,13 +78,24 @@ bayer_image::bayer_image( const std::string& bayer_image_path )
std::pair<double, double> bayer_image::get_noise_params() const std::pair<double, double> bayer_image::get_noise_params() const
{ {
double iso100_lambdas = 3.24 * 0.0001; // Set ISO to 100 if not positive
double iso100_lambdar = 4.3 * 0.000001; double iso_ = iso <= 0 ? 100 : iso;
// Calculate shot noise and read noise parameters w.r.t ISO 100
double lambda_shot_p = iso_ / 100.0f * baseline_lambda_shot;
double lambda_read_p = (iso_ / 100.0f) * (iso_ / 100.0f) * baseline_lambda_read;
double black_level = (black_level_per_channel[0] + \
black_level_per_channel[1] + \
black_level_per_channel[2] + \
black_level_per_channel[3]) / 4.0;
double lambdas = iso / 100 * iso100_lambdas; // Rescale shot and read noise to normal range
double lambdar = ( iso / 100 ) * ( iso / 100 ) * iso100_lambdar; double lambda_shot = lambda_shot_p * (white_level - black_level);
double lambda_read = lambda_read_p * (white_level - black_level) * (white_level - black_level);
return std::make_pair<int, int>(lambdas, lambdar); // return pair
return std::make_pair(lambda_shot, lambda_read);
} }
} }

@ -7,7 +7,7 @@ namespace hdrplus
{ {
void merge::process( const hdrplus::burst& burst_images, \ void merge::process( const hdrplus::burst& burst_images, \
std::vector<std::vector<std::vector<std::pair<int, int>>>>& aligements ) std::vector<std::vector<std::vector<std::pair<int, int>>>>& alignments)
{ {
} }

Loading…
Cancel
Save