-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvs_color_adjust.h
75 lines (59 loc) · 2.89 KB
/
vs_color_adjust.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Copyright (c) 2016-2023 shuyuanmao <[email protected]>. All rights reserved.
* @author shuyuanmao <[email protected]>
* @date 2022-03-04 11:37
* @details Adjust image color style to reference image style, such as: histogram matching, color statistic matching.
*/
#pragma once
#include <memory>
#include <opencv2/imgproc.hpp>
namespace vs {
class ColorAdjustor {
public:
typedef std::vector<std::vector<uchar>> LutType; ///< 1x256 or 3x256
struct Config {
bool input_rgb = false; ///< input image color order, true: R-G-B, false: B-G-R
cv::Size process_ref_size = cv::Size(100, 100); ///< max size to compute histogram/statistics from reference image
cv::Size process_src_size = cv::Size(100, 100); ///< max size to compute histogram/statistics from source image
bool adjust_mask_area_only = false; ///< only adjust mask rect area of ajusted image, other will be fill with 0
int resize_interpolation_type = cv::INTER_NEAREST; ///< parameter for resizing reference/source image
bool use_prior_skin_hist = false; ///< use prior skin histogram. Only used in COLOR_ADJUSTOR_HISTOGRAM_MATCH
};
ColorAdjustor() {}
explicit ColorAdjustor(const Config& cfg) : m_cfg(cfg) {}
virtual ~ColorAdjustor() {}
/** @brief init reference image for color adjustment
* @param[in]ref_img: reference image
* @return whether init ok
*/
virtual bool init(const cv::Mat& ref_img) = 0;
/** @brief adjust color of input image with reference to init reference image
* @param[in]src_img: source image to be adjust
* @param[in]adjust_rate: adjust rate, range [0,1]
* @param[in]src_mask: source mask
* @return adjust image which is same size as src_img
*/
virtual cv::Mat adjust(const cv::Mat& src_img, float adjust_rate = 0.5, const cv::Mat& src_mask = cv::Mat());
/** @brief adjust color of input image with reference to init reference image
* @param[in]src_img: source image to be adjust
* @param[in]adjust_rate: adjust rate, range [0,1]
* @param[in]src_mask: source mask
* @return LUT nchannelx256
*/
virtual LutType calcAdjustLut(const cv::Mat& src_img, float adjust_rate = 0.5,
const cv::Mat& src_mask = cv::Mat()) = 0;
/** @brief set configuration */
void setConfig(const Config& cfg) { m_cfg = cfg; }
/** @brief get configuration */
Config getConfig() const { return m_cfg; }
protected:
Config m_cfg; ///< cofiguration parameters
/** @brief downsample image into max size */
cv::Mat downsampleImg(const cv::Mat& img, const cv::Size& max_size);
};
enum ColorAdjustorType {
COLOR_ADJUSTOR_HISTOGRAM_MATCH = 0, ///< color adjustment with histogram matching
COLOR_ADJUSTOR_STATISTIC_MATCH = 1, ///< color adjustment with image statistic matching
};
std::shared_ptr<ColorAdjustor> createColorAdjustor(ColorAdjustorType type = COLOR_ADJUSTOR_HISTOGRAM_MATCH);
} // namespace vs