Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Processing and clustering colors from images presents some challenges:
Image.quantize
, on the other hand, make the colors sample too coarse.scikit-learn
's KMeans
handle some of these challenges, but are non-deterministic and not flexible in the ways that I'd like.Average similar colors. Specifically, this maps an 8-bit color space to an n-bit color space then averages colors in each bin. An argument, nbits
, specifies the number of bits to use for each color channel. The default is 6, which reduces 17-million-ish possible colors to 300-thousand-ish possible colors. The downside is that the boundaries between n-bit bins are arbitrary. Heavy concentrations of near-identical colors will be split if a boundary passes through them.
Pooling colors from an image path will write a cache to your temp directory.
Reduce the number of colors by recursively splitting the color space along the longest axis. This is a median cut algorithm, but it's not constrained to x, y, or z axes. The longest axis is determined by the standard deviation of the colors in the cluster. I've made the cut just a little bit smarter than standard median cut, but this is essentially k-medoids without the re-distribution step, so it's more efficient, but not the best we can do. An argument, num
, specifies the number of colors to reduce to. 512 is a good number, but if you're still missing some nuance, you can increase it.
delta(a,a)
is 0 and delta(a,b)
is never 0. Common choices are Euclidean, squared Euclidean, and delta-e.Divisive clustering is typically better for, "What are the five dominant colors in this image?"
Agglomerative clustering is typically better for, "How many colors do I need to represent this image with no more than delta==3
between any two cluster members?"
pip install cluster_colors
from cluster_colors import get_image_clusters
# find the five most dominant colors in an image
clusters = get_image_clusters(image_filename)
clusters.split_to_n(5)
exemplars = clusters.get_as_vectors()
# to save the cluster exemplars as an image file
show_clusters(split_clusters, "open_file_to_see_clusters")
FAQs
Cluster rgb vectors with divisive kmedians
We found that cluster-colors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.