We can use genetic algorithm to determine k-1 thresholds to obtain k segments of an image.
The process of segmentation of an image is similar to segmentation using otsu and multi otsu thresholding. However to determine the thresholds we use genetic algorithm.
It is suitable for grayscale image only.
- Define a initial population where a individual/state is k-1 thresholds for k segments.
- Define a fitness function
- Usually entropy function or variance function
- Measures the fitness of a individual thresholds
- Perform further steps of genetic algorithm using the above population and fitness function.
- The GA gives out a fittest individual i.e k-1 thresholds that maximizes the fitness function.
I used PyGAD to implement the Genetic Algorithm because it made easier to carry out this experiment.
- [ ] Improve fitness function
python main.py <img_path> <num_segments> <num_generation>
- They can be found on “./outputs”