miiB_miiB
miiB_miiB

Reputation: 11

Convent dominant color to color name

How can I convert a dominant color into a color name?

This Method is find dominant color from image.

private void extractProminentColors(Bitmap bitmap){
        int defaultColor = 0x000000;
        Palette p = Palette.from(bitmap).generate();
        int VibrantColor = p.getVibrantColor(defaultColor);
        v1 = String.format("#%X", VibrantColor);
        colorv1 = v1;
        checkBox1.setBackgroundColor(VibrantColor);
        int MutedColorLight = p.getLightMutedColor(defaultColor);

        v2 = String.format("#%X", MutedColorLight);
        colorv2 = v2;
        checkBox2.setBackgroundColor(MutedColorLight);
        int MutedColorDark = p.getDarkMutedColor(defaultColor);

        v3 = String.format("#%X", MutedColorDark);
        colorv3 = v3;
        checkBox3.setBackgroundColor(MutedColorDark);
    }

and this is ArrayList of color name

final ArrayList<ColorName> colorList = new ArrayList<ColorName>();
    colorList.add(new ColorName("Black", 0x00, 0x00, 0x00)); 
    colorList.add(new ColorName("White", 0xff, 0xff, 0xff)); 
    colorList.add(new ColorName("Gray", 0x80, 0x80, 0x80)); 
    colorList.add(new ColorName("Navy" , 0x00, 0x00, 0x80)); 
    colorList.add(new ColorName("Red", 0xff, 0x00, 0x00)); 
    colorList.add(new ColorName("Orange", 0xff, 0x80, 0x00)); 
    colorList.add(new ColorName("Yellow", 0xff, 0xff, 0x00)); 
    colorList.add(new ColorName("Green", 0x00, 0xff, 0x00)); 
    colorList.add(new ColorName("Blue", 0x00, 0x00, 0xff)); 

Upvotes: 1

Views: 92

Answers (2)

kallaballa
kallaballa

Reputation: 377

If you are looking for a command-line tool that does exactly that: Cict

Example:

$ ./cict 000081
1   #000080 navyblue

As you can see, you simple pass a 24-bit hex-value to cict and it reports the distance to the color found (1 in this case), the value of the actual color (#000080) and the name (navyblue).

(I am the author of Cict)

Upvotes: 0

Ralf Kleberhoff
Ralf Kleberhoff

Reputation: 7290

As the dominant colors in the image most probably don't exactly match the listed named colors, you can only find the closest named color.

Write a distance() method that calculates how much two colors differ, and in the colorNames list, search for the entry where the distance to the dominant color is minimal.

Upvotes: 1

Related Questions