Skip to main content

Python package clustimage is for unsupervised clustering of images.

Project description

clustimage

Python PyPI Version License Github Forks GitHub Open Issues Project Status Sphinx Downloads Downloads BuyMeCoffee

  • clustimage is a python package for unsupervised clustering of images.

Installation

  • Install clustimage from PyPI (recommended). clustimage is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.
  • A new environment can be created as following:
conda create -n env_clustimage python=3.8
conda activate env_clustimage
  • Install from pypi
pip install -U clustimage

Import the clustimage package

from clustimage import Clustimage

Simple example using data-array as an input.

# Load library
import matplotlib.pyplot as plt
from clustimage import Clustimage
# init
cl = Clustimage()
# Load example digit data
X = cl.import_example(data='digits')

print(X)
# Each row is an image that can be plotted after reshaping:
plt.imshow(X[0,:].reshape(8,8), cmap='binary')
# array([[ 0.,  0.,  5., ...,  0.,  0.,  0.],
#        [ 0.,  0.,  0., ..., 10.,  0.,  0.],
#        [ 0.,  0.,  0., ..., 16.,  9.,  0.],
#        ...,
#        [ 0.,  0.,  0., ...,  9.,  0.,  0.],
#        [ 0.,  0.,  0., ...,  4.,  0.,  0.],
#        [ 0.,  0.,  6., ...,  6.,  0.,  0.]])
# 
# Preprocessing and feature extraction
results = cl.fit_transform(X)

# Scatter
cl.scatter()
# Plot dendrogram
cl.dendrogram()
# Plot the clustered images
cl.plot(cmap='binary')

images with flowers to cluster.

# Load library
from clustimage import Clustimage
# init
cl = Clustimage(method='pca', embedding='tsne')
# load example with flowers
path_to_imgs = cl.import_example(data='flowers')
# Preprocessing and feature extraction
results = cl.fit_transform(path_to_imgs, min_clust=10)
# Scatter
cl.scatter(dot_size=50)
# Plot dendrogram
cl.dendrogram()
# Plot clustered images
cl.plot(ncols=5)

# Predict
results_predict = cl.predict(path_to_imgs[0:5], k=None, alpha=0.05)
cl.plot_predict()
cl.scatter()

Make prediction with unknown input image.

# Predict
results_predict = cl.predict(path_to_imgs[0:5], alpha=0.05)
cl.plot_predict()
cl.scatter()

Make prediction with unknown input image.

from clustimage import Clustimage
# Init
cl = Clustimage(method='pca', grayscale=True, params_pca={'n_components':14})
# Load example with faces
pathnames = cl.import_example(data='faces')
# Detect faces
face_results = cl.detect_faces(pathnames)
# Cluster
results = cl.fit_transform(face_results['facepath'])

# Plot faces
cl.plot_faces()
# Dendrogram depicts the clustering of the faces
cl.dendrogram()

# Make various other plots
cl.scatter()
# Make plot
cl.plot(ncols=2, show_hog=True)

References

Citation

Please cite in your publications if this is useful for your research (see citation).

Maintainers

Contribute

  • All kinds of contributions are welcome!
  • If you wish to buy me a Coffee for this work, it is very appreciated :)

Licence

See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clustimage-1.0.0.tar.gz (19.3 kB view hashes)

Uploaded Source

Built Distribution

clustimage-1.0.0-py3-none-any.whl (18.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page