haskell - How to extract RGB values from (most) pictures? -


i want extract every rgb value possible pictures in haskell.

what easiest way raw values (0-255)?

i got results juicy pixels library, somehow exception:

*** exception: ./data/vector/generic.hs:249 ((!)): index out of bounds (660000,660000) 

this corresponding code.

{-# language typesynonyminstances #-}  module main  import codec.picture         (readimage, pixelat, pixelrgb8(..)) import codec.picture.types import system.filepath.posix (splitextension)  torgbraw :: filepath -> io () torgbraw fp =     image <- readimage fp     case image of       left _ -> putstrln $ "sorry, not supported codec " ++ fp       right dynimg ->         let imgrgba8 = fromdynamicimage dynimg         let (name, _) = splitextension fp         writefile (name ++ ".txt") (concat $ accumpixels imgrgba8)  accumpixels :: image pixelrgba8 -> [string] accumpixels img@(image w h _) = [ format (pixelat img x y) x y | x <- [0..w], y <- [0..h]]   format (pixelrgba8 r g b _) j k = "#" ++ show r ++ "$"                                               ++ show g ++ "$"                                               ++ show b ++ "$"                                               ++ show j ++ "$"                                               ++ show k ++ "*\n"   -- copied -- see http://hackage.haskell.org/package/juicypixels-util-0.2/docs/codec-picture-rgba8.html  class topixelrgba8     torgba8 :: -> pixelrgba8  instance topixelrgba8 pixel8     torgba8 b = pixelrgba8 b b b 255  instance topixelrgba8 pixelya8     torgba8 (pixelya8 l a) = pixelrgba8 l l l  instance topixelrgba8 pixelrgb8     torgba8 (pixelrgb8 r g b) = pixelrgba8 r g b 255  instance topixelrgba8 pixelrgba8     torgba8 = id  fromdynamicimage :: dynamicimage -> image pixelrgba8 fromdynamicimage (imagey8 img) = pixelmap torgba8 img fromdynamicimage (imageya8 img) = pixelmap torgba8 img fromdynamicimage (imagergb8 img) = pixelmap torgba8 img fromdynamicimage (imagergba8 img) = img  -- end of codec.picture.rgba8 

this example image: link

the code little bit unordered because had copy definitions codec.picture.rgba8 not available through lts. don't mind string representation, i'm parsing via arduino wifi shield.

your list comprehension in accumpixels 0-indexed, includes boundaries. issue. in haskell, [0..3] list [0,1,2,3], mean [0..(w-1)] , [0..(h-1)].


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -