开发者

Return array of pixel values using Ruby and Mini Magick (or RMagick?)

开发者 https://www.devze.com 2023-03-30 11:59 出处:网络
I\'m trying to use mini_magick and ruby to get an array of all of the pixel values for an input image.

I'm trying to use mini_magick and ruby to get an array of all of the pixel values for an input image.

I plan on eventually working with that array to design my own codec for it, this is for a homework assignment.

Can anyone assist with the syntax for retrieving an array of these values? Or suggest that I use something other than mini_magick if necessary?

Note: I already have ImageMagick installed on my computer. I'm running Mac OSX Lion.

Update: Because a user requested me to post the code I have already (even though it's not completely relevant)

require 'rubygems'
require 'mini_magick'

path = "/Users/ardavis/Pictures/Atlantis/Andy_and_the_Shuttle.jpg"
image = MiniMagick::Image.new(path)

Update 2: Currently attempting to use RMagick, looking into the export_pixels function, not certain how it's used yet. Thank 开发者_JAVA技巧you!


AFAIK, MiniMagick just wraps the command line tools so that's probably not the best choice for working with individual pixels.

RMagick wraps the C libraries so pixel-level work should be a lot easier and faster. There is get_pixels in RMagick:

Gets the pixels from the specified rectangle within the image.

That returns an array of Pixel objects and from there you can get the raw RGBA data and scale the numbers to whatever ranges works for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号