0

I am trying to, given an image, generate a new one with twice the original width and height.

I am using the haskell's REPA library (https://hackage.haskell.org/package/repa-3.4.1.2/docs/Data-Array-Repa.html), and following this tutorial (https://wiki.haskell.org/Numeric_Haskell:_A_Repa_Tutorial).

main :: IO () 
main = do
    [f, path] <- getArgs
    (RGB v) <- runIL $ readImage f
        let newImage = (computeS $ twiceSize v) :: Array F DIM3 Word8
        runIL $ writeImage (path) (RGB newImage)

twiceSize :: (Source r e) => Array r DIM3 e -> Array D DIM3 e
twiceSize img = something img newImage
   where
      (Z :. originalWidth :. originalHeight  :. k) = extent img
      newImage = (Z :. originalWidth*2 :. originalHeight*2 :. k)
      something a b = ... 

Now, these are my thoughts:

  • 1) Get the original image width an height

  • 2) Generate a new Array with the right size:

  • 3) Fill the new Array with the original, with some function.

The thing is, I don't really know how to achieve points 2) and 3). What does the "something" function need to do in order to fill the new array? Should I use a map on the newImage?

Thanks in advance.

lehins
  • 9,642
  • 2
  • 35
  • 49
Hamburguesa66
  • 87
  • 1
  • 7
  • 3
    How you accomplish this depends largely on what you want to fill the 'extra' space with. It's entirely ambiguous what you mean by "fill the new array with the original". Do you want to duplicate adjacent elements (use `backpermute`)? Do you want to duplicate the entire array (use `extend`)? Do you want to fill the extra elements with values that don't appear in the original array (use `fromFunction` or `traverse`)? In any case, the last case is most general, but you may get better performance from a more specific transformation based on your intended semantics. – user2407038 Jul 30 '17 at 18:39
  • The "something" function you are looking for is one that does interpolation. Look at the implementation of scale function https://hackage.haskell.org/package/hip-1.5.3.0/docs/Graphics-Image-Processing.html#v:scale as well as Bilinear interpolation in the same library. This library uses repa as a computation backend, so you can get more ideas on how to use repa from it. – lehins Aug 02 '17 at 01:17

0 Answers0