Problem with Histogram #2

diegorv opened this Issue Oct 30, 2012 · 1 comment


None yet
2 participants

diegorv commented Oct 30, 2012


I have this image:

When i use this image in the code, 16).scores[0..7].each do |c|
   puts c

I get this error:

ArgumentError: ArgumentError
from /app/vendor/bundle/ruby/1.9.1/gems/color-1.4.1/lib/color/rgb.rb:54:in `from_html'
from (irb):22
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'

Try debug with this code from histogram.rb class

image_path = ""
colors = 16
depth = 8
output = `convert #{image_path} -resize 400x400 -format %c -dither None -quantize YIQ -colors # {colors} -depth #{depth} histogram:info:-`
@lines =
hex_values = { |line| line[/#[0-9A-F]+/] }

I got this output

=> ["#C0B09B", "#CEC6BA", "#D9CDBC", "#EAD2CB", "#F2EEE4", "#D6DBD8", "#BF312B", "#D19A94", "#625A49", "#A69173", "#EF755C", "#573D24", "#ED973A", "#723330", "#9CAE9CFE", "#9A9F9CFA"]

"#9CAE9CFE", "#9A9F9CFA" doesnt work in

def colors
   hex_values = { |line| line[/#[0-9A-F]+/] } { |hex| Color::RGB.from_html(*hex) } # < PROBLEM HERE 

What i can do?


quadule commented Nov 18, 2012

Thanks for the thorough report! I just pushed a new version that should fix this issue.

Since those extra two hex digits in the color are the alpha channel, Colorscore now ignores colors with any transparency. I'm thinking this could be changed to a transparency cutoff, or it could just reduce the score of the color — let me know if you have any thoughts on that.

@quadule quadule closed this Nov 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment