ruby - Image histogram with mini_magick or image_science? -
is possible fetch histogram of image mini_magick or image_science?
i afraid mini_magicks usage of mogrify not allow such information retrieval. image_science hardly documented , seems limited thumbnail scaling , cropping only.
one route take, iterate on each pixel , extract values, in ruby. requires information on pixels, cannot in mini_magick either.
i can fallback either rmagick or im_magick, either less popular/unknown or reportedly bad in performance.
for record: part of earlier question finding entropy of parts of images.
a workaround use mini_magick convert file png format, store result in temporary file, , use "almost-pure ruby" png library or actually-pure ruby chunky_png go on result. both libraries make easy iterate on image pixel pixel.
i'm suspecting specified mini_magick/image_science because these lot easier install than, say, rmagick. reason workaround might work you, then, png , chunky_png pain-free installs due lack of dependencies.
the thing you'd giving little performance if it's real problem, oily_png can extend chunky_png c magic.. there'll compile, shouldn't painful one.
ok, i've come code works:
require 'mini_magick' require 'chunky_png' = minimagick::image.open("a.jpg") i.format('png') p = chunkypng::image.from_io(stringio.new(i.to_blob)) p.height.times |y| p.width.times |x| p[x, y] # => here's pixel.. end end
you can take histogram creation part there ;-)
also, noticed imagemagick can create histograms command line. might not if want specific thought i'd throw out there.
Comments
Post a Comment