문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top