Markov Random Field for Image Segmentation
- Free software: MIT license
- Documentation: https://markov-random-field.readthedocs.io.
For a given grayscale image 'image_array', you do the followimg:
import markov_random_field.markov_random_field hmrf = markov_random_field.markov_random_field.HiddenMarkovRandomField(n_classes=4) pixel_level_classified_image_array = hmrf.fit(grayscale)
That's it.
- TODO
- Sort class labels by pixel means (0 for smallest, n for largest).
- This package borrows almost everything from this repository:
- https://github.com/lucananni93/Hidden-Markov-Random-Fields/blob/master/image_segmentation/main.py
I made small QoL improvements (using scipy.signal.convolve2d instead of iterating through all the pixels to make this faster).
As a small benchmark, an image of size (14930, 20226) with 4 classes takes 20m 40.7s to run on a cluster with 20 cores and 100 GB of RAM. It probably required nowhere near that amount of memory to run, however your mileage will vary.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.