Get image pixel values โ€‹โ€‹using Haskell

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

A slight push in the right direction would be well appreciated.

+6
source share
5 answers

I have used the repa-devil package for this in the past. It allows you to work with a bunch of formats using the image library for developers (DevIL). You can read and write all the formats that you probably care about.

Actual image data is represented as a Repa array. This is a great library for array operations and makes it easy to write parallel code.

+3
source

You can use JuicyPixels, Haskell's own library for uploading images. It is quite easy to convert to REPA (manually or using JuicyPixesl-repa).

+4
source

Try the repa library. There is also a small tutorial here

+3
source
  • GTK supports loading and saving JPEG and PNG. [AFAIK, no other formats.] There is a Haskell binding named Gtk2hs . It supports vector graphics very well, but raster graphics, although supported, are not so easy to understand. So I wrote AC-EasyRaster-GTK , which wraps GTK in a more user-friendly interface. (However, he still needs Gtk2hs .) The only real side is that Gtk2h little difficult to configure on Windows. (And it may be too difficult to install the entire set of GUI tools to load and save image files.)

  • I understand that the "GD" library supports recording several image formats and is quite small and simple. I believe that Hackage has Haskell bindings for GD. I have not tried this personally.

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

0
source

Here is the new Haskell image processing library that uses JuicyPixels for encoding, provides an interface to read and write all supported formats in a very simple manner and manipulate them in any way you can imagine. As a simple example of how easy it is:

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

The above image will be read in JPG format in the RGB color space, rotate it 90 degrees clockwise and save as a PNG image.

Oh yes, it can also use Repa, so you also get parallel processing for free.

0
source

Source: https://habr.com/ru/post/927776/


All Articles