I am completely new to image processing. I know nothing about what is JPEG internally and how it works.
I wonder, if I can find somewhere piece of ruby code performing following simple operation:
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:
There's another ruby-vips example on the main vips site, on the benchmarks page. This example loads an image, crops 100 pixels off every edge, downsizes by 10%, sharpens and saves again.
To set the red and blue channels to zero and just leave a green image (is this what you mean?) you might multiply R and B by zero and G by 1. A handy 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('/home/john/pics/theo.jpg') im = im.lin [0, 1, 0], [0, 0, 0] im.write('x.jpg')
To change image gamma you might try something like:
im = im.pow(0.5).lin(255 / 255 ** 0.5, 0)
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 = Image.identity(1) lut = lut.pow(0.5).lin(255 /255 ** 0.5, 0) im = im.maplut(lut)