Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4615632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:52:04+00:00 2026-05-22T01:52:04+00:00

I want to tackle some image-processing problems in Haskell. I’m working with both bitonal

  • 0

I want to tackle some image-processing problems in Haskell. I’m working with both bitonal (bitmap) and color images with millions of pixels. I have a number of questions:

  1. On what basis should I choose between Vector.Unboxed and UArray? They are both unboxed arrays, but the Vector abstraction seems heavily advertised, particular around loop fusion. Is Vector always better? If not, when should I use which representation?

  2. For color images I will wish to store triples of 16-bit integers or triples of single-precision floating-point numbers. For this purpose, is either Vector or UArray easier to use? More performant?

  3. For bitonal images I will need to store only 1 bit per pixel. Is there a predefined datatype that can help me here by packing multiple pixels into a word, or am I on my own?

  4. Finally, my arrays are two-dimensional. I suppose I could deal with the extra indirection imposed by a representation as “array of arrays” (or vector of vectors), but I’d prefer an abstraction that has index-mapping support. Can anyone recommend anything from a standard library or from Hackage?

I am a functional programmer and have no need for mutation 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:52:04+00:00Added an answer on May 22, 2026 at 1:52 am

    For multi-dimensional arrays, the current best option in Haskell, in my view, is repa.

    Repa provides high performance, regular, multi-dimensional, shape polymorphic parallel arrays. All numeric data is stored unboxed. Functions written with the Repa combinators are automatically parallel provided you supply +RTS -Nwhatever on the command line when running the program.

    Recently, it has been used for some image processing problems:

    • Real time edge detection
    • Efficient Parallel Stencil Convolution in Haskell

    I’ve started writing a tutorial on the use of repa, which is a good place to start if you already know Haskell arrays, or the vector library. The key stepping stone is the use of shape types instead of simple index types, to address multidimensional indices (and even stencils).

    The repa-io package includes support for reading and writing .bmp image files, though support for more formats is needed.

    Addressing your specific questions, here is a graphic, with discussion:


    All three of UArray, Vector, and Repa support unboxing. Vector and Repa have a rich, flexible API, but UArray does not. UArray and Repa have multi-dimensional indexing, but Vector does not. They all have support for bit-packing, although Vector and Repa have some caveats in that regard. Vector and Repa interoperate with C data and code, but UArray does not. Only Repa supports stencils.


    On what basis should I choose between Vector.Unboxed and UArray?

    They have approximately the same underlying representation, however, the primary difference is the breadth of the API for working with vectors: they have almost all the operations you’d normally associate with lists (with a fusion-driven optimization framework), while UArray have almost no API.

    For color images I will wish to store triples of 16-bit integers or triples of single-precision floating-point numbers.

    UArray has better support for multi-dimensional data, as it can use arbitrary data types for indexing. While this is possible in Vector (by writing an instance of UA for your element type), it isn’t the primary goal of Vector — instead, this is where Repa steps in, making it very easy to use custom data types stored in an efficient manner, thanks to the shape indexing.

    In Repa, your triple of shorts would have the type:

    Array DIM3 Word16
    

    That is, a 3D array of Word16s.

    For bitonal images I will need to store only 1 bit per pixel.

    UArrays pack Bools as bits, Vector uses the instance for Bool which does do bit packing, instead using a representation based on Word8. Howver, it is easy to write a bit-packing implementation for vectors — here is one, from the (obsolete) uvector library. Under the hood, Repa uses Vectors, so I think it inherits that libraries representation choices.

    Is there a predefined datatype that can help me here by packing multiple pixels into a word

    You can use the existing instances for any of the libraries, for different word types, but you may need to write a few helpers using Data.Bits to roll and unroll packed data.

    Finally, my arrays are two-dimensional

    UArray and Repa support efficient multi-dimensional arrays. Repa also has a rich interface for doing so. Vector on its own does not.


    Notable mentions:

    • hmatrix, a custom array type with extensive bindings to linear algebra packages. Should be bound to use the vector or repa types.
    • ix-shapeable, getting more flexible indexing from regular arrays
    • chalkboard, Andy Gill’s library for manipulating 2D images
    • codec-image-devil, read and write various image formats to UArray
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project in C# w/ XNA, and I want to reorganize
Want to know what the stackoverflow community feels about the various free and non-free
Want my FireFox at work to be in sync with my FireFox at my
I want to loop over the contents of a text file and do a
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the
I want to reference a COM DLL in a .NET project, but I also
I want to setup a cron job to rsync a remote system to a
I want to make an etag that matches what Apache produces. How does apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.