Home

Awesome

Unity Prominent Color

This is a very simple tool to gather main colors of an image using Unity.

How to use

You will find a static class called ProminentColor. You can call GetColors32FromImage to get a List<Color32> or GetHexColorsFromImage to get a List<string> (of hex colors). Both of the methods will take these parameters:

nametypedescription
textureTexture2DTexture to get colors
maxColorAmountintThe max length of the list to be returned
colorLimiterPercentagefloatValue used to compare color amounts. If color amount percentage is less than this value, it will not be marked as valid color
toleranceUniteColorsintValue used to compare colors and unite them if is a match, useful to discard gradients
minimiumColorPercentagefloatValue used to remove colors that have lower amount percentage compared with full image

result image simple result, without much fine tunning

Removing the white (or any color) border

If your image has borders, you will probably have this color in the list. If you wish to remove this border, there is a helper in ProminentColor class called RemoveBorder, it returns the Texture2D without the border. This method take these parameters:

nametypedescription
textureTexture2DTexture to remove the border
compareColorColor32Color to be removed
tolerancefloatTolerance to compare the color to be removed

removing borders<br /> as you can see, there are small glitches, but white is not prominent anymore.