public
Created

Codebrawl #10

  • Download Gist
.gitignore
1 2
input.png
/Gemfile.lock
Gemfile
Ruby
1 2 3 4
source "http://rubygems.org"
 
gem "chunky_png", "~> 1.2.1"
gem "colour", "~> 0.4.0"
readme.md
Markdown

selective-color

Turns the input image (input.png) into a selectively colored image, turning it into grayscale with just the lighter blue crayon left colored.

dependencies

usage

$ bundle install
$ curl -o input.png https://raw.github.com/gist/7addc24b123aad374832/96656b5a75287f8ca8beac523f1d32eee4030aa5/output.png
$ ruby selective_color.rb
selective_color.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
require 'chunky_png'
require 'colour'
 
#color_range = (14..65) # yellow
color_range = (170..220) # lighter blue
 
input = ChunkyPNG::Image.from_file('input.png')
output = input.grayscale
 
input.pixels.each_index do |x|
pixel = input.pixels[x]
hsv = RGB.new(ChunkyPNG::Color.r(pixel), ChunkyPNG::Color.g(pixel), ChunkyPNG::Color.b(pixel)).to_hsv
output.pixels[x] = pixel if color_range.cover? hsv.h
end
 
output.save('output.png')

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.