# Hello, I would like to segment some images based on some conditions, Could you help me with that?

Hello I have an image that i got after performing clustering for 5 colors. Now there are only 5 colors present in the image. Suppose the colors are (100, 150, 200), (200, 250, 100), (50, 150, 200), (100, 250, 100), (0, 100, 200).

Now I want to split the image into chunks. Each chunks will have some percentage of the pixels of all the 5 colors. Say 20% pixels are of color A and 30% pixels are of color B and so on.

How do I split the image this way?

Example: This is the input image:

This should be the output image:

Each chunk has to have all the clustering colors (i.e. 5 if we use the example above) colors present in the image in it.

edit retag close merge delete

yea, you can do something with some algorithm, and you'll get some result ;(

( 2020-02-06 08:33:31 -0500 )edit

haha .. I was filled with joy when I saw your comment. But then realized something XD

( 2020-02-06 08:46:29 -0500 )edit

your output image looks more like you want spacial segmentation, like e.g. SLIC

( 2020-02-06 08:56:00 -0500 )edit

I just want to group the pixels in such a way that each group will have all the 5 colours

( 2020-02-06 09:09:09 -0500 )edit

What do you mean 5 colors? It looks like an exercise Image histogram is more than 5 colours. Take 5 random pixels and you get regions with 5 colors

use kmean before?

( 2020-02-06 09:29:45 -0500 )edit

Yes, i did a kmeans on the original image where k = 5.. this way i made sure i get an image with 5 colours only.. now i want this new image as input in some kind of algorithm that will help me to come up with chunks of image. Each chunk should contain all the 5 colours

( 2020-02-06 10:36:06 -0500 )edit

Yes, i did a kmeans on the original image where k = 5.. this way i made sure i get an image with 5 colors only

Well if you found 5 centroids you have found 5 dominant colors and also their cluster(area) within the whole image. These cluster dont overlap. "Kmeans algorithm is an iterative algorithm that tries to partition the dataset into Kpre-defined distinct non-overlapping subgroups (clusters)". So you divided the image into distinct areas but at same time you are asking where these area overlap(Each chunk should contain all the 5 colours).

My suggestion. Use contours or similar approach to find areas within the image.I think this is what berak was suggesting with "spacial segmentation". Then run kmeans with k5 on these areas so you get clusters with dominant colors

( 2020-02-06 15:20:06 -0500 )edit

And then check if centroids suffice your criteria. If so - measure the cluster area. If each cluster is sufficiant dominant (maybe like 10% of the whole contours area) - you found your area. I hope this make sense. @berak can you comment on this?

( 2020-02-06 15:23:33 -0500 )edit

@tsabbir96 -- it would be helpful, if you could explain, why you need this, and what for.

@holger -- the image reminded me of superpixels, but those have no guarantee, that all 5 dominant colors are present

( 2020-02-06 16:06:49 -0500 )edit

@holger@berak sorry guys, I would have upvoted you. But I guess I need 5 points to do that.. Thanks a lot for your suggestion. Definitely will test the idea.

( 2020-02-07 04:31:58 -0500 )edit