locatecolorcluster


Namelocatecolorcluster JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/locatecolorcluster
SummaryLightning-fast image color clustering with C-based RGB localization/euclidean distance calculation. Supports DBSCAN/HDBSCAN, Shapely geometry.
upload_time2023-11-14 04:43:23
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords dbscan hdbscan euclidean
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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.

![](https://avatars.githubusercontent.com/u/77182807?s=400&u=b3398787384abf38d62c6f080195550df64f3990&v=4)
![](https://github.com/hansalemaos/screenshots/blob/main/colorcluster/0.png?raw=true)
![](https://github.com/hansalemaos/screenshots/blob/main/colorcluster/1.png?raw=true)

```python
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)



```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/locatecolorcluster",
    "name": "locatecolorcluster",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "DBSCAN,HDBSCAN,euclidean",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/72/2a/2507c978a79038ec9ccb5ed83bf72a47ac13badeefd5563bdb60ac8c6c2a/locatecolorcluster-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Lightning-fast image color clustering with C-based RGB localization/euclidean distance calculation. Supports DBSCAN/HDBSCAN, Shapely geometry. \r\n\r\n## pip install locatecolorcluster\r\n\r\n### Tested against Python 3.11 / Windows 10\r\n\r\n## Important: A C/\u0003C++ compiler is necessary!\r\n\r\n## Advantages:\r\n\r\n\r\n### Flexibility:\r\n\r\nThe module supports both DBSCAN and HDBSCAN clustering algorithms, allowing users to choose the method that best fits their needs.\r\n\r\n\r\n### Parallelization:\r\n\r\nThe code leverages parallelization capabilities in clustering algorithms, specifically in DBSCAN, HDBSCAN and cythoneuclideandistance, by allowing users to specify the number of parallel jobs.\r\n\r\n\r\n### Speed Optimization:\r\n\r\nThe 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.\r\n\r\n\r\n### RGB Localization with C:\r\n\r\nThe 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.\r\n\r\n\r\n### Visualization:\r\n\r\nThe 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.\r\n\r\n\r\n### Shapely Geometry:\r\n\r\nThe module provides Shapely geometry information for each cluster, offering additional insights into the spatial characteristics of the clusters.\r\n\r\n![](https://avatars.githubusercontent.com/u/77182807?s=400&u=b3398787384abf38d62c6f080195550df64f3990&v=4)\r\n![](https://github.com/hansalemaos/screenshots/blob/main/colorcluster/0.png?raw=true)\r\n![](https://github.com/hansalemaos/screenshots/blob/main/colorcluster/1.png?raw=true)\r\n\r\n```python\r\nDependencies:\r\n\t- Cython and a C/C++ compiler!\r\n\t- os.path\r\n\t- sys\r\n\t- cv2\r\n\t- scipy.spatial.distance.pdist, squareform\r\n\t- cythoneuclideandistance\r\n\t- a_cv_imwrite_imread_plus\r\n\t- locate_pixelcolor_c\r\n\t- numpy\r\n\t- shapely.geometry\r\n\t- sklearn.cluster.DBSCAN, HDBSCAN\r\n\t- numexpr\r\n\t- a_cv2_easy_resize\r\n\r\nUsage:\r\n\t- Create an instance of ColorCluster by providing an image path, optional parameters for resizing,\r\n\t  and interpolation method.\r\n\t- Use the find_colors method to search for specific colors in the image.\r\n\t- Calculate the Euclidean distance matrix using the calculate_euclidean_matrix method with the desired backend.\r\n\t- Apply clustering algorithms (DBSCAN or HDBSCAN) using the get_dbscan_labels or get_hdbscan_labels methods.\r\n\t- Extract clusters and visualize results using get_clusters, draw_results, and draw_results_real_size methods.\r\n\t- Obtain Shapely geometry information for each cluster using get_shapely method.\r\n\r\nExample:\r\n\r\n\timport cv2\r\n\r\n\tfrom locatecolorcluster import ColorCluster, get_range_of_colors\r\n\t# Some valid color inputs\r\n\tcolors = get_range_of_colors(\r\n\t\tstart=(0, 0, 0),\r\n\t\tend=(10, 10, 10),\r\n\t\trgb_or_bgr=\"bgr\",\r\n\t\tmin_r=0,\r\n\t\tmax_r=10,\r\n\t\tmin_g=0,\r\n\t\tmax_g=10,\r\n\t\tmin_b=0,\r\n\t\tmax_b=10,\r\n\t)\r\n\tcolors = ((0, 0, 0),)\r\n\tcolors = get_range_of_colors(\r\n\t\tstart=(100, 0, 0),\r\n\t\tend=(255, 0, 0),\r\n\t\trgb_or_bgr=\"bgr\",\r\n\t\tmin_r=100,\r\n\t\tmax_r=255,\r\n\t\tmin_g=0,\r\n\t\tmax_g=10,\r\n\t\tmin_b=0,\r\n\t\tmax_b=10,\r\n\t)\r\n\tcbackend = (\r\n\t\tColorCluster(\r\n\t\t\timg=r'https://avatars.githubusercontent.com/u/77182807?s=400&u=b3398787384abf38d62c6f080195550df64f3990&v=4',\r\n\t\t\tmax_width=200,\r\n\t\t\tmax_height=200,\r\n\t\t\tinterpolation=cv2.INTER_NEAREST,\r\n\t\t)\r\n\t\t.find_colors(colors=colors, reverse_colors=False)\r\n\t\t.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\r\n\t\t.get_dbscan_labels(eps=3, min_samples=10, algorithm=\"auto\", leaf_size=30, n_jobs=5)\r\n\t\t.get_clusters()\r\n\t\t.draw_results(folder=r\"C:\\myimageresults\\1\", color=(255, 0, 255))\r\n\t\t.draw_results_real_size(folder=r\"C:\\myimageresults\\2\", color=(255, 255, 0))\r\n\t\t.get_shapely()\r\n\t)\r\n\tshapelydata = cbackend.shapelydata\r\n\tprint(shapelydata)\r\n\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lightning-fast image color clustering with C-based RGB localization/euclidean distance calculation. Supports DBSCAN/HDBSCAN, Shapely geometry.",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/locatecolorcluster"
    },
    "split_keywords": [
        "dbscan",
        "hdbscan",
        "euclidean"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "866255c18ab7db7c136ab84c12d8d6b5a0c5ecac111dd89423d5e07225407325",
                "md5": "4872efe395f09d91a796537f9f6c07a6",
                "sha256": "5f390b32aa01b91f46116244aa8c5187665c07c77937f434f352f72c1a841071"
            },
            "downloads": -1,
            "filename": "locatecolorcluster-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4872efe395f09d91a796537f9f6c07a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 76782,
            "upload_time": "2023-11-14T04:43:21",
            "upload_time_iso_8601": "2023-11-14T04:43:21.484887Z",
            "url": "https://files.pythonhosted.org/packages/86/62/55c18ab7db7c136ab84c12d8d6b5a0c5ecac111dd89423d5e07225407325/locatecolorcluster-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "722a2507c978a79038ec9ccb5ed83bf72a47ac13badeefd5563bdb60ac8c6c2a",
                "md5": "08ef7efe5cc3568762abcfe91ccd641c",
                "sha256": "9923089dd8accb1377e2e3e1b01e5df4f6d6bc85412a900da44fc25599730071"
            },
            "downloads": -1,
            "filename": "locatecolorcluster-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "08ef7efe5cc3568762abcfe91ccd641c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 75854,
            "upload_time": "2023-11-14T04:43:23",
            "upload_time_iso_8601": "2023-11-14T04:43:23.810205Z",
            "url": "https://files.pythonhosted.org/packages/72/2a/2507c978a79038ec9ccb5ed83bf72a47ac13badeefd5563bdb60ac8c6c2a/locatecolorcluster-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-14 04:43:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "locatecolorcluster",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "locatecolorcluster"
}
        
Elapsed time: 0.19266s