Domanda

I want to process the image pixel by pixel and need to find each pixel's RGB value. This is my exact requirement.

For this am using rmagick gem. But it was very slow to process the entire image.

This is my code,

source = Magick::Image.read("http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash3/s720x720/1000741_634750993209985_702651963_n.jpg")

source.rows.times do |row|
            source.columns.times do |col|

            end 
end

Can any one give me solution for this?

È stato utile?

Soluzione

There is a method called each_pixel on your image object. I think that might be what you want. Latest version of RMagick and some of the older versions also has it

(Object) each_pixel

def each_pixel
  get_pixels(0, 0, columns, rows).each_with_index do |p, n|
    yield(p, n%columns, n/columns)
  end
  self
end

You can find the documentation and other methods here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top