Skip to main content

Lightning-fast image color clustering with C-based RGB localization/euclidean distance calculation. Supports DBSCAN/HDBSCAN, Shapely geometry.

pip install locatecolorcluster

Tested against Python 3.11 / Windows 10

Important: A C/C++ compiler is necessary!

Advantages:

Flexibility:

The module supports both DBSCAN and HDBSCAN clustering algorithms, allowing users to choose the method that best fits their needs.

Parallelization:

The code leverages parallelization capabilities in clustering algorithms, specifically in DBSCAN, HDBSCAN and cythoneuclideandistance, by allowing users to specify the number of parallel jobs.

Speed Optimization:

The module exhibits exceptional speed, outperforming standard libraries like SciPy in Euclidean distance calculations by a factor of four. This performance boost is crucial for large-scale image processing tasks.

RGB Localization with C:

The module includes efficient C implementations for RGB localization (300x faster than Python - search_colors method), enhancing the speed and accuracy of color identification in images.

Visualization:

The module includes methods (draw_results and draw_results_real_size) for visualizing the clustered results, making it easier for users to interpret and analyze the outcomes.

Shapely Geometry:

The module provides Shapely geometry information for each cluster, offering additional insights into the spatial characteristics of the clusters.

Dependencies:
	- Cython and a C/C++ compiler!
	- os.path
	- sys
	- cv2
	- scipy.spatial.distance.pdist, squareform
	- cythoneuclideandistance
	- a_cv_imwrite_imread_plus
	- locate_pixelcolor_c
	- numpy
	- shapely.geometry
	- sklearn.cluster.DBSCAN, HDBSCAN
	- numexpr
	- a_cv2_easy_resize

Usage:
	- Create an instance of ColorCluster by providing an image path, optional parameters for resizing,
	  and interpolation method.
	- Use the find_colors method to search for specific colors in the image.
	- Calculate the Euclidean distance matrix using the calculate_euclidean_matrix method with the desired backend.
	- Apply clustering algorithms (DBSCAN or HDBSCAN) using the get_dbscan_labels or get_hdbscan_labels methods.
	- Extract clusters and visualize results using get_clusters, draw_results, and draw_results_real_size methods.
	- Obtain Shapely geometry information for each cluster using get_shapely method.

Example:

	import cv2

	from locatecolorcluster import ColorCluster, get_range_of_colors
	# Some valid color inputs
	colors = get_range_of_colors(
		start=(0, 0, 0),
		end=(10, 10, 10),
		rgb_or_bgr="bgr",
		min_r=0,
		max_r=10,
		min_g=0,
		max_g=10,
		min_b=0,
		max_b=10,
	)
	colors = ((0, 0, 0),)
	colors = get_range_of_colors(
		start=(100, 0, 0),
		end=(255, 0, 0),
		rgb_or_bgr="bgr",
		min_r=100,
		max_r=255,
		min_g=0,
		max_g=10,
		min_b=0,
		max_b=10,
	)
	cbackend = (
		ColorCluster(
			img=r'https://avatars.githubusercontent.com/u/77182807?s=400&u=b3398787384abf38d62c6f080195550df64f3990&v=4',
			max_width=200,
			max_height=200,
			interpolation=cv2.INTER_NEAREST,
		)
		.find_colors(colors=colors, reverse_colors=False)
		.calculate_euclidean_matrix(backend="C", memorylimit_mb=10000) # Define a memory limit for the C backend - It's 4x faster than scipy, but if the array is too big for the memory, the process crashes with 0xc0000005
		.get_dbscan_labels(eps=3, min_samples=10, algorithm="auto", leaf_size=30, n_jobs=5)
		.get_clusters()
		.draw_results(folder=r"C:\myimageresults\1", color=(255, 0, 255))
		.draw_results_real_size(folder=r"C:\myimageresults\2", color=(255, 255, 0))
		.get_shapely()
	)
	shapelydata = cbackend.shapelydata
	print(shapelydata)

Metadata

Release files for locatecolorcluster 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for locatecolorcluster 0.10
File Size Uploaded Provenance Actions
locatecolorcluster-0.10.tar.gz 75.9 kB Without provenance Details for locatecolorcluster-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for locatecolorcluster 0.10
File Interpreter ABI Platform Actions
locatecolorcluster-0.10-py3-none-any.whl Python 3 none any Details for locatecolorcluster-0.10-py3-none-any.whl

Total release size: 152.6 kB

Release files / locatecolorcluster-0.10.tar.gz

Download URL locatecolorcluster-0.10.tar.gz
Size 75.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9923089dd8accb1377e2e3e1b01e5df4f6d6bc85412a900da44fc25599730071
BLAKE2b-256 checksum
How to use checksums
722a2507c978a79038ec9ccb5ed83bf72a47ac13badeefd5563bdb60ac8c6c2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / locatecolorcluster-0.10-py3-none-any.whl

Download URL locatecolorcluster-0.10-py3-none-any.whl
Size 76.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f390b32aa01b91f46116244aa8c5187665c07c77937f434f352f72c1a841071
BLAKE2b-256 checksum
How to use checksums
866255c18ab7db7c136ab84c12d8d6b5a0c5ecac111dd89423d5e07225407325
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for locatecolorcluster 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page