From ec668ce3a7a80dac91e420e94f05b65e2b86373f Mon Sep 17 00:00:00 2001 From: Fedor Morozov Date: Fri, 19 Jul 2013 00:23:49 +0400 Subject: [PATCH] Documentation --- doc/mymath.sty | 42 -------------- modules/highgui/src/grfmt_hdr.cpp | 21 ++++--- modules/photo/doc/hdr_imaging.rst | 116 ++++++++++++++++++++++++++++++++++++++ modules/photo/doc/photo.rst | 1 + modules/photo/src/align.cpp | 3 - 5 files changed, 130 insertions(+), 53 deletions(-) create mode 100644 modules/photo/doc/hdr_imaging.rst diff --git a/doc/mymath.sty b/doc/mymath.sty index 491c160..e69de29 100644 --- a/doc/mymath.sty +++ b/doc/mymath.sty @@ -1,42 +0,0 @@ -\ProvidesPackage{mymath} - -\newcommand{\matTT}[9]{ -\[ -\left|\begin{array}{ccc} - #1 & #2 & #3\\ - #4 & #5 & #6\\ - #7 & #8 & #9 -\end{array}\right| -\] -} - -\newcommand{\fork}[4]{ - \left\{ - \begin{array}{l l} - #1 & \mbox{#2}\\ - #3 & \mbox{#4}\\ - \end{array} \right.} -\newcommand{\forkthree}[6]{ - \left\{ - \begin{array}{l l} - #1 & \mbox{#2}\\ - #3 & \mbox{#4}\\ - #5 & \mbox{#6}\\ - \end{array} \right.} - -\newcommand{\vecthree}[3]{ -\begin{bmatrix} - #1\\ - #2\\ - #3 -\end{bmatrix} -} - -\newcommand{\vecthreethree}[9]{ -\begin{bmatrix} - #1 & #2 & #3\\ - #4 & #5 & #6\\ - #7 & #8 & #9 -\end{bmatrix} -} - diff --git a/modules/highgui/src/grfmt_hdr.cpp b/modules/highgui/src/grfmt_hdr.cpp index 3f27304..cf4a0e8 100644 --- a/modules/highgui/src/grfmt_hdr.cpp +++ b/modules/highgui/src/grfmt_hdr.cpp @@ -78,17 +78,19 @@ bool HdrDecoder::readHeader() return true; } -bool HdrDecoder::readData(Mat& img) +bool HdrDecoder::readData(Mat& _img) { + Mat img(m_height, m_width, CV_32FC3); if(!file) { readHeader(); } - if(img.cols != m_width || img.rows != m_height || - img.type() != CV_32FC3) { - CV_Error(Error::StsError, "HDR decoder: bad mat"); - } RGBE_ReadPixels_RLE(file, const_cast(img.ptr()), img.cols, img.rows); fclose(file); file = NULL; + if(_img.depth() == img.depth()) { + img.convertTo(_img, _img.type()); + } else { + img.convertTo(_img, _img.type(), 255); + } return true; } @@ -115,10 +117,13 @@ HdrEncoder::~HdrEncoder() { } -bool HdrEncoder::write( const Mat& img, const std::vector& params ) +bool HdrEncoder::write( const Mat& _img, const std::vector& params ) { - if(img.type() != CV_32FC3) { - CV_Error(Error::StsBadArg, "HDR encoder: need 32FC3 mat"); + Mat img; + if(_img.depth() == CV_32F) { + _img.convertTo(img, CV_32FC3); + } else { + _img.convertTo(img, CV_32FC3, 1/255.0f); } if(!(params.empty() || params[0] == HDR_NONE || params[0] == HDR_RLE)) { CV_Error(Error::StsBadArg, "HDR encoder: wrong compression param"); diff --git a/modules/photo/doc/hdr_imaging.rst b/modules/photo/doc/hdr_imaging.rst new file mode 100644 index 0000000..a9fdb4c --- /dev/null +++ b/modules/photo/doc/hdr_imaging.rst @@ -0,0 +1,116 @@ +HDR imaging +========== + +.. highlight:: cpp + +makeHDR +----------- +Creates HDR image from a set of bracketed exposures using algorithm by Debevec and Malik. + +"Recovering High Dynamic Range Radiance Maps from Photographs", Debevec, Malik, 1997 + +.. ocv:function:: void makeHDR(InputArrayOfArrays srcImgs, const std::vector& expTimes, OutputArray dst, bool align = false) + + :param src_imgs: vector of 8-bit 3-channel images + + :param exp_times: exposure times for each of source images + + :param dst: output image + + :param align: if true, images are first aligned using median threshold bitmap algorithm. See :ocv:func:`getExpShift`. + +tonemap +----------- +Tonemaps image. + +.. ocv:function:: tonemap(InputArray src, OutputArray dst, int algorithm, const std::vector& params = std::vector()) + + :param src: input HDR image + + :param dst: floating-point image in [0; 1] range + + :param algorithm: + * TONEMAP_LINEAR - simple linear mapping + + * TONEMAP_DRAGO - "Adaptive Logarithmic Mapping For Displaying HighContrast Scenes", Drago et al., 2003 + + * TONEMAP_REINHARD - "Dynamic Range Reduction Inspired by Photoreceptor Physiology", Reinhard, Devlin, 2005 + + * TONEMAP_DURAND - "Fast Bilateral Filtering for the Display of High-Dynamic-Range Images", Durand, Dorsey, 2002 + + :param params: vector of parameters for specified algorithm. + If some parameters are missing default values are used. + The first element is gamma value for gamma correction. + + * TONEMAP_LINEAR: + + No parameters. + + * TONEMAP_DRAGO: + + params[1] - value for bias function. Range [0.7, 0.9], default 0.85. + + * TONEMAP_REINHARD: + + params[1] - result intensity. Range [-8, 8], default 0. + + params[2] - chromatic adaptation. Range [0, 1], default 0. + + params[3] - light adaptation. Range [0, 1], default 0; + + * TONEMAP_DURAND: + + params[1] - result contrast on logarithmic scale. + + params[2] - bilateral filter sigma in the color space. + + params[3] - bilateral filter sigma in the coordinate space. + +exposureFusion +----------- +Fuses a bracketed exposure sequence into a single image without converting to HDR first. + +"Exposure Fusion", Mertens et al., 2007 + +.. ocv:function:: exposureFusion(InputArrayOfArrays src_imgs, OutputArray dst, bool align = false, float wc = 1, float ws = 1, float we = 0) + + :param src_imgs: vector of 8-bit 3-channel images + + :param dst: output image. Although it's a floating-point image tonemapping is not necessary. + + :param align: if true, images are first aligned using median threshold bitmap algorithm. See :ocv:func:`getExpShift`. + + :param wc: contrast factor weight + + :param ws: saturation factor weight + + :param we: well-exposedness factor weight + +getExpShift +----------- +Calculates translation vector that can be used to align img1 with img0. +Uses median threshold bitmap algorithm by Ward. + +"Fast, Robust Image Registration for Compositing High Dynamic Range Photographs from Handheld Exposures", Ward, 2003 + +.. ocv:function:: getExpShift(InputArray img0, InputArray img1, int max_bits = 6, int exclude_range = 4) + + :param img0: 8-bit 1-channel image + + :param img1: 8-bit 1-channel image + + :param max_bits: logarithm to the base 2 of maximal shift in each dimension + + :param exclude_range: range value for exclusion bitmap. Refer to the article. + +shiftMat +----------- +Shifts image filling the new regions with zeros. + +.. ocv:function:: shiftMat(InputArray src, Point shift, OutputArray dst) + + :param src: input image + + :param shift: shift vector + + :param dst: output image \ No newline at end of file diff --git a/modules/photo/doc/photo.rst b/modules/photo/doc/photo.rst index fa2aa1e..c8aefda 100644 --- a/modules/photo/doc/photo.rst +++ b/modules/photo/doc/photo.rst @@ -9,3 +9,4 @@ photo. Computational Photography inpainting denoising + hdr_imaging \ No newline at end of file diff --git a/modules/photo/src/align.cpp b/modules/photo/src/align.cpp index 3c2ba26..6caa191 100644 --- a/modules/photo/src/align.cpp +++ b/modules/photo/src/align.cpp @@ -102,9 +102,6 @@ static void computeBitmaps(Mat& img, Mat& tb, Mat& eb, int exclude_range) void shiftMat(InputArray _src, Point shift, OutputArray _dst) { Mat src = _src.getMat(); - if(src.depth() != CV_8U) { - CV_Error(Error::StsBadArg, "Image must have CV_8U depth."); - } _dst.create(src.size(), src.type()); Mat dst = _dst.getMat(); -- 2.7.4