- A lib can be used to segment image https://pypi.org/project/segment-image/
- The first version just has k_means algorithm.
- python >= 3.6
- install
$ pip install segment-image
-
cv2
need to be installed bypip install opencv-python
-
Kmeans
import segment_image
import cv2
img = cv2.imread("./sample_imgs/lena.png")
k = 2 # number of segments
k_means = segment_image.Kmeans(img, k)
iteration = 10
convergence_radius = 1e-6
k_means.run(iteration, convergence_radius)
- gvf_snake (The speed is so slow, so I use small
max_iteration_gvf
andmax_iteration_gvf
. if you want to get great results, pleas adjust them)
import segment_image
import cv2
img = cv2.imread("./sample_imgs/star.png")
max_iteration_gvf = 10
max_iteration_snake = 10
gvf_snake = segment_image.GVFSnake(img, max_iteration_gvf, max_iteration_snake)
gvf_snake.run(save=True)