Page 3 of 3

Re: Palleter

Posted: Mon Apr 28, 2014 10:29 pm
by bones
^ OK, got that, thanks. So, it looks like it just outputs the color palette info into the console, right? What's the best way to get that info from the console to a new entry in the "console_colors" directory?

Re: Palleter

Posted: Mon Apr 28, 2014 10:46 pm
by pidsley

Code: Select all

./palleterx /path/to/image > /path/to/xcolors_file

Re: Palleter

Posted: Mon Apr 28, 2014 10:48 pm
by dkeg
I do this

Code: Select all

./palleterX /path/to/image > /path/to/console_colors/newscheme && $editor /path/to/console_colors/newscheme 
I do it this way to add in bg and fg colors, or whatever

Ahh, I see pids chimed in already.

Re: Palleter

Posted: Mon Apr 28, 2014 10:54 pm
by bones
Excellent, thanks gentlemen!

Re: Palleter

Posted: Mon Apr 28, 2014 11:00 pm
by pidsley
dkeg wrote:Ahh, I see pids chimed in already.
Sorry; I didn't wait long enough for you to answer -- your answer is better anyway.

Re: Palleter

Posted: Mon Apr 28, 2014 11:15 pm
by bones
Both work great, thanks. The results of my first...
sharkfin_nightscape.png
I'm calling it 'nightscape':

Code: Select all

!!!! nightscape !!!!
*background:#111111
*foreground:#d3d3d3
*fading:10
*fadeColor:#111111
*transparent:0
*shading:70
*color0: #0A0C11
*color1: #111526
*color2: #21221F
*color3: #2D3747
*color4: #2F2D2F
*color5: #354C54
*color6: #374536
*color7: #49362B
*color8: #575F5B
*color9: #5C4C31
*color10: #637D7F
*color11: #6F9FCE
*color12: #708F94
*color13: #946738
*color14: #B4C4B9
*color15: #BD9E5A

Re: Palleter

Posted: Mon Apr 28, 2014 11:48 pm
by dkeg
nice! you should post this in the .Xresource thread please

Re: Palleter

Posted: Tue Apr 29, 2014 12:14 am
by bones
^ Done!

Re: Palleter

Posted: Mon Aug 03, 2015 1:41 pm
by a-109-107
My bash is too weak, so I added some changes in python to suit my setup better. The changes are:
- The brightest color is labeled as foreground
- The darkest as background
- The histogram from imagemagick is tweaked to produce more 'drastic' colors with the use of the -level parameter

Code: Select all

#!/usr/bin/env python2.7

import re
import sys
import operator
import commands

histogram = commands.getoutput('convert '+sys.argv[1]+' -colors 16 -level 10%  -format "%c" histogram:info: | sort -nr').split('\n')

colors = list()
outputColors = dict()
outputSpecial = dict()

for line in histogram:
    #extract the hex string
    hex = re.search("\((.+?)\).(\#\S{6})",line).group(2)

    #regex, strip, and put R-G-B into an array
    rgb = re.search("\((.+?)\).(\#\S{6})",line).group(1).split(',')
    rgb = map(str.strip, rgb)
    rgb = map(int, rgb)

    # approximated luma calculation
    luma = (rgb[0]+rgb[0]+rgb[1]+rgb[2]+rgb[2]+rgb[2])/6

    colors.append({'luma':luma, 'hex':hex})

# get the darkest and brightest and remove them from the list
seq = [c['luma'] for c in colors]
maxLuma = max(seq)
minLuma = min(seq)

for i,c in enumerate(colors):
    if c['luma'] == minLuma:
        outputSpecial["background"]= c['hex']
    elif c['luma'] == maxLuma:
        outputSpecial["foreground"] = c['hex']
    else:
        outputColors["color"+str(i)] = c['hex']

print '\n'.join("*.%s: %s" % (key,val) for (key,val) in outputSpecial.iteritems())
for key in sorted(outputColors.iterkeys()):
    print "*.%s: %s" % (key, outputColors[key])

The script used upon this image:
Image
Yields:

Code: Select all

*.foreground: #FFFFFF
*.background: #000000
*.color0: #6D6D5F
*.color1: #E2E06E
*.color10: #382FFD
*.color11: #3B3200
*.color12: #E2E2E2
*.color13: #DCDAAF
*.color14: #D5A818
*.color15: #17B1ED
*.color2: #989898
*.color5: #3D3D3D
*.color6: #1DAB1C
*.color7: #A8A15D
*.color8: #1F1510
*.color9: #C14809
Which colorized looks like this (disregard the background color):
Image

Re: Palleter

Posted: Tue Aug 04, 2015 3:18 am
by dkeg
good idea with grabbing the bg and fg. Looks good. Nice work.

Re: Palleter

Posted: Tue Aug 04, 2015 8:57 am
by a-109-107
Theres another interesting take on this task. If you sort the histogram outbut by the first column, you will get the most popular/representative color of the image.
I'm thinking about the most universal way of extracting usable palletes. Something like:

- Get histogram sorted by popularity
- Grap and pop darkest and lightest
- Sort the rest by hue (?)

Now that I've written these steps down, not sure what's the point of the sorting in the first place...

Re: Palleter

Posted: Tue Aug 04, 2015 7:36 pm
by rhowaldt
nice, great work man. you could've of course taken the opportunity to brush up your bash, but who cares ;)

Re: Palleter

Posted: Fri Aug 07, 2015 5:36 am
by doubledutch
Now write it in objective-c and get app store famous. Beautiful script.