Search code examples
imageimage-processingcolorspixel

How can I extract all the hex color codes from a given image?


Is there any program or code that would allow me to get the color values for every single pixel of an image? Or a certain image file format that would make it easy to read them all through textpad or something similar


Solution

  • In ImageMagick, the txt: output format allows one to exact the pixel location and hex values. Using unix, tail and sed, I can return only those values (without the other color values) for the upper left corner 10x10 region of the ImageMagick internal image rose:. The colon is important for IM internal images. Just replace rose:[10x10+0+0] with your actual image.suffix. See http://www.imagemagick.org/Usage/files/#txt

    convert rose:[10x10+0+0] -depth 8 txt: | tail -n +2 | sed -n "s/^\(.*\):.*\(#.*\) .*$/\1 \2/p"
    

    Which returns:

    0,0 #302F2D 
    1,0 #32302E 
    2,0 #36322F 
    3,0 #38332E 
    4,0 #3A332D 
    5,0 #39322D 
    6,0 #38302D 
    7,0 #39312E 
    8,0 #38302D 
    9,0 #38302D 
    0,1 #2F2E2C 
    1,1 #302F2D 
    2,1 #35302D 
    3,1 #37312D 
    4,1 #38312C 
    5,1 #38302C 
    6,1 #362F2C 
    7,1 #38312D 
    8,1 #38312D 
    9,1 #38312E 
    0,2 #2C2C2C 
    1,2 #2C2D2B 
    2,2 #302F2C 
    3,2 #312E2B 
    4,2 #322C28 
    5,2 #322D2A 
    6,2 #302C2B 
    7,2 #322C2B 
    8,2 #322B2B 
    9,2 #322C2B 
    0,3 #2C2D2F 
    1,3 #2B2D2F 
    2,3 #2E2D2D 
    3,3 #2F2D29 
    4,3 #2F2A27 
    5,3 #2D2B28 
    6,3 #2C2A2A 
    7,3 #2C2A2A 
    8,3 #2E2B2B 
    9,3 #2E2B2B 
    0,4 #2C2F32 
    1,4 #2B2F32 
    2,4 #2E2E30 
    3,4 #2D2E2D 
    4,4 #2D2B29 
    5,4 #2C2A2B 
    6,4 #2B292B 
    7,4 #282728 
    8,4 #2A2A2B 
    9,4 #2C2A2B 
    0,5 #2E302E 
    1,5 #2F2F2D 
    2,5 #2F312E 
    3,5 #32312E 
    4,5 #33302D 
    5,5 #332F2C 
    6,5 #322D2A 
    7,5 #2D2A2B 
    8,5 #2C2B2C 
    9,5 #2A292D 
    0,6 #32332D 
    1,6 #33342D 
    2,6 #35332E 
    3,6 #393631 
    4,6 #393631 
    5,6 #3A322E 
    6,6 #38302D 
    7,6 #332E2C 
    8,6 #333030 
    9,6 #2D2E30 
    0,7 #373832 
    1,7 #373832 
    2,7 #393934 
    3,7 #3C3A35 
    4,7 #403D38 
    5,7 #423A38 
    6,7 #413935 
    7,7 #3D3733 
    8,7 #3C3735 
    9,7 #3A3534 
    0,8 #383933 
    1,8 #393A34 
    2,8 #3E3E38 
    3,8 #413F3A 
    4,8 #443F3A 
    5,8 #46413C 
    6,8 #45413A 
    7,8 #45403A 
    8,8 #473F38 
    9,8 #453D34 
    0,9 #363731 
    1,9 #363831 
    2,9 #3D3D38 
    3,9 #42403B 
    4,9 #46413F 
    5,9 #48433E 
    6,9 #48433E 
    7,9 #4A443C 
    8,9 #4D4237 
    9,9 #4A3D30