Ruby-vips image processing library. Are there any good use cases?

I am completely new to image processing. I donโ€™t know anything about what's inside JPEG and how it works.

I wonder if I can find a ruby โ€‹โ€‹code snippet that performs the following simple operation:

  • Open the jpeg file.
  • Swipe through each pixel and set the color to green fx.
  • Write the result to another file.

I am particularly interested in how this can be done using the ruby-vips library
https://github.com/ender672/ruby-vips

My goal is to learn how to perform basic image processing operations using ruby-vips (gamma correction, brightness, hue, ...)

Any links to working examples that are more complex than "hello world", as on the ruby-vips github page, would be much appreciated!

If there are alternatives to ruby-vips, I will also be grateful to them.


UPDATE

A lot has happened since I asked this question:

+5
source share
2 answers

I am one of the supporting libvips, an image processing library that wraps ruby-vips.

The Tim Ruby-vips repository did not move for some time. I have a fork that works with current libvips:

https://github.com/jcupitt/ruby-vips

There is another example of ruby-vips on the vips main site, on the benchmark page. This example loads an image, visits 100 pixels from each edge, reduces it by 10%, sharpenes and saves again.

http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use#ruby-vips

To set the red and blue channels to zero and just leave the green image (is that what you mean?), You can multiply R and B by zero and G by 1. A convenient operation for this is "lin", (which means "linear transformation").

http://rubyvips.holymonkey.com/classes/VIPS/Image.html#M000123

out = in.lin(a, b) 

sets each pixel to

 out = in * a + b 

It allows you to give an array of numbers for a and b and will use one element of the array per image channel. 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 the gamut of the image, you can try something like:

 im = im.pow(0.5).lin(255 / 255 ** 0.5, 0) 

Although this will be a bit slow (it will call pow () three times for each pixel), it would be much faster to do a lookup table, run pow (), and then display the image through the table:

 lut = Image.identity(1) lut = lut.pow(0.5).lin(255 /255 ** 0.5, 0) im = im.maplut(lut) 
+9
source

I'm sorry I don't know ruby-vips, but ImageMagick is classic when it comes to image processing. There are Ruby bindings in the form of RMagick ( current repo ), and you can get many functions from ImageMagick documents, but there are also three tutorials here , as well as many examples on the Internet.

If you really want to delve into the theory of image processing, which is fundamentally a form of signal processing (this is completely interesting and useful, since it often allows you to use very similar algorithms on images and audio / video signals, but in the end it will be very difficult in mathematics - Fourier transform), then, if mathematics does not scare you, I can only recommend reading a book by Gonzalez and Woods, I would say that this is a definite reference in this area. It's expensive, but there is everything you need to get you started and far beyond. There is also a page with links to free e-books if you want to get started without spending a lot of money in the first place.

+1
source

All Articles