Here we are using k-means clustering to cluster (x,y,r,g,b)
values. This creates an image segmentation effect.
Usage:
from kmeans import *
kmeans(filepath, k, wx = 1.0, wy = 1.0, outdir = None)
Arguments:
filepath
- The file path of the image to apply the k-means effect.k
- The number of means/clusters.wx
- A weight on the x values. Higher values will make it cluster along the x-axis.wy
- A weight on the y values. Higher values will make it cluster along the y-axis.outdir
- The file path to the output directory.
from kmeans import *
# read from input/nagano_train_960x720.jpeg
kmeans(readpath, 5, 0.5, 0.5, outpath)
from kmeans import *
# read from input/kurohime_bike_1920x1080.jpeg
kmeans(readpath, 50, 3.0, 1.0, outpath)
from kmeans import *
# read from input/flower_1856x1392.jpeg
kmeans(readpath, 16, 5.0, 5.0, outpath)
from kmeans import *
# read from input/kurohime_bike_1920x1080.jpeg
kmeans(readpath, 50, 3.0, 3.0, outpath)
from kmeans import *
# read from input/nagano_train_960x720.jpeg
kmeans(readpath, 100, 4.0, 4.0, outpath)
from kmeans import *
# read from input/kurohime_bike_960x540.jpeg
kmeans(readpath, 100, 4.0, 4.0, outpath)