-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell Image Processing (HIP) Library. -- -- Haskell Image Processing (HIP) Library provides an easy to use -- interface with a whole variaty of image manipulation capabilities. -- -- Processing can be done sequentially as well as in parallel, with an -- inherited fusion capabily, all through repa and vector -- packages. It is highly extendable, with an ability to add various -- color spaces or provide implementations for underlying array like -- custom data structures. -- -- It is capable of reading and writing a number of popular image formats -- by using JuciyPixels and netpbm packages. Being a pure -- Haskell library it does not require any external programs, although it -- can display images using a program of your choice. @package hip @version 1.2.0.0 module Graphics.Image.Interface -- | This class has all included color spaces installed into it and is also -- intended for implementing any other possible custom color spaces. -- Every instance of this class automatically installs an associated -- Pixel into Num, Fractional, Floating, -- Functor, Applicative and Foldable, which in turn -- make it possible to be used by the rest of the library. class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs where type PixelElt cs e data Pixel cs e where { type family PixelElt cs e; data family Pixel cs e; } -- | Construt a pixel by replicating a same value among all of the -- channels. fromChannel :: ColorSpace cs => e -> Pixel cs e -- | Convert a Pixel to a representation suitable for storage as an unboxed -- element, usually a tuple of channels. toElt :: ColorSpace cs => Pixel cs e -> PixelElt cs e -- | Convert from an elemnt representation back to a Pixel. fromElt :: ColorSpace cs => PixelElt cs e -> Pixel cs e -- | Retrieve Pixel's channel value getPxCh :: ColorSpace cs => Pixel cs e -> cs -> e -- | Map a channel aware function over all Pixel's channels. chOp :: ColorSpace cs => (cs -> e' -> e) -> Pixel cs e' -> Pixel cs e -- | Map a function over all Pixel's channels. pxOp :: ColorSpace cs => (e' -> e) -> Pixel cs e' -> Pixel cs e -- | Function application to a Pixel. chApp :: ColorSpace cs => Pixel cs (e' -> e) -> Pixel cs e' -> Pixel cs e -- | A pixel eqiuvalent of foldMap. pxFoldMap :: (ColorSpace cs, Monoid m) => (e -> m) -> Pixel cs e -> m -- | Get a pure colour representation of a channel. csColour :: ColorSpace cs => cs -> AlphaColour Double -- | A color space that supports transparency. class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs where type Opaque cs where { type family Opaque cs; } -- | Get an alpha channel of a transparant pixel. getAlpha :: Alpha cs => Pixel cs e -> e -- | Add an alpha channel of an opaque pixel. -- --
-- addAlpha 0 (PixelHSI 1 2 3) == PixelHSIA 1 2 3 0 --addAlpha :: Alpha cs => e -> Pixel (Opaque cs) e -> Pixel cs e -- | Convert a transparent pixel to an opaque one by dropping the alpha -- channel. -- --
-- dropAlpha (PixelRGBA 1 2 3 4) == PixelRGB 1 2 3 --dropAlpha :: Alpha cs => Pixel cs e -> Pixel (Opaque cs) e -- | Get a corresponding opaque channel type. opaque :: Alpha cs => cs -> Opaque cs -- | A class with a set of convenient functions that allow for changing -- precision of channels within pixels, while scaling the values to keep -- them in an appropriate range. -- --
-- >>> let rgb = PixelRGB 0.0 0.5 1.0 :: Pixel RGB Double -- -- >>> toWord8 rgb -- <RGB:(0|128|255)> --class Elevator e toWord8 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word8 toWord16 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word16 toWord32 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word32 toWord64 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word64 toFloat :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Float toDouble :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Double fromDouble :: (Elevator e, ColorSpace cs) => Pixel cs Double -> Pixel cs e -- | Base array like representation for an image. class (Show arr, ColorSpace cs, Num (Pixel cs e), Functor (Pixel cs), Applicative (Pixel cs), Foldable (Pixel cs), Num e, Typeable e, Elt arr cs e) => Array arr cs e where type Elt arr cs e :: Constraint data Image arr cs e type Elt arr cs e = () where { type family Elt arr cs e :: Constraint; data family Image arr cs e; type Elt arr cs e = (); } -- | Create an Image by supplying it's dimensions and a pixel generating -- function. makeImage :: Array arr cs e => (Int, Int) -> ((Int, Int) -> Pixel cs e) -> Image arr cs e -- | Create a singleton image, required for various operations on images -- with a scalar. singleton :: Array arr cs e => Pixel cs e -> Image arr cs e -- | Get dimensions of an image. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> frog -- <Image VectorUnboxed RGB (Double): 200x320> -- -- >>> dims frog -- (200,320) --dims :: Array arr cs e => Image arr cs e -> (Int, Int) -- | Map a function over a an image. map :: (Array arr cs e, Array arr cs' e') => (Pixel cs' e' -> Pixel cs e) -> Image arr cs' e' -> Image arr cs e -- | Map an index aware function over each pixel in an image. imap :: (Array arr cs e, Array arr cs' e') => ((Int, Int) -> Pixel cs' e' -> Pixel cs e) -> Image arr cs' e' -> Image arr cs e -- | Zip two images with a function zipWith :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => (Pixel cs1 e1 -> Pixel cs2 e2 -> Pixel cs e) -> Image arr cs1 e1 -> Image arr cs2 e2 -> Image arr cs e -- | Zip two images with an index aware function izipWith :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => ((Int, Int) -> Pixel cs1 e1 -> Pixel cs2 e2 -> Pixel cs e) -> Image arr cs1 e1 -> Image arr cs2 e2 -> Image arr cs e -- | Traverse an image traverse :: (Array arr cs e, Array arr cs' e') => Image arr cs' e' -> ((Int, Int) -> (Int, Int)) -> (((Int, Int) -> Pixel cs' e') -> (Int, Int) -> Pixel cs e) -> Image arr cs e -- | Traverse two images. traverse2 :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => Image arr cs1 e1 -> Image arr cs2 e2 -> ((Int, Int) -> (Int, Int) -> (Int, Int)) -> (((Int, Int) -> Pixel cs1 e1) -> ((Int, Int) -> Pixel cs2 e2) -> (Int, Int) -> Pixel cs e) -> Image arr cs e -- | Transpose an image transpose :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Backwards permutation of an image. backpermute :: Array arr cs e => (Int, Int) -> ((Int, Int) -> (Int, Int)) -> Image arr cs e -> Image arr cs e -- | Construct an image from a nested rectangular shaped list of pixels. -- Length of an outer list will constitute m rows, while the -- length of inner lists - n columns. All of the inner lists -- must be the same length and greater than 0. fromLists :: Array arr cs e => [[Pixel cs e]] -> Image arr cs e -- | Array representation that is actually has real data stored in memory, -- hence allowing for image indexing, forcing pixels into computed state -- etc. class Array arr cs e => ManifestArray arr cs e where index !img !ix = borderIndex (error $ show img ++ " - Index out of bounds: " ++ show ix) img ix unsafeIndex :: ManifestArray arr cs e => Image arr cs e -> (Int, Int) -> Pixel cs e -- | Get a pixel at i-th and j-th location. -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY $ fromIntegral (i*j)) / (200*200) -- -- >>> index grad_gray (20, 30) == PixelY ((20*30) / (200*200)) -- True --index :: ManifestArray arr cs e => Image arr cs e -> (Int, Int) -> Pixel cs e -- | Make sure that an image is fully evaluated. deepSeqImage :: ManifestArray arr cs e => Image arr cs e -> a -> a -- | Perform matrix multiplication on two images. Inner dimensions must -- agree. (|*|) :: ManifestArray arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e -- | Undirected reduction of an image. fold :: ManifestArray arr cs e => (Pixel cs e -> Pixel cs e -> Pixel cs e) -> Pixel cs e -> Image arr cs e -> Pixel cs e -- | Pixelwise equality function of two images. Images are considered -- distinct if either images' dimensions or at least one pair of -- corresponding pixels are not the same. Used in defining an in instance -- for the Eq typeclass. eq :: (ManifestArray arr cs e, Eq (Pixel cs e)) => Image arr cs e -> Image arr cs e -> Bool -- | Array representation that allows computation, which depends on some -- specific order, consequently making it possible to be computed only -- sequentially. class ManifestArray arr cs e => SequentialArray arr cs e -- | Fold an image from the left in a row major order. foldl :: SequentialArray arr cs e => (a -> Pixel cs e -> a) -> a -> Image arr cs e -> a -- | Fold an image from the right in a row major order. foldr :: SequentialArray arr cs e => (Pixel cs e -> a -> a) -> a -> Image arr cs e -> a -- | Create an Image by supplying it's dimensions and a monadic pixel -- generating action. makeImageM :: (SequentialArray arr cs e, Functor m, Monad m) => (Int, Int) -> ((Int, Int) -> m (Pixel cs e)) -> m (Image arr cs e) -- | Monading mapping over an image. mapM :: (SequentialArray arr cs e, SequentialArray arr cs' e', Functor m, Monad m) => (Pixel cs' e' -> m (Pixel cs e)) -> Image arr cs' e' -> m (Image arr cs e) -- | Monading mapping over an image. Result is discarded. mapM_ :: (SequentialArray arr cs e, Functor m, Monad m) => (Pixel cs e -> m b) -> Image arr cs e -> m () foldM :: (SequentialArray arr cs e, Functor m, Monad m) => (a -> Pixel cs e -> m a) -> a -> Image arr cs e -> m a foldM_ :: (SequentialArray arr cs e, Functor m, Monad m) => (a -> Pixel cs e -> m a) -> a -> Image arr cs e -> m () -- | Array representation that supports mutation. class ManifestArray arr cs e => MutableArray arr cs e where data MImage st arr cs e where { data family MImage st arr cs e; } -- | Get dimensions of a mutable image. mdims :: MutableArray arr cs e => MImage st arr cs e -> (Int, Int) -- | Yield a mutable copy of an image. thaw :: (MutableArray arr cs e, Functor m, PrimMonad m) => Image arr cs e -> m (MImage (PrimState m) arr cs e) -- | Yield an immutable copy of an image. freeze :: (MutableArray arr cs e, Functor m, PrimMonad m) => MImage (PrimState m) arr cs e -> m (Image arr cs e) -- | Create a mutable image with given dimensions. Pixels are likely -- uninitialized. new :: (MutableArray arr cs e, Functor m, PrimMonad m) => (Int, Int) -> m (MImage (PrimState m) arr cs e) -- | Yield the pixel at a given location. read :: (MutableArray arr cs e, Functor m, PrimMonad m) => MImage (PrimState m) arr cs e -> (Int, Int) -> m (Pixel cs e) -- | Set a pixel at a given location. write :: (MutableArray arr cs e, Functor m, PrimMonad m) => MImage (PrimState m) arr cs e -> (Int, Int) -> Pixel cs e -> m () -- | Swap pixels at given locations. swap :: (MutableArray arr cs e, Functor m, PrimMonad m) => MImage (PrimState m) arr cs e -> (Int, Int) -> (Int, Int) -> m () -- | Allows for changing an underlying image representation. class Exchangable arr' arr -- | Exchange the underlying array representation of an image. exchange :: (Exchangable arr' arr, Array arr' cs e, Array arr cs e) => arr -> Image arr' cs e -> Image arr cs e -- | exchange function that is allows restricting the representation -- type of source image. exchangeFrom :: (Exchangable arr' arr, Array arr' cs e, Array arr cs e) => arr' -> arr -> Image arr' cs e -> Image arr cs e -- | Image indexing function that returns a default pixel if index is out -- of bounds. defaultIndex :: ManifestArray arr cs e => Pixel cs e -> Image arr cs e -> (Int, Int) -> Pixel cs e -- | Image indexing function that uses a special border resolutions -- strategy for out of bounds pixels. borderIndex :: ManifestArray arr cs e => Border (Pixel cs e) -> Image arr cs e -> (Int, Int) -> Pixel cs e -- | Image indexing function that returns Nothing if index -- is out of bounds, Just px otherwise. maybeIndex :: ManifestArray arr cs e => Image arr cs e -> (Int, Int) -> Maybe (Pixel cs e) -- | Approach to be used near the borders during various transformations. -- Whenever a function needs information not only about a pixel of -- interest, but also about it's neighbours, it will go out of bounds -- around the image edges, hence is this set of approaches that can be -- used in such situtation. data Border px -- | Fill in a constant pixel. -- --
-- outside | Image | outside -- (Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0 --Fill :: !px -> Border px -- | Wrap around from the opposite border of the image. -- --
-- outside | Image | outside -- Wrap : 1 2 3 4 | 1 2 3 4 | 1 2 3 4 --Wrap :: Border px -- | Replicate the pixel at the edge. -- --
-- outside | Image | outside -- Edge : 1 1 1 1 | 1 2 3 4 | 4 4 4 4 --Edge :: Border px -- | Mirror like reflection. -- --
-- outside | Image | outside -- Reflect : 4 3 2 1 | 1 2 3 4 | 4 3 2 1 --Reflect :: Border px -- | Also mirror like reflection, but without repeating the edge pixel. -- --
-- outside | Image | outside -- Continue : 1 4 3 2 | 1 2 3 4 | 3 2 1 4 --Continue :: Border px -- | Border handling function. If (i, j) location is within -- bounds, then supplied lookup function will be used, otherwise it will -- be handled according to a supplied border strategy. handleBorderIndex :: Border px -> (Int, Int) -> ((Int, Int) -> px) -> (Int, Int) -> px instance GHC.Show.Show px => GHC.Show.Show (Graphics.Image.Interface.Border px) instance Graphics.Image.Interface.Exchangable arr arr instance Graphics.Image.Interface.ColorSpace cs => GHC.Base.Functor (Graphics.Image.Interface.Pixel cs) instance Graphics.Image.Interface.ColorSpace cs => GHC.Base.Applicative (Graphics.Image.Interface.Pixel cs) instance Graphics.Image.Interface.ColorSpace cs => Data.Foldable.Foldable (Graphics.Image.Interface.Pixel cs) instance (Graphics.Image.Interface.ColorSpace cs, GHC.Num.Num e) => GHC.Num.Num (Graphics.Image.Interface.Pixel cs e) instance (Graphics.Image.Interface.ColorSpace cs, GHC.Real.Fractional e) => GHC.Real.Fractional (Graphics.Image.Interface.Pixel cs e) instance (Graphics.Image.Interface.ColorSpace cs, GHC.Float.Floating e) => GHC.Float.Floating (Graphics.Image.Interface.Pixel cs e) instance (Graphics.Image.Interface.ColorSpace cs, GHC.Enum.Bounded e) => GHC.Enum.Bounded (Graphics.Image.Interface.Pixel cs e) instance (Graphics.Image.Interface.ManifestArray arr cs e, GHC.Classes.Eq (Graphics.Image.Interface.Pixel cs e)) => GHC.Classes.Eq (Graphics.Image.Interface.Image arr cs e) instance Graphics.Image.Interface.Array arr cs e => GHC.Num.Num (Graphics.Image.Interface.Image arr cs e) instance (GHC.Real.Fractional (Graphics.Image.Interface.Pixel cs e), Graphics.Image.Interface.Array arr cs e) => GHC.Real.Fractional (Graphics.Image.Interface.Image arr cs e) instance (GHC.Float.Floating (Graphics.Image.Interface.Pixel cs e), Graphics.Image.Interface.Array arr cs e) => GHC.Float.Floating (Graphics.Image.Interface.Image arr cs e) instance Graphics.Image.Interface.ManifestArray arr cs e => Control.DeepSeq.NFData (Graphics.Image.Interface.Image arr cs e) instance Graphics.Image.Interface.Array arr cs e => GHC.Show.Show (Graphics.Image.Interface.Image arr cs e) instance Graphics.Image.Interface.MutableArray arr cs e => GHC.Show.Show (Graphics.Image.Interface.MImage st arr cs e) module Graphics.Image.Processing -- | Downsample an image by discarding every odd row. downsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Downsample an image by discarding every odd column. downsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Downsample an image by discarding every odd row and column. downsample :: Array arr cs e => Image arr cs e -> Image arr cs e downsampleF :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e -- | Upsample an image by inserting a row of back pixels after each row of -- a source image. upsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Upsample an image by inserting a column of back pixels after each -- column of a source image. upsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Upsample an image by inserting a row and a column of back pixels after -- each row and a column of a source image. upsample :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Upsample an image by a positive factor. Every upsampleF :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e -- | Concatenate two images together into one. Both input images must have -- the same number of rows. leftToRight :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e -- | Concatenate two images together into one. Both input images must have -- the same number of columns. topToBottom :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e translate :: Array arr cs e => Border (Pixel cs e) -> (Int, Int) -> Image arr cs e -> Image arr cs e -- | Crop an image, i.e. retrieves a sub-image image with m rows -- and n columns. Make sure (i + m, j + n) is not -- greater than dimensions of a source image. crop :: Array arr cs e => (Int, Int) -> (Int, Int) -> Image arr cs e -> Image arr cs e -- | Place one image on top of a source image, starting at a particular -- location within a source image. superimpose :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e -> Image arr cs e -- | Flip an image vertically. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_flipV.jpg" $ flipV frog ---- flipV :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Flip an image horizontally. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_flipH.jpg" $ flipH frog ---- flipH :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Rotate an image clockwise by 90°. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_rotate90.jpg" $ rotate90 frog ---- rotate90 :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Rotate an image by 180°. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_rotate180.jpg" $ rotate180 frog ---- rotate180 :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Rotate an image clockwise by 270°. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_rotate270.jpg" $ rotate270 frog ---- rotate270 :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Rotate an image clockwise by an angle Θ in radians. -- --
-- >>> frog <- readImageRGBA "images/frog.jpg" -- -- >>> writeImage "images/frog_rotate330.png" $ rotate Bilinear (Fill 0) (11*pi/6) frog ---- rotate :: (Array arr cs e, Elevator e, Interpolation method) => method -> Border (Pixel cs e) -> Double -> Image arr cs e -> Image arr cs e -- | Resize an image using an interpolation method. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_resize.jpg" $ resize Bilinear Edge (100, 640) frog ---- resize :: (Interpolation method, Array arr cs e, Elevator e) => method -> Border (Pixel cs e) -> (Int, Int) -> Image arr cs e -> Image arr cs e -- | Scale an image. Same as resize, except scaling factors are supplied -- instead of new dimensions. -- --
-- scale Bilinear Edge (0.5, 2) frog == resize Bilinear Edge (100, 640) frog --scale :: (Interpolation method, Array arr cs e, Elevator e) => method -> Border (Pixel cs e) -> (Double, Double) -> Image arr cs e -> Image arr cs e -- | Implementation for an interpolation method. class Interpolation method -- | Construct a new pixel by using information from neighboring pixels. interpolate :: (Interpolation method, Elevator e, Num e, ColorSpace cs) => method -> Border (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e -- | Nearest Neighbor interpolation method. data Nearest Nearest :: Nearest -- | Bilinear interpolation method. data Bilinear Bilinear :: Bilinear -- | Convolution of an image using a kernel. Border resolution technique is -- required. -- -- Example using Sobel operator: -- --
-- >>> frog <- readImageY "frog.jpg" -- -- >>> let frogX = convolve Edge (fromLists [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) frog -- -- >>> let frogY = convolve Edge (fromLists [[-1,-2,-1], [ 0, 0, 0], [ 1, 2, 1]]) frog -- -- >>> displayImage $ normalize $ sqrt (frogX ^ 2 + frogY ^ 2) ---- convolve :: ManifestArray arr cs e => Border (Pixel cs e) -> Image arr cs e -> Image arr cs e -> Image arr cs e -- | Convolve image's rows with a vector kernel represented by a list of -- pixels. convolveRows :: ManifestArray arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e -- | Convolve image's columns with a vector kernel represented by a list of -- pixels. convolveCols :: ManifestArray arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e -- | Approach to be used near the borders during various transformations. -- Whenever a function needs information not only about a pixel of -- interest, but also about it's neighbours, it will go out of bounds -- around the image edges, hence is this set of approaches that can be -- used in such situtation. data Border px -- | Fill in a constant pixel. -- --
-- outside | Image | outside -- (Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0 --Fill :: !px -> Border px -- | Wrap around from the opposite border of the image. -- --
-- outside | Image | outside -- Wrap : 1 2 3 4 | 1 2 3 4 | 1 2 3 4 --Wrap :: Border px -- | Replicate the pixel at the edge. -- --
-- outside | Image | outside -- Edge : 1 1 1 1 | 1 2 3 4 | 4 4 4 4 --Edge :: Border px -- | Mirror like reflection. -- --
-- outside | Image | outside -- Reflect : 4 3 2 1 | 1 2 3 4 | 4 3 2 1 --Reflect :: Border px -- | Also mirror like reflection, but without repeating the edge pixel. -- --
-- outside | Image | outside -- Continue : 1 4 3 2 | 1 2 3 4 | 3 2 1 4 --Continue :: Border px -- | This function magnifies an image by a positive factor and draws a grid -- around the original pixels. It is here simply as useful inspection -- tool. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeImage "images/frog_eye_grid.png" $ pixelGrid 10 $ crop (51, 112) (20, 20) frog ---- pixelGrid :: (Array arr cs e, Elevator e) => Word8 -> Image arr cs e -> Image arr cs e module Graphics.Image.Processing.Complex -- | Construct a complex image from two images representing real and -- imaginary parts. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> frog !+! 0 -- <Image VectorUnboxed RGB (Complex Double): 200x320> -- -- >>> frog !+! frog -- <Image VectorUnboxed RGB (Complex Double): 200x320> --(!+!) :: (Array arr cs e, Array arr cs (Complex e)) => Image arr cs e -> Image arr cs e -> Image arr cs (Complex e) infix 6 !+! -- | Extracts the real part of a complex image. realPart' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs e -- | Extracts the imaginary part of a complex image. imagPart' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs e -- | Form a complex image from polar components of magnitude and phase. mkPolar' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs e -> Image arr cs e -> Image arr cs (Complex e) -- | cis' t is a complex image with magnitude 1 and phase t -- (modulo 2*pi). cis' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs e -> Image arr cs (Complex e) -- | The function polar' takes a complex image and returns -- a (magnitude, phase) pair of images in canonical form: the magnitude -- is nonnegative, and the phase in the range (-pi, -- pi]; if the magnitude is zero, then so is the phase. polar' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> (Image arr cs e, Image arr cs e) -- | The nonnegative magnitude of a complex image. magnitude' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs e -- | The phase of a complex image, in the range (-pi, -- pi]. If the magnitude is zero, then so is the phase. phase' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs e -- | The conjugate of a complex image. conjugate' :: (Array arr cs e, Array arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs (Complex e) -- | Make a filter by using a function that works around a regular (x, -- y) coordinate system. makeFilter :: (ManifestArray arr cs e, RealFloat e) => (Int, Int) -> ((Int, Int) -> Pixel cs e) -> Image arr cs e -- | Apply a filter to an image created by makeFilter. applyFilter :: (ManifestArray arr cs e, ManifestArray arr cs (Complex e), RealFloat e) => Image arr cs e -> Image arr cs e -> Image arr cs e -- | Fast Fourier Transform fft :: (ManifestArray arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs (Complex e) -- | Inverse Fast Fourier Transform ifft :: (ManifestArray arr cs (Complex e), RealFloat e) => Image arr cs (Complex e) -> Image arr cs (Complex e) module Graphics.Image.ColorSpace -- | This class has all included color spaces installed into it and is also -- intended for implementing any other possible custom color spaces. -- Every instance of this class automatically installs an associated -- Pixel into Num, Fractional, Floating, -- Functor, Applicative and Foldable, which in turn -- make it possible to be used by the rest of the library. class (Eq cs, Enum cs, Show cs, Typeable cs) => ColorSpace cs where data Pixel cs e where { data family Pixel cs e; } -- | A color space that supports transparency. class (ColorSpace (Opaque cs), ColorSpace cs) => Alpha cs where type Opaque cs where { type family Opaque cs; } -- | A class with a set of convenient functions that allow for changing -- precision of channels within pixels, while scaling the values to keep -- them in an appropriate range. -- --
-- >>> let rgb = PixelRGB 0.0 0.5 1.0 :: Pixel RGB Double -- -- >>> toWord8 rgb -- <RGB:(0|128|255)> --class Elevator e toWord8 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word8 toWord16 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word16 toWord32 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word32 toWord64 :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Word64 toFloat :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Float toDouble :: (Elevator e, ColorSpace cs) => Pixel cs e -> Pixel cs Double fromDouble :: (Elevator e, ColorSpace cs) => Pixel cs Double -> Pixel cs e -- | Luma or brightness, that is usually denoted as Y'. data Y Y :: Y -- | Luma with Alpha channel. data YA -- | Luma YA :: YA -- | Alpha channel AlphaYA :: YA -- | Conversion to Luma color space. class ColorSpace cs => ToY cs where toImageY = map toPixelY -- | Convert a pixel to Luma pixel. toPixelY :: ToY cs => Pixel cs Double -> Pixel Y Double -- | Convert an image to Luma image. toImageY :: (ToY cs, Array arr cs Double, Array arr Y Double) => Image arr cs Double -> Image arr Y Double -- | Conversion to Luma from another color space with Alpha channel. class (ToY (Opaque cs), Alpha cs) => ToYA cs where toPixelYA px = addAlpha (getAlpha px) (toPixelY (dropAlpha px)) toImageYA = map toPixelYA -- | Convert a pixel to Luma pixel with Alpha. toPixelYA :: ToYA cs => Pixel cs Double -> Pixel YA Double -- | Convert an image to Luma image with Alpha. toImageYA :: (ToYA cs, Array arr cs Double, Array arr YA Double) => Image arr cs Double -> Image arr YA Double -- | Red, Green and Blue color space. data RGB RedRGB :: RGB GreenRGB :: RGB BlueRGB :: RGB -- | Red, Green and Blue color space with Alpha channel. data RGBA RedRGBA :: RGBA GreenRGBA :: RGBA BlueRGBA :: RGBA AlphaRGBA :: RGBA -- | Conversion to RGB color space. class ColorSpace cs => ToRGB cs where toImageRGB = map toPixelRGB -- | Convert to an RGB pixel. toPixelRGB :: ToRGB cs => Pixel cs Double -> Pixel RGB Double -- | Convert to an RGB image. toImageRGB :: (ToRGB cs, Array arr cs Double, Array arr RGB Double) => Image arr cs Double -> Image arr RGB Double -- | Conversion to RGBA from another color space with Alpha channel. class (ToRGB (Opaque cs), Alpha cs) => ToRGBA cs where toPixelRGBA px = addAlpha (getAlpha px) (toPixelRGB (dropAlpha px)) toImageRGBA = map toPixelRGBA -- | Convert to an RGBA pixel. toPixelRGBA :: ToRGBA cs => Pixel cs Double -> Pixel RGBA Double -- | Convert to an RGBA image. toImageRGBA :: (ToRGBA cs, Array arr cs Double, Array arr RGBA Double) => Image arr cs Double -> Image arr RGBA Double -- | Hue, Saturation and Intensity color space. data HSI -- | Hue HueHSI :: HSI -- | Saturation SatHSI :: HSI -- | Intensity IntHSI :: HSI -- | Hue, Saturation and Intensity color space with Alpha channel. data HSIA -- | Hue HueHSIA :: HSIA -- | Saturation SatHSIA :: HSIA -- | Intensity IntHSIA :: HSIA -- | Alpha AlphaHSIA :: HSIA -- | Conversion to HSI color space. class ColorSpace cs => ToHSI cs where toImageHSI = map toPixelHSI -- | Convert to an HSI pixel. toPixelHSI :: ToHSI cs => Pixel cs Double -> Pixel HSI Double -- | Convert to an HSI image. toImageHSI :: (ToHSI cs, Array arr cs Double, Array arr HSI Double) => Image arr cs Double -> Image arr HSI Double -- | Conversion to HSIA from another color space with Alpha channel. class (ToHSI (Opaque cs), Alpha cs) => ToHSIA cs where toPixelHSIA px = addAlpha (getAlpha px) (toPixelHSI (dropAlpha px)) toImageHSIA = map toPixelHSIA -- | Convert to an HSIA pixel. toPixelHSIA :: ToHSIA cs => Pixel cs Double -> Pixel HSIA Double -- | Convert to an HSIA image. toImageHSIA :: (ToHSIA cs, Array arr cs Double, Array arr HSIA Double) => Image arr cs Double -> Image arr HSIA Double -- | Cyan, Magenta, Yellow and Black color space. data CMYK -- | Cyan CyanCMYK :: CMYK -- | Magenta MagCMYK :: CMYK -- | Yellow YelCMYK :: CMYK -- | Key (Black) KeyCMYK :: CMYK -- | Cyan, Magenta, Yellow and Black color space with Alpha channel. data CMYKA -- | Cyan CyanCMYKA :: CMYKA -- | Magenta MagCMYKA :: CMYKA -- | Yellow YelCMYKA :: CMYKA -- | Key (Black) KeyCMYKA :: CMYKA -- | Alpha AlphaCMYKA :: CMYKA -- | Conversion to CMYK color space. class ColorSpace cs => ToCMYK cs where toImageCMYK = map toPixelCMYK -- | Convert to a CMYK pixel. toPixelCMYK :: ToCMYK cs => Pixel cs Double -> Pixel CMYK Double -- | Convert to a CMYK image. toImageCMYK :: (ToCMYK cs, Array arr cs Double, Array arr CMYK Double) => Image arr cs Double -> Image arr CMYK Double -- | Conversion to CMYKA from another color space with Alpha -- channel. class (ToCMYK (Opaque cs), Alpha cs) => ToCMYKA cs where toPixelCMYKA px = addAlpha (getAlpha px) (toPixelCMYK (dropAlpha px)) toImageCMYKA = map toPixelCMYKA -- | Convert to a CMYKA pixel. toPixelCMYKA :: ToCMYKA cs => Pixel cs Double -> Pixel CMYKA Double -- | Convert to a CMYKA image. toImageCMYKA :: (ToCMYKA cs, Array arr cs Double, Array arr CMYKA Double) => Image arr cs Double -> Image arr CMYKA Double -- | Color space is used to encode RGB information and is used in JPEG -- compression. data YCbCr -- | Luma component (commonly denoted as Y') LumaYCbCr :: YCbCr -- | Blue difference chroma component CBlueYCbCr :: YCbCr -- | Red difference chroma component CRedYCbCr :: YCbCr -- | YCbCr color space with Alpha channel. data YCbCrA -- | Luma component (commonly denoted as Y') LumaYCbCrA :: YCbCrA -- | Blue difference chroma component CBlueYCbCrA :: YCbCrA -- | Red difference chroma component CRedYCbCrA :: YCbCrA -- | Alpha component. AlphaYCbCrA :: YCbCrA -- | Conversion to YCbCr color space. class ColorSpace cs => ToYCbCr cs where toImageYCbCr = map toPixelYCbCr -- | Convert to an YCbCr pixel. toPixelYCbCr :: ToYCbCr cs => Pixel cs Double -> Pixel YCbCr Double -- | Convert to an YCbCr image. toImageYCbCr :: (ToYCbCr cs, Array arr cs Double, Array arr YCbCr Double) => Image arr cs Double -> Image arr YCbCr Double -- | Conversion to YCbCrA from another color space with Alpha -- channel. class (ToYCbCr (Opaque cs), Alpha cs) => ToYCbCrA cs where toPixelYCbCrA px = addAlpha (getAlpha px) (toPixelYCbCr (dropAlpha px)) toImageYCbCrA = map toPixelYCbCrA -- | Convert to an YCbCrA pixel. toPixelYCbCrA :: ToYCbCrA cs => Pixel cs Double -> Pixel YCbCrA Double -- | Convert to an YCbCrA image. toImageYCbCrA :: (ToYCbCrA cs, Array arr cs Double, Array arr YCbCrA Double) => Image arr cs Double -> Image arr YCbCrA Double -- | This is a signgle channel colorspace, that is designed to hold any -- channel from any other colorspace, hence it is not convertible to and -- from, but rather is here to allow separation of channels from other -- multichannel colorspaces. If you are looking for a true grayscale -- colorspace Y should be used instead. data Gray Gray :: Gray -- | Separate an image into a list of images with Gray pixels -- containing every channel from the source image. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> let [frog_red, frog_green, frog_blue] = toGrayImages frog -- -- >>> writeImage "images/frog_red.png" $ toImageY frog_red -- -- >>> writeImage "images/frog_green.jpg" $ toImageY frog_green -- -- >>> writeImage "images/frog_blue.jpg" $ toImageY frog_blue ---- toGrayImages :: (Array arr cs e, Array arr Gray e) => Image arr cs e -> [Image arr Gray e] -- | Combine a list of images with Gray pixels into an image of any -- color space, by supplying an order of color space channels. -- -- For example here is a frog with swapped BlueRGB and -- GreenRGB channels. -- --
-- >>> writeImage "images/frog_rbg.jpg" $ fromGrayImages [frog_red, frog_green, frog_blue] [RedRGB, BlueRGB, GreenRGB] ---- -- -- It is worth noting though, that separating image channels can be -- sometimes pretty useful, the same effect as above can be achieved in a -- much simpler and more efficient way: -- --
-- map ((PixelRGB r g b) -> PixelRGB r b g) frog --fromGrayImages :: forall arr cs e. (Array arr Gray e, Array arr cs e) => [Image arr Gray e] -> [cs] -> Image arr cs e -- | This is a Binary colorspace, pixel's of which can be created using -- these constructors: -- --
-- >>> on + on -- equivalent to: 1 .|. 1 -- <Binary:(1)> -- -- >>> (on + on) * off -- equivalent to: (1 .|. 1) .&. 0 -- <Binary:(0)> -- -- >>> (on + on) - on -- <Binary:(0)> --data Binary -- | Under the hood, Binary pixels are represented as Word8 that can -- only take values of 0 or 1. data Bit -- | Represents value True or 1 in binary. Often also -- called a foreground pixel of an object. on :: Pixel Binary Bit -- | Represents value False or 0 in binary. Often also -- called a background pixel. off :: Pixel Binary Bit -- | Test if Pixel's value is on. isOn :: Pixel Binary Bit -> Bool -- | Test if Pixel's value is off. isOff :: Pixel Binary Bit -> Bool -- | Convert a Bool to a PixelBin pixel. -- --
-- >>> isOn (fromBool True) -- True --fromBool :: Bool -> Pixel Binary Bit -- | Invert value of a pixel. Equivalent of not for Bool's. complement :: Pixel Binary Bit -> Pixel Binary Bit -- | Convert any pixel to binary pixel. toPixelBinary :: (ColorSpace cs, Eq (Pixel cs e), Num e) => Pixel cs e -> Pixel Binary Bit -- | Convert a Binary pixel to Luma pixel fromPixelBinary :: Pixel Binary Bit -> Pixel Y Word8 -- | Convert any image to binary image. toImageBinary :: (Array arr cs e, Array arr Binary Bit, Eq (Pixel cs e)) => Image arr cs e -> Image arr Binary Bit -- | Convert a Binary image to Luma image fromImageBinary :: (Array arr Binary Bit, Array arr Y Word8) => Image arr Binary Bit -> Image arr Y Word8 -- | Complex numbers are an algebraic type. -- -- For a complex number z, abs z is a number -- with the magnitude of z, but oriented in the positive real -- direction, whereas signum z has the phase of -- z, but unit magnitude. -- -- The Foldable and Traversable instances traverse the real -- part first. data Complex a :: * -> * -- | forms a complex number from its real and imaginary rectangular -- components. (:+) :: ~a -> ~a -> Complex a -- | Constrcut a complex pixel from two pixels representing real and -- imaginary parts. -- --
-- PixelRGB 4 8 6 +: PixelRGB 7 1 1 == PixelRGB (4 :+ 7) (8 :+ 1) (6 :+ 1) --(+:) :: ColorSpace cs => Pixel cs e -> Pixel cs e -> Pixel cs (Complex e) infix 6 +: -- | Extracts the real part of a complex pixel. realPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e -- | Extracts the imaginary part of a complex pixel. imagPart :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e -- | Form a complex pixel from polar components of magnitude and phase. mkPolar :: (ColorSpace cs, RealFloat e) => Pixel cs e -> Pixel cs e -> Pixel cs (Complex e) -- | cis t is a complex pixel with magnitude 1 and phase t -- (modulo 2*pi). cis :: (ColorSpace cs, RealFloat e) => Pixel cs e -> Pixel cs (Complex e) -- | The function polar takes a complex pixel and returns a -- (magnitude, phase) pair of pixels in canonical form: the magnitude is -- nonnegative, and the phase in the range (-pi, -- pi]; if the magnitude is zero, then so is the phase. polar :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> (Pixel cs e, Pixel cs e) -- | The nonnegative magnitude of a complex pixel. magnitude :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e -- | The phase of a complex pixel, in the range (-pi, -- pi]. If the magnitude is zero, then so is the phase. phase :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs e -- | The conjugate of a complex pixel. conjugate :: (ColorSpace cs, RealFloat e) => Pixel cs (Complex e) -> Pixel cs (Complex e) -- | 8-bit unsigned integer type data Word8 :: * -- | 16-bit unsigned integer type data Word16 :: * -- | 32-bit unsigned integer type data Word32 :: * -- | 64-bit unsigned integer type data Word64 :: * instance Graphics.Image.ColorSpace.Luma.ToY Graphics.Image.ColorSpace.Gray.Gray instance Graphics.Image.ColorSpace.Luma.ToY Graphics.Image.ColorSpace.RGB.RGB instance Graphics.Image.ColorSpace.Luma.ToYA Graphics.Image.ColorSpace.RGB.RGBA instance Graphics.Image.ColorSpace.Luma.ToY Graphics.Image.ColorSpace.HSI.HSI instance Graphics.Image.ColorSpace.Luma.ToYA Graphics.Image.ColorSpace.HSI.HSIA instance Graphics.Image.ColorSpace.Luma.ToY Graphics.Image.ColorSpace.CMYK.CMYK instance Graphics.Image.ColorSpace.Luma.ToY Graphics.Image.ColorSpace.YCbCr.YCbCr instance Graphics.Image.ColorSpace.Luma.ToYA Graphics.Image.ColorSpace.YCbCr.YCbCrA instance Graphics.Image.ColorSpace.RGB.ToRGB Graphics.Image.ColorSpace.Luma.Y instance Graphics.Image.ColorSpace.RGB.ToRGBA Graphics.Image.ColorSpace.Luma.YA instance Graphics.Image.ColorSpace.RGB.ToRGB Graphics.Image.ColorSpace.HSI.HSI instance Graphics.Image.ColorSpace.RGB.ToRGBA Graphics.Image.ColorSpace.HSI.HSIA instance Graphics.Image.ColorSpace.RGB.ToRGB Graphics.Image.ColorSpace.YCbCr.YCbCr instance Graphics.Image.ColorSpace.RGB.ToRGBA Graphics.Image.ColorSpace.YCbCr.YCbCrA instance Graphics.Image.ColorSpace.RGB.ToRGB Graphics.Image.ColorSpace.CMYK.CMYK instance Graphics.Image.ColorSpace.RGB.ToRGBA Graphics.Image.ColorSpace.CMYK.CMYKA instance Graphics.Image.ColorSpace.HSI.ToHSI Graphics.Image.ColorSpace.Luma.Y instance Graphics.Image.ColorSpace.HSI.ToHSIA Graphics.Image.ColorSpace.Luma.YA instance Graphics.Image.ColorSpace.HSI.ToHSI Graphics.Image.ColorSpace.RGB.RGB instance Graphics.Image.ColorSpace.HSI.ToHSIA Graphics.Image.ColorSpace.RGB.RGBA instance Graphics.Image.ColorSpace.YCbCr.ToYCbCr Graphics.Image.ColorSpace.RGB.RGB instance Graphics.Image.ColorSpace.YCbCr.ToYCbCrA Graphics.Image.ColorSpace.RGB.RGBA instance Graphics.Image.ColorSpace.CMYK.ToCMYK Graphics.Image.ColorSpace.RGB.RGB instance Graphics.Image.ColorSpace.CMYK.ToCMYKA Graphics.Image.ColorSpace.RGB.RGBA instance Graphics.Image.Interface.Elevator GHC.Word.Word8 instance Graphics.Image.Interface.Elevator GHC.Word.Word16 instance Graphics.Image.Interface.Elevator GHC.Word.Word32 instance Graphics.Image.Interface.Elevator GHC.Word.Word64 instance Graphics.Image.Interface.Elevator GHC.Types.Float instance Graphics.Image.Interface.Elevator GHC.Types.Double module Graphics.Image.IO.Formats -- | Bitmap image with .bmp extension. data BMP BMP :: BMP -- | Graphics Interchange Format image with .gif extension. data GIF GIF :: GIF -- | Delay to wait before showing the next Gif image. The delay is -- expressed in 100th of seconds. type GifDelay = Int -- | Help to control the behaviour of GIF animation looping. data GifLooping :: * -- | The animation will stop once the end is reached LoopingNever :: GifLooping -- | The animation will restart once the end is reached LoopingForever :: GifLooping -- | The animation will repeat n times before stoping LoopingRepeat :: Word16 -> GifLooping -- | To specify how the palette will be created. data PaletteOptions :: * PaletteOptions :: PaletteCreationMethod -> Bool -> Int -> PaletteOptions -- | Algorithm used to find the palette [paletteCreationMethod] :: PaletteOptions -> PaletteCreationMethod -- | Do we want to apply the dithering to the image. Enabling it often -- reduce compression ratio but enhance the perceived quality of the -- final image. [enableImageDithering] :: PaletteOptions -> Bool -- | Maximum number of color we want in the palette [paletteColorCount] :: PaletteOptions -> Int -- | Define which palette creation method is used. data PaletteCreationMethod :: * -- | MedianMeanCut method, provide the best results (visualy) at the cost -- of increased calculations. MedianMeanCut :: PaletteCreationMethod -- | Very fast algorithm (one pass), doesn't provide good looking results. Uniform :: PaletteCreationMethod -- | High-dynamic-range image with .hdr or .pic -- extension. data HDR HDR :: HDR -- | Joint Photographic Experts Group image with .jpg or -- .jpeg extension. data JPG JPG :: JPG -- | Portable Network Graphics image with .png extension. data PNG PNG :: PNG -- | Truevision Graphics Adapter image with .tga extension. data TGA TGA :: TGA -- | Tagged Image File Format image with .tif or .tiff -- extension. data TIF TIF :: TIF -- | Netpbm: portable bitmap image with .pbm extension. data PBM PBM :: PBM -- | Netpbm: portable graymap image with .pgm extension. data PGM PGM :: PGM -- | Netpbm: portable pixmap image with .ppm extension. data PPM PPM :: PPM -- | A collection of all image formats that can be read into HIP images -- with Double precision pixel channels. data InputFormat -- | A collection of all image formats that can be written to file using -- images with Double precision pixels. data OutputFormat -- | Image formats that can be read from file. class ImageFormat format => Readable img format -- | Decode an image from ByteString. decode :: Readable img format => format -> ByteString -> Either String img -- | Image formats that can be written to file. class ImageFormat format => Writable img format -- | Encode an image to ByteString. encode :: Writable img format => format -> [SaveOption format] -> img -> ByteString -- | Image file format. Helps in guessing image format using a file -- extension, as well as supplying format specific options during saving -- an image. class ImageFormat format where data SaveOption format exts f = [ext f] isFormat e f = e `elem` exts f where { data family SaveOption format; } -- | Default file extension for this image format. ext :: ImageFormat format => format -> String -- | Known extensions for this image format. exts :: ImageFormat format => format -> [String] -- | Returns True if a file extension (ex. ".png") -- corresponds to this format. isFormat :: ImageFormat format => String -> format -> Bool instance GHC.Classes.Eq Graphics.Image.IO.Formats.OutputFormat instance GHC.Enum.Enum Graphics.Image.IO.Formats.OutputFormat instance GHC.Show.Show Graphics.Image.IO.Formats.OutputFormat instance GHC.Classes.Eq Graphics.Image.IO.Formats.InputFormat instance GHC.Enum.Enum Graphics.Image.IO.Formats.InputFormat instance GHC.Show.Show Graphics.Image.IO.Formats.InputFormat instance Graphics.Image.IO.Base.ImageFormat Graphics.Image.IO.Formats.InputFormat instance (Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.BMP, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.GIF, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.HDR, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.JPG, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.PNG, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.TGA, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.TIF, Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.Netpbm.PPM) => Graphics.Image.IO.Base.Readable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.InputFormat instance Graphics.Image.IO.Base.ImageFormat Graphics.Image.IO.Formats.OutputFormat instance (Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.BMP, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.GIF, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.HDR, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.JPG, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.PNG, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.TGA, Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.JuicyPixels.TIF) => Graphics.Image.IO.Base.Writable (Graphics.Image.Interface.Image arr cs GHC.Types.Double) Graphics.Image.IO.Formats.OutputFormat module Graphics.Image.IO -- | This function will try to guess an image format from file's extension, -- then it will attempt to read it as such. It will fall back onto the -- rest of the supported formats and will try to read them regarless of -- file's extension. Whenever image cannot be decoded, Left -- containing all errors for each attempted format will be returned, and -- Right containing an image otherwise. Image will be read into a -- type signature specified ColorSpace (Y, YA, -- RGB and RGBA only) with Double precision, while -- doing all necessary conversions. readImage :: Readable (Image arr cs Double) InputFormat => FilePath -> IO (Either String (Image arr cs Double)) -- | This function allows for reading any supported image in the exact -- colorspace and precision it is currently encoded in. For instance, -- frog image can be read into it's YCbCr colorspace with -- Word8 precision and into any supported array representation. -- --
-- >>> readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RP YCbCr Word8)) -- Right <Image RepaParallel YCbCr (Word8): 200x320> ---- -- The drawback here is that colorspace and precision has to match -- exactly, otherwise it will return an error: -- --
-- >>> readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RD RGB Word8)) -- Left "JuicyPixel decoding error: Input image is in YCbCr8 (Pixel YCbCr Word8), cannot convert it to RGB8 (Pixel RGB Word8) colorspace." ---- -- Attempt to read an image in a particular color space that is not -- supported by the format, will result in a compile error. Refer to -- Readable class for all images that can be decoded. readImageExact :: Readable img format => format -> FilePath -> IO (Either String img) -- | Just like readImage, this function will guess an output file -- format from the extension and write to file any image that is in one -- of Y, YA, RGB or RGBA color spaces with -- Double precision. While doing necessary conversions the choice -- will be given to the most suited color space supported by the format. -- For instance, in case of a PNG format, an (Image -- arr RGBA Double) would be written as -- RGBA16, hence preserving transparency and using highest -- supported precision Word16. At the same time, writing that -- image in GIF format would save it in RGB8, since -- Word8 is the highest precision GIF supports and it -- currently cannot be saved with transparency. writeImage :: Writable (Image arr cs e) OutputFormat => FilePath -> Image arr cs e -> IO () -- | Write an image in a specific format, while supplying any format -- specific options. Precision and color space that an image will be -- written is decided from image's type. Attempt to write image file in a -- format that does not support color space and precision combination -- will result in a compile error. writeImageExact :: Writable img format => format -> [SaveOption format] -> FilePath -> img -> IO () -- | External viewing application to use for displaying images. data ExternalViewer -- | Any custom viewer, which can be specified: -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> displayImage frog --displayImage :: Writable (Image arr cs e) TIF => Image arr cs e -> IO () -- | An image is written as a .tiff file into an operating -- system's temporary directory and passed as an argument to the external -- viewer program. displayImageUsing :: Writable (Image arr cs e) TIF => ExternalViewer -> Bool -> Image arr cs e -> IO () -- | Displays an image file by calling an external image viewer. displayImageFile :: ExternalViewer -> FilePath -> IO () defaultViewer :: ExternalViewer -- | eog tmphip/img.tiff Eye of GNOME eogViewer :: ExternalViewer -- | gpicview tmphip/img.tiff GPicView gpicviewViewer :: ExternalViewer -- | feh --fullscreen --auto-zoom tmphip/img.tiff -- FEH fehViewer :: ExternalViewer -- | gimp tmphip/img.tiff GIMP gimpViewer :: ExternalViewer instance GHC.Show.Show Graphics.Image.IO.ExternalViewer module Graphics.Image.IO.Histogram -- | A single channel histogram of an image. data Histogram Histogram :: Vector Int -> String -> AlphaColour Double -> Histogram -- | Vector containing pixel counts. Index of a vector serves as an -- original pixel value. [hBins] :: Histogram -> Vector Int -- | Name of the channel that will be displayed in the legend. [hName] :: Histogram -> String -- | Color of a plotted line. [hColour] :: Histogram -> AlphaColour Double -- | For now it is just a type synonym, but in the future it might become a -- custom data type with fields like title, width, heigth, etc. type Histograms = [Histogram] -- | Create a histogram per channel with 256 bins each. getHistograms :: forall arr cs e. (SequentialArray arr Gray e, SequentialArray arr cs e, Elevator e) => Image arr cs e -> Histograms -- | Generate a histogram with 256 bins for a single channel Gray image. getHistogram :: (SequentialArray arr Gray e, Elevator e) => Image arr Gray e -> Histogram -- | Display image histograms using an external program. Works in a similar -- way as displayImage. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> displayHistograms $ getHistograms frog --displayHistograms :: Histograms -> IO () -- | Write histograms into a PNG image file. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> writeHistograms "images/frog_histogram.svg" $ getHistograms frog ---- writeHistograms :: FilePath -> Histograms -> IO () module Graphics.Image.Interface.Repa -- | Create a delayed representation of an image. makeImage :: Array RD cs Double => (Int, Int) -> ((Int, Int) -> Pixel cs Double) -> Image RD cs Double -- | Construct an image from a nested rectangular shaped list of pixels. fromLists :: Array RD cs e => [[Pixel cs e]] -> Image RD cs e -- | Read image as luma (brightness). readImageY :: FilePath -> IO (Image RD Y Double) -- | Read image as luma with Alpha channel. readImageYA :: FilePath -> IO (Image RD YA Double) -- | Read image in RGB colorspace. readImageRGB :: FilePath -> IO (Image RD RGB Double) -- | Read image in RGB colorspace with Alpha channel. readImageRGBA :: FilePath -> IO (Image RD RGBA Double) -- | Computes an image sequentially and ensures that all elements are -- evaluated. computeS :: (Array arr cs e, Array RS cs e, Exchangable arr RS) => Image arr cs e -> Image RS cs e -- | Computes an image in parallel and ensures that all elements are -- evaluated. computeP :: (Array arr cs e, Array RP cs e, Exchangable arr RP) => Image arr cs e -> Image RP cs e -- | Delays an image, so further operations can be fused together. delay :: (ManifestArray arr cs e, Array RD cs e, Exchangable arr RD) => Image arr cs e -> Image RD cs e -- | Repa Delayed Array representation, which allows for fusion of -- computation. data RD RD :: RD -- | Repa Unboxed Array representation, which is computed -- sequentially. data RS RS :: RS -- | Repa Unboxed Array representation, which is computed in -- parallel. data RP RP :: RP -- | Create an image from a 2D Repa delayed array. fromRepaArray :: Array D DIM2 (Pixel cs e) -> Image RD cs e -- | Retrieve an underlying Repa array from RD image type. toRepaArray :: (ColorSpace cs, Unbox (PixelElt cs e)) => Image RD cs e -> Array D DIM2 (Pixel cs e) module Graphics.Image.Interface.Vector -- | Create an image with VU (Vector Unboxed) representation and -- pixels of Double precision. Note, that for Double -- precision pixels it is essential to keep values normalized in the -- [0, 1] range in order for an image to be written to file -- properly. -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY (fromIntegral i)/200 * (fromIntegral j)/200) ---- -- Because all Pixels and Images are installed into -- Num, above is equivalent to: -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY $ fromIntegral (i*j)) / (200*200) -- -- >>> writeImage "images/grad_gray.png" grad_gray ---- -- Creating color images is just as easy. -- --
-- >>> let grad_color = makeImage (200, 200) (\(i, j) -> PixelRGB (fromIntegral i) (fromIntegral j) (fromIntegral (i + j))) / 400 -- -- >>> writeImage "images/grad_color.png" grad_color ---- makeImage :: Array VU cs Double => (Int, Int) -> ((Int, Int) -> Pixel cs Double) -> Image VU cs Double -- | Construct an image from a nested rectangular shaped list of pixels. -- Length of an outer list will constitute m rows, while the -- length of inner lists - n columns. All of the inner lists -- must be the same length and greater than 0. -- --
-- >>> fromLists [[PixelY (fromIntegral (i*j) / 60000) | j <- [1..300]] | i <- [1..200]] -- <Image VectorUnboxed Y (Double): 200x300> ---- fromLists :: Array VU cs e => [[Pixel cs e]] -> Image VU cs e -- | Construct a two dimensional image with m rows and n -- columns from a flat Unboxed Vector of length k. It is -- a O(1) opeartion. Make sure that m * n = k. -- --
-- >>> fromUnboxedVector (200, 300) $ generate 60000 (\i -> PixelY $ fromIntegral i / 60000) -- <Image VectorUnboxed Luma: 200x300> ---- fromUnboxedVector :: Array VU cs e => (Int, Int) -> Vector (Pixel cs e) -> Image VU cs e -- | Convert an image to a flattened Unboxed Vector. It is a -- O(1) opeartion. -- --
-- >>> toUnboxedVector $ makeImage (3, 2) (\(i, j) -> PixelY $ fromIntegral (i+j)) -- fromList [<Luma:(0.0)>,<Luma:(1.0)>,<Luma:(1.0)>,<Luma:(2.0)>,<Luma:(2.0)>,<Luma:(3.0)>] --toUnboxedVector :: Array VU cs e => Image VU cs e -> Vector (Pixel cs e) -- | Read image as luma (brightness). readImageY :: FilePath -> IO (Image VU Y Double) -- | Read image as luma with Alpha channel. readImageYA :: FilePath -> IO (Image VU YA Double) -- | Read image in RGB colorspace. readImageRGB :: FilePath -> IO (Image VU RGB Double) -- | Read image in RGB colorspace with Alpha channel. readImageRGBA :: FilePath -> IO (Image VU RGBA Double) -- | Unboxed Vector representation. data VU VU :: VU -- | Flat vector to 2D index conversion. toIx :: Int -> Int -> (Int, Int) -- | 2D to a flat vector index conversion. -- -- Note: There is an implicit assumption that j < n fromIx :: Int -> (Int, Int) -> Int module Graphics.Image.Processing.Binary -- | Construct a binary image using a predicate from a source image. toImageBinaryUsing :: (Array arr cs e, Array arr Binary Bit) => (Pixel cs e -> Bool) -> Image arr cs e -> Image arr Binary Bit -- | Construct a binary image using a predicate from two source images. toImageBinaryUsing2 :: (Array arr cs e, Array arr Binary Bit) => (Pixel cs e -> Pixel cs e -> Bool) -> Image arr cs e -> Image arr cs e -> Image arr Binary Bit -- | Threshold a source image with an applicative pixel. -- --
-- >>> yield <- readImageRGB "images/yield.jpg" -- -- >>> writeImageExact PNG [] "images/yield_bin.png" $ thresholdWith (PixelRGB (>0.55) (<0.6) (<0.5)) yield ---- thresholdWith :: (Array arr cs e, Array arr Binary Bit) => Pixel cs (e -> Bool) -> Image arr cs e -> Image arr Binary Bit -- | Compare two images with an applicative pixel. Works just like -- thresholdWith, but on two images. compareWith :: (Array arr cs e1, Array arr cs e2, Array arr Binary Bit) => Pixel cs (e1 -> e2 -> Bool) -> Image arr cs e1 -> Image arr cs e2 -> Image arr Binary Bit -- | Pixel wise AND operator on binary images. (.&&.) :: Array arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit infixr 3 .&&. -- | Pixel wise OR operator on binary images. (.||.) :: Array arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit infixr 2 .||. -- | Complement each pixel in a binary image invert :: Array arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -- | Thresholding contains a convenient set of functions for binary -- image construction, which is done by comparing either a single pixel -- with every pixel in an image or two same size images pointwise. For -- example: -- --
-- >>> frog <- readImageY "images/frog.jpg" -- -- >>> frog .==. PixelY 0 -- (or: PixelY 0 .==. frog) -- -- >>> frog .<. flipH frog -- (or: flipH frog .>. frog) --class Array arr Binary Bit => Thresholding a b arr | a b -> arr (.==.) :: (Thresholding a b arr, Eq (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit (./=.) :: (Thresholding a b arr, Eq (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit (.<.) :: (Thresholding a b arr, Ord (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit (.<=.) :: (Thresholding a b arr, Ord (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit (.>.) :: (Thresholding a b arr, Ord (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit (.>=.) :: (Thresholding a b arr, Ord (Pixel cs e), Array arr cs e) => a cs e -> b cs e -> Image arr Binary Bit -- | Erosion is defined as: {E = B ⊖ S = {m,n|Sₘₙ⊆B} -- --
-- >>> writeImageExact PNG [] "images/figure_erode.png" $ pixelGrid 10 $ fromImageBinary $ erode struct figure ---- -- eroded with is erode :: ManifestArray arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit -- | Dialation is defined as: {D = B ⊕ S = {m,n|Sₘₙ∩B≠∅} -- --
-- >>> writeImageExact PNG [] "images/figure_dialate.png" $ pixelGrid 10 $ fromImageBinary $ dialate struct figure ---- -- dialated with is dialate :: ManifestArray arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit -- | Opening is defined as: {B ○ S = (B ⊖ S) ⊕ S} -- --
-- >>> writeImageExact PNG [] "images/figure_open.png" $ pixelGrid 10 $ fromImageBinary $ open struct figure ---- -- opened with is open :: ManifestArray arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit -- | Closing is defined as: {B ● S = (B ⊕ S) ⊖ S} -- --
-- >>> writeImageExact PNG [] "images/figure_close.png" $ pixelGrid 10 $ fromImageBinary $ close struct figure ---- -- closed with is close :: ManifestArray arr Binary Bit => Image arr Binary Bit -> Image arr Binary Bit -> Image arr Binary Bit instance Graphics.Image.Interface.Array arr Graphics.Image.ColorSpace.Binary.Binary Graphics.Image.ColorSpace.Binary.Bit => Graphics.Image.Processing.Binary.Thresholding (Graphics.Image.Interface.Image arr) (Graphics.Image.Interface.Image arr) arr instance Graphics.Image.Interface.Array arr Graphics.Image.ColorSpace.Binary.Binary Graphics.Image.ColorSpace.Binary.Bit => Graphics.Image.Processing.Binary.Thresholding Graphics.Image.Interface.Pixel (Graphics.Image.Interface.Image arr) arr instance Graphics.Image.Interface.Array arr Graphics.Image.ColorSpace.Binary.Binary Graphics.Image.ColorSpace.Binary.Bit => Graphics.Image.Processing.Binary.Thresholding (Graphics.Image.Interface.Image arr) Graphics.Image.Interface.Pixel arr module Graphics.Image.Types -- | Base array like representation for an image. class (Show arr, ColorSpace cs, Num (Pixel cs e), Functor (Pixel cs), Applicative (Pixel cs), Foldable (Pixel cs), Num e, Typeable e, Elt arr cs e) => Array arr cs e where data Image arr cs e type Elt arr cs e = () where { data family Image arr cs e; type Elt arr cs e = (); } -- | Array representation that is actually has real data stored in memory, -- hence allowing for image indexing, forcing pixels into computed state -- etc. class Array arr cs e => ManifestArray arr cs e where index !img !ix = borderIndex (error $ show img ++ " - Index out of bounds: " ++ show ix) img ix -- | Array representation that allows computation, which depends on some -- specific order, consequently making it possible to be computed only -- sequentially. class ManifestArray arr cs e => SequentialArray arr cs e -- | Array representation that supports mutation. class ManifestArray arr cs e => MutableArray arr cs e where data MImage st arr cs e where { data family MImage st arr cs e; } -- | Allows for changing an underlying image representation. class Exchangable arr' arr -- | Approach to be used near the borders during various transformations. -- Whenever a function needs information not only about a pixel of -- interest, but also about it's neighbours, it will go out of bounds -- around the image edges, hence is this set of approaches that can be -- used in such situtation. data Border px -- | Fill in a constant pixel. -- --
-- outside | Image | outside -- (Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0 --Fill :: !px -> Border px -- | Wrap around from the opposite border of the image. -- --
-- outside | Image | outside -- Wrap : 1 2 3 4 | 1 2 3 4 | 1 2 3 4 --Wrap :: Border px -- | Replicate the pixel at the edge. -- --
-- outside | Image | outside -- Edge : 1 1 1 1 | 1 2 3 4 | 4 4 4 4 --Edge :: Border px -- | Mirror like reflection. -- --
-- outside | Image | outside -- Reflect : 4 3 2 1 | 1 2 3 4 | 4 3 2 1 --Reflect :: Border px -- | Also mirror like reflection, but without repeating the edge pixel. -- --
-- outside | Image | outside -- Continue : 1 4 3 2 | 1 2 3 4 | 3 2 1 4 --Continue :: Border px -- | Unboxed Vector representation. data VU VU :: VU -- | Repa Delayed Array representation, which allows for fusion of -- computation. data RD RD :: RD -- | Repa Unboxed Array representation, which is computed -- sequentially. data RS RS :: RS -- | Repa Unboxed Array representation, which is computed in -- parallel. data RP RP :: RP -- | Haskell Image Processing (HIP) library is a wrapper around any array -- like data structure and is fully agnostic to the underlying -- representation. All of the functionality in this library relies upon a -- few type classes, which corresponding representation types are -- instances of: -- --
-- import qualified Graphics.Image as I -- import Graphics.Image.Types --module Graphics.Image -- | Create an image with VU (Vector Unboxed) representation and -- pixels of Double precision. Note, that for Double -- precision pixels it is essential to keep values normalized in the -- [0, 1] range in order for an image to be written to file -- properly. -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY (fromIntegral i)/200 * (fromIntegral j)/200) ---- -- Because all Pixels and Images are installed into -- Num, above is equivalent to: -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY $ fromIntegral (i*j)) / (200*200) -- -- >>> writeImage "images/grad_gray.png" grad_gray ---- -- Creating color images is just as easy. -- --
-- >>> let grad_color = makeImage (200, 200) (\(i, j) -> PixelRGB (fromIntegral i) (fromIntegral j) (fromIntegral (i + j))) / 400 -- -- >>> writeImage "images/grad_color.png" grad_color ---- makeImage :: Array VU cs Double => (Int, Int) -> ((Int, Int) -> Pixel cs Double) -> Image VU cs Double -- | Construct an image from a nested rectangular shaped list of pixels. -- Length of an outer list will constitute m rows, while the -- length of inner lists - n columns. All of the inner lists -- must be the same length and greater than 0. -- --
-- >>> fromLists [[PixelY (fromIntegral (i*j) / 60000) | j <- [1..300]] | i <- [1..200]] -- <Image VectorUnboxed Y (Double): 200x300> ---- fromLists :: Array VU cs e => [[Pixel cs e]] -> Image VU cs e -- | Generates a nested list of pixels from an image. -- --
-- img == fromLists (toLists img) --toLists :: ManifestArray arr cs e => Image arr cs e -> [[Pixel cs e]] -- | Read image as luma (brightness). readImageY :: FilePath -> IO (Image VU Y Double) -- | Read image as luma with Alpha channel. readImageYA :: FilePath -> IO (Image VU YA Double) -- | Read image in RGB colorspace. readImageRGB :: FilePath -> IO (Image VU RGB Double) -- | Read image in RGB colorspace with Alpha channel. readImageRGBA :: FilePath -> IO (Image VU RGBA Double) -- | This function allows for reading any supported image in the exact -- colorspace and precision it is currently encoded in. For instance, -- frog image can be read into it's YCbCr colorspace with -- Word8 precision and into any supported array representation. -- --
-- >>> readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RP YCbCr Word8)) -- Right <Image RepaParallel YCbCr (Word8): 200x320> ---- -- The drawback here is that colorspace and precision has to match -- exactly, otherwise it will return an error: -- --
-- >>> readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RD RGB Word8)) -- Left "JuicyPixel decoding error: Input image is in YCbCr8 (Pixel YCbCr Word8), cannot convert it to RGB8 (Pixel RGB Word8) colorspace." ---- -- Attempt to read an image in a particular color space that is not -- supported by the format, will result in a compile error. Refer to -- Readable class for all images that can be decoded. readImageExact :: Readable img format => format -> FilePath -> IO (Either String img) -- | Just like readImage, this function will guess an output file -- format from the extension and write to file any image that is in one -- of Y, YA, RGB or RGBA color spaces with -- Double precision. While doing necessary conversions the choice -- will be given to the most suited color space supported by the format. -- For instance, in case of a PNG format, an (Image -- arr RGBA Double) would be written as -- RGBA16, hence preserving transparency and using highest -- supported precision Word16. At the same time, writing that -- image in GIF format would save it in RGB8, since -- Word8 is the highest precision GIF supports and it -- currently cannot be saved with transparency. writeImage :: Writable (Image arr cs e) OutputFormat => FilePath -> Image arr cs e -> IO () -- | Write an image in a specific format, while supplying any format -- specific options. Precision and color space that an image will be -- written is decided from image's type. Attempt to write image file in a -- format that does not support color space and precision combination -- will result in a compile error. writeImageExact :: Writable img format => format -> [SaveOption format] -> FilePath -> img -> IO () -- | Makes a call to an external viewer that is set as a default image -- viewer by the OS. This is a non-blocking function call, so it will -- take some time before an image will appear. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> displayImage frog --displayImage :: Writable (Image arr cs e) TIF => Image arr cs e -> IO () -- | Get the number of rows in an image. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> frog -- <Image VectorUnboxed RGB (Double): 200x320> -- -- >>> rows frog -- 200 --rows :: Array arr cs e => Image arr cs e -> Int -- | Get the number of columns in an image. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> frog -- <Image VectorUnboxed RGB (Double): 200x320> -- -- >>> cols frog -- 320 --cols :: Array arr cs e => Image arr cs e -> Int -- | Get dimensions of an image. -- --
-- >>> frog <- readImageRGB "images/frog.jpg" -- -- >>> frog -- <Image VectorUnboxed RGB (Double): 200x320> -- -- >>> dims frog -- (200,320) --dims :: Array arr cs e => Image arr cs e -> (Int, Int) -- | Get a pixel at i-th and j-th location. -- --
-- >>> let grad_gray = makeImage (200, 200) (\(i, j) -> PixelY $ fromIntegral (i*j)) / (200*200) -- -- >>> index grad_gray (20, 30) == PixelY ((20*30) / (200*200)) -- True --index :: ManifestArray arr cs e => Image arr cs e -> (Int, Int) -> Pixel cs e -- | Image indexing function that returns Nothing if index -- is out of bounds, Just px otherwise. maybeIndex :: ManifestArray arr cs e => Image arr cs e -> (Int, Int) -> Maybe (Pixel cs e) -- | Image indexing function that returns a default pixel if index is out -- of bounds. defaultIndex :: ManifestArray arr cs e => Pixel cs e -> Image arr cs e -> (Int, Int) -> Pixel cs e -- | Image indexing function that uses a special border resolutions -- strategy for out of bounds pixels. borderIndex :: ManifestArray arr cs e => Border (Pixel cs e) -> Image arr cs e -> (Int, Int) -> Pixel cs e -- | Map a function over a an image. map :: (Array arr cs e, Array arr cs' e') => (Pixel cs' e' -> Pixel cs e) -> Image arr cs' e' -> Image arr cs e -- | Map an index aware function over each pixel in an image. imap :: (Array arr cs e, Array arr cs' e') => ((Int, Int) -> Pixel cs' e' -> Pixel cs e) -> Image arr cs' e' -> Image arr cs e -- | Zip two images with a function zipWith :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => (Pixel cs1 e1 -> Pixel cs2 e2 -> Pixel cs e) -> Image arr cs1 e1 -> Image arr cs2 e2 -> Image arr cs e -- | Zip two images with an index aware function izipWith :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => ((Int, Int) -> Pixel cs1 e1 -> Pixel cs2 e2 -> Pixel cs e) -> Image arr cs1 e1 -> Image arr cs2 e2 -> Image arr cs e -- | Traverse an image traverse :: (Array arr cs e, Array arr cs' e') => Image arr cs' e' -> ((Int, Int) -> (Int, Int)) -> (((Int, Int) -> Pixel cs' e') -> (Int, Int) -> Pixel cs e) -> Image arr cs e -- | Traverse two images. traverse2 :: (Array arr cs e, Array arr cs1 e1, Array arr cs2 e2) => Image arr cs1 e1 -> Image arr cs2 e2 -> ((Int, Int) -> (Int, Int) -> (Int, Int)) -> (((Int, Int) -> Pixel cs1 e1) -> ((Int, Int) -> Pixel cs2 e2) -> (Int, Int) -> Pixel cs e) -> Image arr cs e -- | Transpose an image transpose :: Array arr cs e => Image arr cs e -> Image arr cs e -- | Backwards permutation of an image. backpermute :: Array arr cs e => (Int, Int) -> ((Int, Int) -> (Int, Int)) -> Image arr cs e -> Image arr cs e -- | Perform matrix multiplication on two images. Inner dimensions must -- agree. (|*|) :: ManifestArray arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e -- | Undirected reduction of an image. fold :: ManifestArray arr cs e => (Pixel cs e -> Pixel cs e -> Pixel cs e) -> Pixel cs e -> Image arr cs e -> Pixel cs e -- | Sum all pixels in the image. sum :: ManifestArray arr cs e => Image arr cs e -> Pixel cs e -- | Multiply all pixels in the image. product :: ManifestArray arr cs e => Image arr cs e -> Pixel cs e -- | Retrieve the biggest pixel from an image maximum :: (ManifestArray arr cs e, Ord (Pixel cs e)) => Image arr cs e -> Pixel cs e -- | Retrieve the smallest pixel from an image minimum :: (ManifestArray arr cs e, Ord (Pixel cs e)) => Image arr cs e -> Pixel cs e -- | Scales all of the pixels to be in the range [0, 1]. normalize :: (ManifestArray arr cs e, ManifestArray arr Gray e, Fractional e, Ord e) => Image arr cs e -> Image arr cs e -- | Exchange the underlying array representation of an image. exchange :: (Exchangable arr' arr, Array arr' cs e, Array arr cs e) => arr -> Image arr' cs e -> Image arr cs e -- | Unboxed Vector representation. data VU VU :: VU -- | Repa Delayed Array representation, which allows for fusion of -- computation. data RD RD :: RD -- | Repa Unboxed Array representation, which is computed -- sequentially. data RS RS :: RS -- | Repa Unboxed Array representation, which is computed in -- parallel. data RP RP :: RP