10

Is there a way or a library available that can load an image (jpeg, png, etc) and assign the pixel values of that image into a list or matrix? I'd like to do some experiments with image and pattern recognition.

A little nudge in the right direction would be appreciated.

lehins
  • 9,642
  • 2
  • 35
  • 49
subtlearray
  • 1,251
  • 1
  • 11
  • 23

5 Answers5

4

You can use JuicyPixels, a native Haskell library for image loading. This is rather easy to convert to REPA as well (manually or with JuicyPixesl-repa).

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • 1
    Thomas, would you happen to know where I could find some usage examples? The documentation is reading very cryptically for me. – subtlearray Jun 02 '13 at 00:36
  • 1
    I can't help much without knowing the task. I suggest starting with `func file = onImg someRepaFunction \`fmap\` readImage file`. Using that line you should only need to define `someRepaFunction`. – Thomas M. DuBuisson Jun 02 '13 at 00:47
  • I'm sorry for bothering you. I don't know what a repa is, and I can't get repa-devil to install in Windows because of some -dev C library dependency. My patience has finally ran out. I like Haskell, but I can't deal with this anymore. Thank you again for your time. – subtlearray Jun 02 '13 at 01:45
  • 1
    Repa is an array library, there are tutorials you can find online - one linked in the below answer. If you are looking for more real-time help then I suggest you try IRC (#haskell on freenode.net) – Thomas M. DuBuisson Jun 02 '13 at 01:50
3

Try the repa library .Also there is a small tutorial here

user1105045
  • 474
  • 3
  • 15
3

I've used the repa-devil package for this in the past. It lets you work with a bunch of formats using Developer's Image Library (DevIL). You can read and write all the formats you are likely to care about.

The actual image data is given as a Repa array. This is a great library for array operations and makes it very easy to write parallel code.

Tikhon Jelvis
  • 67,485
  • 18
  • 177
  • 214
1

Here is a new Haskell Image Processing library, which uses JuicyPixels for encoding, provides interface for you to read and write all of the supported formats in a very easy manner and manipulate them in any way you can imagine. Just as a simple example on how easy it is:

>>> img <- readImageRGB "image.jpg"
>>> writeImage "image90.png" $ rotate90 img

Above will read a JPG image in RGB color space, rotate it 90 degrees clockwise and save it as a PNG image.

Oh yeah, it also can use Repa, so you will get parallel processing for free as well.

lehins
  • 9,642
  • 2
  • 35
  • 49
0
  1. GTK supports loading and saving JPEG and PNG. [AFAIK, no other formats though.] There is a Haskell binding named Gtk2hs. It supports vector graphics very well, but bitmap graphics, while supported, isn't especially easy to figure out. So I wrote AC-EasyRaster-GTK, which wraps GTK in a more friendly interface. (It still needs Gtk2hs though.) The only real down-side is that Gtk2h is a bit fiddly to set up on Windows. (And it's arguably overkill to install an entire GUI toolkit just to load and save image files.)

  2. I gather the "GD" library supports writing several image formats, and is quite small and simple. I believe Hackage has Haskell bindings for GD as well. I haven't tried this personally.

  3. There is a file format called PPM which is deliberately designed to be ridiculously easy to implement (it's a tiny header and then an array of pixels), and consequently there's at least a dozen packages on Hackage which implement it (including my own AC-PPM). There are also lots of programs out there which can display and/or convert images in this format.

MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220