A function can be thought of as a black box, which produces output results when fed with proper inputs. We have already used several ready-made functions so far, but we haven't made any functions of our own. The biggest advantage of making our own functions is that we can reuse them with different inputs to produce different results, as opposed to scripts where inputs must usually be changed by altering and resaving the source code.
To begin, let's attempt to mix all the aforementioned enhancement methods in a single function that will accept the choice of method from the input. More specifically, we will make a function that will take two inputs; an image and a number. The image will be enhanced using the method denoted by the number. After opening the Editor, we type in the following code:
function [output] = ContrastEnhancement(input,method) % Function that performs image contrast enhancement with methods % incorporated in MATLAB toolboxes % Inputs: ...