I have an image of different colored particles (red, green, and yellow) that are all mixed up against a black background. I am interested in knowing what color each particle has for its neighbor (if any). Because some particles severely overlap and merge into large blobs, I cannot easily define particles with segmentation analysis. But this is okay, I am more interested in looking at neighbors by color, not by individual particle. Specifically, I want to ask what is the distribution of colors that any given color is touching (i.e. not separated by black pixels).
For analysis, rather than defining specific areas of interest, I was thinking about using a grid approach that would sample the whole image. First, overlay a grid onto the image, with each unit of the grid approximating the size of a particle. Then I would like to have a way so that each grid can report what % of color is in the area of each grid unit. In the end, I would get a distribution for what colors are in each grid unit. Each grid could then be compiled for analysis.
So far, I have separated the channels, binarized the channel, and then pseudo colored back the original color so that everything is equal in terms of intensity. But I need some help to go from here. Any help would be greatly appreciated.
Unfortunately due to unexpected server maintenance my stored images are not accessible at this moment. I've mocked up an image that should suffice. [![mock up test image]]
This will partition the image into the approximate size of one particle.
Perhaps the pixel colors for each square's border can be defined into a matrix that will produce a quantitative distribution for the image?
----update jun 7----
After Wjx's helpful responses and trying out more things, I would like to rephrase and simplify my question.
After the ImagePartition step, I would like to assess each square to know how many colors are in each individual square. As Wjx mentioned earlier, the DominantColors function could be used. For example, taking one square from my mock up partition that has red, green, and yellow (with no black background) and applying the DominantColors function yields Red, Green, and Yellow. Doing the same for one square with just green and black background yields Green and Black.
I have decided that this type of information is sufficient for my needs. So, instead of the neighbor-correlation approach, what I'd like to do is have each square of the partitioned image be analyzed with the DominantColors function.
Then, I'd like to classify each individual square based on its DominantColor result so that each square can be binned into a category. The final result for the image would then be # of squares in each category so that a distribution could be produced.
The Categories would be as follows:
- "Negatives" - All black
- "Red" - All red (as well as any that are red AND black)
- "Green" - All green (as well as any that are green AND black)
- "Mixed" - any combination of the 3 colors (i.e. R+G, R+Y, G+Y, R+G+Y+, and again, of course black is allowed in any of the combinations also since it is the background).
Hopefully this is a clearer question and should be straightforward code wise. But I still need help putting all the code together. thank you!
-------Update Jun 9--------
@shrx - here is my code for my "pre-processing" of the colors.
i= image imgR = ColorSeparate[i, "R"]; imgG = ColorSeparate[i, "G"]; imgRB = Binarize[imgR]; imgRc = ColorReplace[imgRB, White -> Red]; imgGB = Binarize[imgG]; imgGc = ColorReplace[imgGB, White -> Green]; ImageAdd[imgRc, imgGc]
final output image (cannot post because I am at limit for links since I am new)