Palleter

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Palleter

Unread post by bones » Mon Apr 28, 2014 10:29 pm

^ 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?

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Palleter

Unread post by pidsley » Mon Apr 28, 2014 10:46 pm

Code: Select all

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

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Palleter

Unread post by dkeg » Mon Apr 28, 2014 10:48 pm

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.

Work hard; Complain less

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Palleter

Unread post by bones » Mon Apr 28, 2014 10:54 pm

Excellent, thanks gentlemen!

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Palleter

Unread post by pidsley » Mon Apr 28, 2014 11:00 pm

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.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Palleter

Unread post by bones » Mon Apr 28, 2014 11:15 pm

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

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Palleter

Unread post by dkeg » Mon Apr 28, 2014 11:48 pm

nice! you should post this in the .Xresource thread please

Work hard; Complain less

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Palleter

Unread post by bones » Tue Apr 29, 2014 12:14 am

^ Done!

User avatar
a-109-107
Riesenpenis
Posts: 30
Joined: Thu May 21, 2015 9:04 am

Re: Palleter

Unread post by a-109-107 » Mon Aug 03, 2015 1:41 pm

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

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: Palleter

Unread post by dkeg » Tue Aug 04, 2015 3:18 am

good idea with grabbing the bg and fg. Looks good. Nice work.

Work hard; Complain less

User avatar
a-109-107
Riesenpenis
Posts: 30
Joined: Thu May 21, 2015 9:04 am

Re: Palleter

Unread post by a-109-107 » Tue Aug 04, 2015 8:57 am

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...

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Palleter

Unread post by rhowaldt » Tue Aug 04, 2015 7:36 pm

nice, great work man. you could've of course taken the opportunity to brush up your bash, but who cares ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
doubledutch
killall X
Posts: 163
Joined: Sun Aug 10, 2014 1:25 pm

Re: Palleter

Unread post by doubledutch » Fri Aug 07, 2015 5:36 am

Now write it in objective-c and get app store famous. Beautiful script.

Post Reply