Skip to content
stanislaw edited this page Jun 22, 2012 · 27 revisions

Examples

Gamma

#!/usr/bin/ruby

require 'rubygems'
require 'vips'
include VIPS

im = Image.new('mypic.jpg')

lut = Image.identity(1)

gamma = 0.8

lut = lut.pow(gamma).lin(255 /255 ** gamma, 0)
im = im.maplut(lut)

im.write('x.jpg')

Color given jpg file to green (this is my favourite example).

For 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. A handy vips operation for this is "lin", meaning "linear transform").

out = in.lin(a, b)

sets every pixel in out to be

out = in * a + b

It lets you give an array of numbers for a and b and will use one array element per image channel. So therefore:

#!/usr/bin/ruby
require 'rubygems'
require 'vips'
include VIPS

im = Image.new('mypic.jpg')
im = im.lin [0, 0, 0], [0, 255, 0]

im.write('output.jpg')
Clone this wiki locally