本文介绍了Ruby-vips图像处理库。有没有好用的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我对图像处理完全陌生。我对JPEG内部及其工作方式一无所知。I am completely new to image processing. I know nothing about what is JPEG internally and how it works.我想知道,如果我能找到一些执行以下简单操作的ruby代码:I wonder, if I can find somewhere piece of ruby code performing following simple operation: 打开jpeg文件。 遍历每个像素并将其颜色设置为fx green。 将结果写入另一个文件。我对使用ruby-vips库如何实现这一点特别感兴趣 https://github.com/ender672/ruby-vipsI am especially interested in how this can be accomplished using ruby-vips libraryhttps://github.com/ender672/ruby-vips我的目标 - 学习如何使用ruby-vips执行基本图像处理操作(伽马校正,亮度,色调......)My goal - to learn how to perform basic image processing operations using ruby-vips (gamma correction, brightness, tint, ...)任何比'hello world'更复杂的工作示例的链接 - 就像在ruby-vips的github页面上一样,将非常感谢!Any links to working examples more complex than 'hello world'-like one on ruby-vips's github page would be highly appreciated!如果有的话是ruby-vips的替代品,我也会感谢他们。If there are alternatives to ruby-vips, I would be thankful for them too. UPDATE自从我提出这个问题以来发生了很多事情:Much has happened since I asked this question: ruby​​-vips是一个宝石: http:// libvips.blogspot.co.uk/2012/06/ruby-vips-launches.html 完全重写vips8,现在基于ruby-ffi 源代码存储库在这里: https://github.com/jcupitt/ruby -vips / 使用示例: https://github.com/jcupitt/ruby-vips/wiki/Examples 视频图像处理的基本概念: https://github.com/jcupitt/ruby-vips/wiki/Basic-concepts ruby​​-vips集成到Ruby on Rails的CarrierWave上传器插件: https://github.com/eltiare/carrierwave-vips ruby​​-vips是rails6中ActiveStorage的官方后端之一ruby-vips is a gem: http://libvips.blogspot.co.uk/2012/06/ruby-vips-launches.htmlcomplete rewrite for vips8, now based on ruby-ffiSource code repository is here: https://github.com/jcupitt/ruby-vips/The examples of usage: https://github.com/jcupitt/ruby-vips/wiki/ExamplesBasic concepts of vips image processing: https://github.com/jcupitt/ruby-vips/wiki/Basic-conceptsruby-vips integration into CarrierWave uploader plugin for Ruby on Rails: https://github.com/eltiare/carrierwave-vipsruby-vips is one of the official backends for ActiveStorage in rails6推荐答案 更新 ruby​​-vips已经改变了一点,因为写了这个答案。我已经修改了当前的(2018)版本。update ruby-vips has changed a bit since this answer was written. I've revised it for the current (2018) version.我是libvips的维护者之一,这是ruby-vips的图像处理库包裹。I'm one of the maintainers of libvips, the image processing library that ruby-vips wraps. Tim的ruby-vips存储库暂时没有被触及。我在这里有一个与当前libvips一起使用的分支: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这里有一些例子: https://github.com/jcupitt/ruby-vips / tree / master / example要将红色和蓝色通道设置为零,只需保留绿色图像,您可以将R和B相乘通过零和G乘以1. ruby​​-vips使用数组来表示像素常量,因此您只需写:To set the red and blue channels to zero and just leave agreen image you might multiply R and B byzero 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/rubyrequire 'vips'im = Vips::Image.new_from_file '/home/john/pics/theo.jpg'im *= [0, 1, 0]im.write_to_file 'x.jpg'有一招你可用于 new_from_file :如果你知道你只是对图像进行简单的从上到下操作,比如算术或过滤或调整大小,你可以告诉ruby-vips你只需要顺序访问像素: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现在ruby-vips将流式传输您的图像。它将并行运行加载,乘法和保存,并且在任何时候都不会在内存中保留多个像素扫描线。这可以为速度和内存使用提供非常好的改进。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虽然这有点慢(它会为每个像素调用pow()三次),制作一个查找表,运行pow(),然后通过表映射图像要快得多: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.identitylut = lut ** 0.5 * 255 /255 ** 0.5im = im.maplut lut如有任何问题,请随时在rubyvips问题跟踪器上打开它们:Any questions, please feel free to open them on the rubyvips issue tracker: https://github.com/jcupitt/ruby- vips / issues 这篇关于Ruby-vips图像处理库。有没有好用的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 04:55