10. Code
- Walter Cheng
- Aug 17, 2019
- 3 min read
We used C++ as our main programming language, although the algorithm should work fine in multiple languages. Since OpenCV supports C++, Java and Python (also MatLab), these will be the best language in our opinions. However, if you can use those algorithm and function in other graphic library, the algorithm should work perfectly in those languages as well.
In the future, we might implement Python version and connect with a web-page so that usercan use it directly without any programming background, but now it is just the code. Here is the GitHub repo:
In this article, we would like to describe what each functions are doing in this script, so that user can modify the variables easier
void image_histogram(Mat src, Mat& dst, bool color, bool uniform, bool accumulate)
Generating the image histogram from the source image
src : source image that you would like to see the image histogram
dst : result image histogram image
color : whether the image histogram should have RGB three lines or in gray-scale one lime
uniform : whether the image histogram is uniform
accumulate : whether the image histogram is accumulate
void histogram_matching(Mat input, Mat ref, Mat& output)
Histogram matching between two images
input : source image for the histogram matching
ref : reference image for the image histogram
output : the result image after histogram matching
float getRatio(int index, float curve, float light, float offset, float height)
For getting the ratio between source image and the color picker
Variable details can be seen here:
index : ratio for the corresponding index, from 0 to 255
void drawRatio(float curve, float light, float offset, float height, char* filename)
For drawing the ratio into an image, using the value from getRatio()
filename : the name of the image file after drawn
void fillColor(Mat src, Mat ref, Mat col, Mat& dst, float curve, float light, float offset, float height)
Filling color according to the ratio, details here:
src : source image for the color you wanted to be filled
ref : source image after histogram matching, for reference on which color values
col : color picker image that generated from colorPickByMidPoint()
dst : result image
float getRatioByColor(int index, int midvalue, float darkness, float lightness)
Function to get the color picker value for colorPickByMidPoint()
index : color value for the corresponding index, from 0 to 255
midvalue : main theme color for the output color picker
darkness : determine how dark the darker value is
lightness : determine how bright the brighter value is
void colorPickByMidPoint(Mat& dst, int r, int g, int b, float darkness, float lightness)
Function to get the color picker from a main theme color
More information here:
dst : result image
r : red value of the main color
g : green value of the main color
b : blue value of the main color
darkness : determine how dark the darker value is
lightness : determine how bright the brighter value is
void drawRatio(int r, int g, int b, float darkness, float lightness, char* filename)
Different drawRatio function, for drawing the ratio by the color picker which you can see in
r : red value of the main color
g : green value of the main color
b : blue value of the main color
darkness : determine how dark the darker value is
lightness : determine how bright the brighter value is
filename : the name of the image file after drawn
Mat getAlpha(Mat markers, vector<vector<Point>> contours, int fst_index, int snd_index, float min, float max)
Getting the alpha value for different sections of the image using the distance transform method and normalization, more details here:
markers : markers for different sections in the image from getMarkers()
contours : contours for different sections in the image from getMarkers()
fst_index : starting index of the section
snd_index : ending index of the section
min : minimum value for the function normalize()
max : maximum value for the function normalize()
void getMarkers(Mat src, Mat& markers, vector<vector<Point>>& contours, float light, int section)
Getting markers for different sections in the image using the watershed algorithm
More details here:
src : source image
markers : output information that stores the markers
contours : output information that stores the contours
light : determine the size of the light source
section : determine the size of the section
void finalCombine(Mat ref1, Mat ref2, Mat dst1, Mat dst2, Mat markers, Mat& dst, bool noise)
Combining two colors together with their own alpha values by different sections
ref1 : first result image by fillColor()
ref2 : second result image by fillColor()
dst1 : first alpha image by getAlpha()
dst2 : second alpha image by getAlpha()
markers : markers to determine different sections from getMarkers()
dst : result image
noise : whether using the noise image or not



Comments