update ruby-vips has changed a bit since this answer was written. I've revised it for the current (2018) version.
I'm one of the maintainers of libvips, the image processing library that ruby-vips wraps.
Tim's ruby-vips repository hasn't been touched for a while. I have a fork here that works with current libvips:
https://github.com/jcupitt/ruby-vips
There are some examples here:
https://github.com/jcupitt/ruby-vips/tree/master/example
To set the red and blue channels to zero and just leave a
green image you might multiply R and B by
zero and G by 1. ruby-vips uses arrays to represent pixel constants, so you can just write:
out = in * [0, 1, 0]
A complete runnable example might be:
#!/usr/bin/ruby
require 'vips'
im = Vips::Image.new_from_file '/home/john/pics/theo.jpg'
im *= [0, 1, 0]
im.write_to_file 'x.jpg'
There's a trick you can use for new_from_file
: if you know you will just be doing simple top-to-bottom operations on the image, like arithmetic or filtering or resize, you can tell ruby-vips that you only need sequential access to pixels:
im = Vips::Image.new_from_file '/home/john/pics/theo.jpg', access: :sequential
Now ruby-vips will stream your image. It'll run the load, the multiply and the save all in parallel and never keep more than a few scanlines of pixels in memory at any one time. This can give a really nice improvement to speed and memory use.
To change image gamma you might try something like:
im = im ** 0.5 * 255 / 255 ** 0.5
Though that'll be a bit slow (it'll call pow() three times for each pixel), it'd be much faster to make a lookup table, run the pow() on that, then map the image through the table:
lut = Vips::Image.identity
lut = lut ** 0.5 * 255 /255 ** 0.5
im = im.maplut lut
Any questions, please feel free to open them on the rubyvips issue tracker:
https://github.com/jcupitt/ruby-vips/issues