A
A
Adminx12021-08-08 23:38:06
Python
Adminx1, 2021-08-08 23:38:06

How to reduce color range in python photo?

Good afternoon, the question is how to implement image processing in python, where you will need to convert the input image (jpg,png) into groups of colors up to 24. At the output, I want to get a vector image with 24 colors in .ai format, how can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-08-09
@Vindicar

As for reducing the number of colors, I can suggest one idea.
You collect a collection of all the colors in the image. It will be a kind of point cloud in RGB coordinate space. You can either take all pixels or just unique colors - see what works best.
Then you apply the k-means method to break this cloud into the desired number of clusters. Implementations of the k-means method can be found in the opencv-python (aka cv2) package, along with the bitmap loading mechanics.
You will get a set of 24 points - the centers of the clusters. These will be the final colors, just round their RGB coordinates to the nearest integer.
Then, for each pixel in the image, you find the center of the cluster closest to its color. This will be the color that will need to recolor the pixel.
I'm rather interested in how you are going to turn a raster image into a vector one - this is a non-trivial thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question