I'm trying to implement/convert the daltonize algorithm for correcting images for colour-blind people into ruby.
There are two primary reference implementations written in javascript and python + other implementations in languages/environments I'm not familiar with.
I have virtually no experience with image processing, let alone with VIPS / ruby-vips. I'm wondering how to make the first steps. The documentation seems primarily in C/C++ and very little on the ruby side. It's also extremely detailed. I'm not even sure which basic operations to use. Looks like the lin
function is a good starting point, but I'm not exactly sure how to apply it.
Anybody with some VIPS experience can probably work out the entire algorithm in a few minutes. I wonder if anybody can give me some pointers on where to start. Specifically:
(note This was a very old answer and described ruby-vips as of two major versions ago. I've updated it for the 2.0.16 gem, the current version in November 2019)
There is complete documentation here:
https://rubydoc.info/gems/ruby-vips
The Vips
section has a tutorial-style introduction:
https://rubydoc.info/gems/ruby-vips/Vips
For example:
require 'vips'
if ARGV.length < 2
raise "usage: #{$PROGRAM_NAME}: input-file output-file"
end
im = Vips::Image.new_from_file ARGV[0], access: :sequential
im *= [1, 2, 1]
mask = Vips::Image.new_from_array [
[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]
], 8
im = im.conv mask, precision: :integer
im.write_to_file ARGV[1]
This opens an image in streaming mode, multiplies the middle band (green) by two, sharpens the image with an integer convolution, and writes the result back. You can run it like this:
./example.rb x.jpg y.ppm
There's a full "daltonize" example in the ruby-vips repo:
https://github.com/libvips/ruby-vips/blob/master/example/daltonize8.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With