# Towards Automatic Image Enhancement with Genetic Programming and Machine Learning
## 3 The Proposed Approach
### Genetic Programming Engine--ELAINE  
The analysis of the related work and preliminary work with the implemented filters showed that individually the filters can perform well under the right conditions but may struggle with versatility, i.e., input images under different conditions may require adjustments on parameters. Moreover, it is clear that applying different filters sequentially can produce unique results and that slight adjustments in the order of the filters may cause significant changes to the output. Furthermore, some images may require the application of one or two filters, depending on different conditions. The need for more filters led us to conclude that, for automatic IE, we need to find a generic pipeline for the application of image filters suitable to different input images. Contemplating these insights, a way to automatically generate pipelines that compute image filters applied to the input images was developed. We opted for GP using a tree representation since the problem inherently can be viewed as a program, a succession of steps and decisions of what filters should be applied on the input image and by what order. GP provides us with a representation suitable for exploring solutions in a structured and flexible way, with variation operators well-defined and adaptable to our problem. Thus, the system developed was later named ELAINE (EvoLutionAry Image eNhancEment), a GP engine that allows the evolution of image enhancement pipelines based on pre-defined image filters. Making use of GP requires the definition of the primitives and terminals that will be available to the population during the evolution. The scenario presented wants to evolve a sequence of filter functions that generally receive at least an image and a numeric value as input, i.e., the filter's parameters. We defined a primitive set containing all the seven Classical functions previously implemented, a terminal set containing the input image, and _ephemeral constants_ ranging from \(-1\) to \(1\). Each function then mapped the defined range in order to adapt it to the desired magnitude. Each function parameter range was empirically defined so that the function provided acceptable results. Additionally, we introduced an \"_if-then-else_\" function that, depending on the boolean value of a condition, returns the output of the \"_then_ tree\" or the \"_else_ tree\", allowing the same program solution to behave differently according to the input characteristics. Since one of the primitives is the whole image, it required values that could be used for comparison to make conditionals. To make this possible, a set of \"conditional functions\" were introduced. Thus, we added to the primitive set five functions that extracted relevant features from the image. The features are image-related features that capture characteristics of the perceived quality of the image: noise, contrast, saturation, brightness, and sharpness. To extract the noise, we used the work proposed in Reference [22] to estimate the images Gaussian noise quickly. For contrast, the _RMS_ contrast [23] was calculated, meaning standard deviation of pixel intensities. For saturation, we averaged the pixels' intensity in the \(S\) channel of the _HSV_ color system. For brightness, the _HSP_ color system was used [24], as it grants a brightness value closer to the real human perception when compared to the Luminance (L) channel of the _HSL_ or the value (V) channel from the _HSV_. We then averaged the perceived brightness (P) channel to obtain a final value. Finally, for sharpness, we applied a Laplacian filter, calculated the variance of the output, and used that as a sharpness score, as proposed in Reference [25]. All functions were adapted to expect an image as input and an ephemeral constant, which serves as a threshold for that condition. Figure 3 shows a graphical example of a possible individual. The entire implementation was performed using _DEAP_[26] for Python as the base Evolutionary engine.