{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module ArrayFire.Image where
import Control.Exception (mask_)
import Data.Bits (popCount)
import Data.Proxy
import Data.Word
import Foreign.C.Types (CBool)
import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Marshal.Array (allocaArray, peekArray)
import System.IO.Unsafe (unsafePerformIO)
import ArrayFire.Exception (throwAFError)
import ArrayFire.Internal.Defines (AFMomentType(..))
import ArrayFire.Internal.Types
import ArrayFire.Internal.Image
import ArrayFire.FFI
gradient :: Array a -> (Array a, Array a)
gradient :: forall a. Array a -> (Array a, Array a)
gradient Array a
a = Array a
a Array a
-> (Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr)
-> (Array a, Array a)
forall a b.
Array a
-> (Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr)
-> (Array a, Array b)
`op2p` Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr
af_gradient
loadImage
:: String
-> Bool
-> IO (Array a)
loadImage :: forall a. String -> Bool -> IO (Array a)
loadImage String
s Bool
b = String
-> Bool
-> (Ptr AFArray -> CString -> CBool -> IO AFErr)
-> IO (Array a)
forall a.
String
-> Bool
-> (Ptr AFArray -> CString -> CBool -> IO AFErr)
-> IO (Array a)
loadAFImage String
s Bool
b Ptr AFArray -> CString -> CBool -> IO AFErr
af_load_image
saveImage :: Array a -> String -> IO ()
saveImage :: forall a. Array a -> String -> IO ()
saveImage Array a
a String
s = Array a -> String -> (CString -> AFArray -> IO AFErr) -> IO ()
forall b.
Array b -> String -> (CString -> AFArray -> IO AFErr) -> IO ()
afSaveImage Array a
a String
s CString -> AFArray -> IO AFErr
af_save_image
loadImageNative :: String -> IO (Array a)
loadImageNative :: forall a. String -> IO (Array a)
loadImageNative String
s = String -> (Ptr AFArray -> CString -> IO AFErr) -> IO (Array a)
forall a.
String -> (Ptr AFArray -> CString -> IO AFErr) -> IO (Array a)
loadAFImageNative String
s Ptr AFArray -> CString -> IO AFErr
af_load_image_native
saveImageNative :: Array a -> String -> IO ()
saveImageNative :: forall a. Array a -> String -> IO ()
saveImageNative Array a
a String
s = Array a -> String -> (CString -> AFArray -> IO AFErr) -> IO ()
forall b.
Array b -> String -> (CString -> AFArray -> IO AFErr) -> IO ()
afSaveImage Array a
a String
s CString -> AFArray -> IO AFErr
af_save_image_native
isImageIOAvailable :: IO Bool
isImageIOAvailable :: IO Bool
isImageIOAvailable =
Int -> Bool
forall a. Enum a => Int -> a
toEnum (Int -> Bool) -> (CBool -> Int) -> CBool -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CBool -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CBool -> Bool) -> IO CBool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr CBool -> IO AFErr) -> IO CBool
forall a. Storable a => (Ptr a -> IO AFErr) -> IO a
afCall1 Ptr CBool -> IO AFErr
af_is_image_io_available
resize
:: Array a
-> Int
-> Int
-> InterpType
-> Array a
resize :: forall a. Array a -> Int -> Int -> InterpType -> Array a
resize Array a
a (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
d0) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
d1) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray -> AFArray -> DimT -> DimT -> AFInterpType -> IO AFErr
af_resize Ptr AFArray
ptr AFArray
x DimT
d0 DimT
d1 AFInterpType
interp)
transform
:: Array a
-> Array a
-> Int
-> Int
-> InterpType
-> Bool
-> Array a
transform :: forall a.
Array a -> Array a -> Int -> Int -> InterpType -> Bool -> Array a
transform Array a
inp Array a
trans (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
d0) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
d1) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
inverse) =
Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
inp Array a
trans (\Ptr AFArray
ptr AFArray
a1 AFArray
a2 -> Ptr AFArray
-> AFArray
-> AFArray
-> DimT
-> DimT
-> AFInterpType
-> CBool
-> IO AFErr
af_transform Ptr AFArray
ptr AFArray
a1 AFArray
a2 DimT
d0 DimT
d1 AFInterpType
interp CBool
inverse)
transformCoordinates
:: Array a
-> Float
-> Float
-> Array a
transformCoordinates :: forall a. Array a -> Float -> Float -> Array a
transformCoordinates Array a
a Float
d0 Float
d1 =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray -> AFArray -> Float -> Float -> IO AFErr
af_transform_coordinates Ptr AFArray
ptr AFArray
x Float
d0 Float
d1)
rotate
:: Array a
-> Float
-> Bool
-> InterpType
-> Array a
rotate :: forall a. Array a -> Float -> Bool -> InterpType -> Array a
rotate Array a
a Float
theta (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
crop) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray
-> AFArray -> Float -> CBool -> AFInterpType -> IO AFErr
af_rotate Ptr AFArray
ptr AFArray
x Float
theta CBool
crop AFInterpType
interp)
translate
:: Array a
-> Float
-> Float
-> Int
-> Int
-> InterpType
-> Array a
translate :: forall a.
Array a -> Float -> Float -> Int -> Int -> InterpType -> Array a
translate Array a
a Float
trans0 Float
trans1 (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim0) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim1) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray
-> AFArray
-> Float
-> Float
-> DimT
-> DimT
-> AFInterpType
-> IO AFErr
af_translate Ptr AFArray
ptr AFArray
x Float
trans0 Float
trans1 DimT
odim0 DimT
odim1 AFInterpType
interp)
scale
:: Array a
-> Float
-> Float
-> Int
-> Int
-> InterpType
-> Array a
scale :: forall a.
Array a -> Float -> Float -> Int -> Int -> InterpType -> Array a
scale Array a
a Float
trans0 Float
trans1 (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim0) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim1) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray
-> AFArray
-> Float
-> Float
-> DimT
-> DimT
-> AFInterpType
-> IO AFErr
af_scale Ptr AFArray
ptr AFArray
x Float
trans0 Float
trans1 DimT
odim0 DimT
odim1 AFInterpType
interp)
skew
:: Array a
-> Float
-> Float
-> Int
-> Int
-> InterpType
-> Bool
-> Array a
skew :: forall a.
Array a
-> Float -> Float -> Int -> Int -> InterpType -> Bool -> Array a
skew Array a
a Float
trans0 Float
trans1 (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim0) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
odim1) (InterpType -> AFInterpType
fromInterpType -> AFInterpType
interp) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
b) =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray
-> AFArray
-> Float
-> Float
-> DimT
-> DimT
-> AFInterpType
-> CBool
-> IO AFErr
af_skew Ptr AFArray
ptr AFArray
x Float
trans0 Float
trans1 DimT
odim0 DimT
odim1 AFInterpType
interp CBool
b)
histogram
:: AFType a
=> Array a
-> Int
-> Double
-> Double
-> Array Word32
histogram :: forall a.
AFType a =>
Array a -> Int -> Double -> Double -> Array Word32
histogram Array a
a (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
b) Double
c Double
d =
Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array Word32
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
x -> Ptr AFArray -> AFArray -> CUInt -> Double -> Double -> IO AFErr
af_histogram Ptr AFArray
ptr AFArray
x CUInt
b Double
c Double
d)
dilate
:: Array a
-> Array a
-> Array a
dilate :: forall a. Array a -> Array a -> Array a
dilate Array a
in' Array a
mask = Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in' Array a
mask Ptr AFArray -> AFArray -> AFArray -> IO AFErr
af_dilate
dilate3
:: Array a
-> Array a
-> Array a
dilate3 :: forall a. Array a -> Array a -> Array a
dilate3 Array a
in' Array a
mask = Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in' Array a
mask Ptr AFArray -> AFArray -> AFArray -> IO AFErr
af_dilate3
erode
:: Array a
-> Array a
-> Array a
erode :: forall a. Array a -> Array a -> Array a
erode Array a
in' Array a
mask = Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in' Array a
mask Ptr AFArray -> AFArray -> AFArray -> IO AFErr
af_erode
erode3
:: Array a
-> Array a
-> Array a
erode3 :: forall a. Array a -> Array a -> Array a
erode3 Array a
in' Array a
mask = Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in' Array a
mask Ptr AFArray -> AFArray -> AFArray -> IO AFErr
af_erode3
bilateral
:: Array a
-> Float
-> Float
-> Bool
-> Array a
bilateral :: forall a. Array a -> Float -> Float -> Bool -> Array a
bilateral Array a
in' Float
a Float
b (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
c) = Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> Float -> Float -> CBool -> IO AFErr
af_bilateral Ptr AFArray
ptr AFArray
k Float
a Float
b CBool
c)
meanShift
:: Array a
-> Float
-> Float
-> Int
-> Bool
-> Array a
meanShift :: forall a. Array a -> Float -> Float -> Int -> Bool -> Array a
meanShift Array a
in' Float
a Float
b (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
c) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
d) = Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray
-> AFArray -> Float -> Float -> CUInt -> CBool -> IO AFErr
af_mean_shift Ptr AFArray
ptr AFArray
k Float
a Float
b CUInt
c CBool
d)
minFilt
:: Array a
-> Int
-> Int
-> BorderType
-> Array a
minFilt :: forall a. Array a -> Int -> Int -> BorderType -> Array a
minFilt Array a
in' (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
a) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
b) (BorderType -> AFBorderType
fromBorderType -> AFBorderType
c) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> DimT -> DimT -> AFBorderType -> IO AFErr
af_minfilt Ptr AFArray
ptr AFArray
k DimT
a DimT
b AFBorderType
c)
maxFilt
:: Array a
-> Int
-> Int
-> BorderType
-> Array a
maxFilt :: forall a. Array a -> Int -> Int -> BorderType -> Array a
maxFilt Array a
in' (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
a) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
b) (BorderType -> AFBorderType
fromBorderType -> AFBorderType
c) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> DimT -> DimT -> AFBorderType -> IO AFErr
af_maxfilt Ptr AFArray
ptr AFArray
k DimT
a DimT
b AFBorderType
c)
regions
:: forall a . (AFType a)
=> Array a
-> Connectivity
-> Array a
regions :: forall a. AFType a => Array a -> Connectivity -> Array a
regions Array a
in' (Connectivity -> AFConnectivity
fromConnectivity -> AFConnectivity
conn) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> AFConnectivity -> AFDtype -> IO AFErr
af_regions Ptr AFArray
ptr AFArray
k AFConnectivity
conn AFDtype
dtype)
where
dtype :: AFDtype
dtype = Proxy a -> AFDtype
forall a. AFType a => Proxy a -> AFDtype
afType (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a)
sobel_operator
:: Array a
-> Int
-> (Array a, Array a)
sobel_operator :: forall a. Array a -> Int -> (Array a, Array a)
sobel_operator Array a
in' (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
kerSize) =
Array a
in' Array a
-> (Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr)
-> (Array a, Array a)
forall a b.
Array a
-> (Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr)
-> (Array a, Array b)
`op2p` (\Ptr AFArray
ptrA Ptr AFArray
ptrB AFArray
k -> Ptr AFArray -> Ptr AFArray -> AFArray -> CUInt -> IO AFErr
af_sobel_operator Ptr AFArray
ptrA Ptr AFArray
ptrB AFArray
k CUInt
kerSize)
rgb2gray
:: Array a
-> Float
-> Float
-> Float
-> Array a
rgb2gray :: forall a. Array a -> Float -> Float -> Float -> Array a
rgb2gray Array a
in' Float
a Float
b Float
c =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> Float -> Float -> Float -> IO AFErr
af_rgb2gray Ptr AFArray
ptr AFArray
k Float
a Float
b Float
c)
gray2rgb
:: Array a
-> Float
-> Float
-> Float
-> Array a
gray2rgb :: forall a. Array a -> Float -> Float -> Float -> Array a
gray2rgb Array a
in' Float
a Float
b Float
c = Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
k -> Ptr AFArray -> AFArray -> Float -> Float -> Float -> IO AFErr
af_gray2rgb Ptr AFArray
ptr AFArray
k Float
a Float
b Float
c)
histEqual
:: Array a
-> Array a
-> Array a
histEqual :: forall a. Array a -> Array a -> Array a
histEqual Array a
in' Array a
mask = Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in' Array a
mask Ptr AFArray -> AFArray -> AFArray -> IO AFErr
af_hist_equal
gaussianKernel
:: Int
-> Int
-> Double
-> Double
-> Array a
gaussianKernel :: forall a. Int -> Int -> Double -> Double -> Array a
gaussianKernel (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CInt
i1) (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CInt
i2) Double
d1 Double
d2 =
(Ptr AFArray -> IO AFErr) -> Array a
forall a. (Ptr AFArray -> IO AFErr) -> Array a
createArray (\Ptr AFArray
ptr -> Ptr AFArray -> CInt -> CInt -> Double -> Double -> IO AFErr
af_gaussian_kernel Ptr AFArray
ptr CInt
i1 CInt
i2 Double
d1 Double
d2)
hsv2rgb
:: Array a
-> Array a
hsv2rgb :: forall a. Array a -> Array a
hsv2rgb = (Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` Ptr AFArray -> AFArray -> IO AFErr
af_hsv2rgb)
rgb2hsv
:: Array a
-> Array a
rgb2hsv :: forall a. Array a -> Array a
rgb2hsv = (Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` Ptr AFArray -> AFArray -> IO AFErr
af_rgb2hsv)
colorSpace
:: Array a
-> CSpace
-> CSpace
-> Array a
colorSpace :: forall a. Array a -> CSpace -> CSpace -> Array a
colorSpace Array a
in' (CSpace -> AFCSpace
fromCSpace -> AFCSpace
to) (CSpace -> AFCSpace
fromCSpace -> AFCSpace
from) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
a -> Ptr AFArray -> AFArray -> AFCSpace -> AFCSpace -> IO AFErr
af_color_space Ptr AFArray
p AFArray
a AFCSpace
to AFCSpace
from)
unwrap
:: Array a
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Bool
-> Array a
unwrap :: forall a.
Array a
-> Int -> Int -> Int -> Int -> Int -> Int -> Bool -> Array a
unwrap Array a
in' (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
wx) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
wy) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
sx) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
sy) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
px) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
py) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
b)
= Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
a -> Ptr AFArray
-> AFArray
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> CBool
-> IO AFErr
af_unwrap Ptr AFArray
ptr AFArray
a DimT
wx DimT
wy DimT
sx DimT
sy DimT
px DimT
py CBool
b)
wrap
:: Array a
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Bool
-> Array a
wrap :: forall a.
Array a
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Bool
-> Array a
wrap Array a
in' (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
ox) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
oy) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
wx) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
wy)
(Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
sx) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
sy) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
px) (Int -> DimT
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> DimT
py) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
b)
= Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
ptr AFArray
a -> Ptr AFArray
-> AFArray
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> DimT
-> CBool
-> IO AFErr
af_wrap Ptr AFArray
ptr AFArray
a DimT
ox DimT
oy DimT
wx DimT
wy DimT
sx DimT
sy DimT
px DimT
py CBool
b)
sat
:: Array a
-> Array a
sat :: forall a. Array a -> Array a
sat = (Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` Ptr AFArray -> AFArray -> IO AFErr
af_sat)
ycbcr2rgb
:: Array a
-> YccStd
-> Array a
ycbcr2rgb :: forall a. Array a -> YccStd -> Array a
ycbcr2rgb Array a
a YccStd
y = Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
k -> Ptr AFArray -> AFArray -> AFYccStd -> IO AFErr
af_ycbcr2rgb Ptr AFArray
p AFArray
k (YccStd -> AFYccStd
fromAFYccStd YccStd
y))
rgb2ycbcr
:: Array a
-> YccStd
-> Array a
rgb2ycbcr :: forall a. Array a -> YccStd -> Array a
rgb2ycbcr Array a
a YccStd
y = Array a
a Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
k -> Ptr AFArray -> AFArray -> AFYccStd -> IO AFErr
af_rgb2ycbcr Ptr AFArray
p AFArray
k (YccStd -> AFYccStd
fromAFYccStd YccStd
y))
moments
:: Array a
-> MomentType
-> Array a
moments :: forall a. Array a -> MomentType -> Array a
moments Array a
in' MomentType
m =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
k -> Ptr AFArray -> AFArray -> AFMomentType -> IO AFErr
af_moments Ptr AFArray
p AFArray
k (MomentType -> AFMomentType
fromMomentType MomentType
m))
momentsAll
:: Array a
-> MomentType
-> [Double]
{-# NOINLINE momentsAll #-}
momentsAll :: forall a. Array a -> MomentType -> [Double]
momentsAll (Array ForeignPtr ()
fptr) MomentType
m =
IO [Double] -> [Double]
forall a. IO a -> a
unsafePerformIO (IO [Double] -> [Double])
-> ((AFArray -> IO [Double]) -> IO [Double])
-> (AFArray -> IO [Double])
-> [Double]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO [Double] -> IO [Double]
forall a. IO a -> IO a
mask_ (IO [Double] -> IO [Double])
-> ((AFArray -> IO [Double]) -> IO [Double])
-> (AFArray -> IO [Double])
-> IO [Double]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr () -> (AFArray -> IO [Double]) -> IO [Double]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr ()
fptr ((AFArray -> IO [Double]) -> [Double])
-> (AFArray -> IO [Double]) -> [Double]
forall a b. (a -> b) -> a -> b
$ \AFArray
aptr ->
Int -> (Ptr Double -> IO [Double]) -> IO [Double]
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray Int
n ((Ptr Double -> IO [Double]) -> IO [Double])
-> (Ptr Double -> IO [Double]) -> IO [Double]
forall a b. (a -> b) -> a -> b
$ \Ptr Double
outPtr -> do
AFErr -> IO ()
throwAFError (AFErr -> IO ()) -> IO AFErr -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Double -> AFArray -> AFMomentType -> IO AFErr
af_moments_all Ptr Double
outPtr AFArray
aptr AFMomentType
afm
Int -> Ptr Double -> IO [Double]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr Double
outPtr
where
afm :: AFMomentType
afm@(AFMomentType Int
raw) = MomentType -> AFMomentType
fromMomentType MomentType
m
n :: Int
n = Int -> Int
forall a. Bits a => a -> Int
popCount Int
raw
canny
:: Array a
-> CannyThreshold
-> Float
-> Float
-> Int
-> Bool
-> Array CBool
canny :: forall a.
Array a
-> CannyThreshold -> Float -> Float -> Int -> Bool -> Array CBool
canny Array a
in' (CannyThreshold -> AFCannyThreshold
fromCannyThreshold -> AFCannyThreshold
canny') Float
low Float
high (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
window) (Int -> CBool
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CBool) -> (Bool -> Int) -> Bool -> CBool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum -> CBool
fast) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array CBool
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
a -> Ptr AFArray
-> AFArray
-> AFCannyThreshold
-> Float
-> Float
-> CUInt
-> CBool
-> IO AFErr
af_canny Ptr AFArray
p AFArray
a AFCannyThreshold
canny' Float
low Float
high CUInt
window CBool
fast)
anisotropicDiffusion
:: Array a
-> Float
-> Float
-> Int
-> FluxFunction
-> DiffusionEq
-> Array a
anisotropicDiffusion :: forall a.
Array a
-> Float -> Float -> Int -> FluxFunction -> DiffusionEq -> Array a
anisotropicDiffusion Array a
in' Float
ts Float
con (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> CUInt
iter) (FluxFunction -> AFFluxFunction
fromFluxFunction -> AFFluxFunction
flux) (DiffusionEq -> AFDiffusionEq
fromDiffusionEq -> AFDiffusionEq
diff) =
Array a
in' Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array a
forall a b.
Array a -> (Ptr AFArray -> AFArray -> IO AFErr) -> Array b
`op1` (\Ptr AFArray
p AFArray
a -> Ptr AFArray
-> AFArray
-> Float
-> Float
-> CUInt
-> AFFluxFunction
-> AFDiffusionEq
-> IO AFErr
af_anisotropic_diffusion Ptr AFArray
p AFArray
a Float
ts Float
con CUInt
iter AFFluxFunction
flux AFDiffusionEq
diff)
inverseDeconv
:: Array a
-> Array a
-> Float
-> InverseDeconvAlgo
-> Array a
inverseDeconv :: forall a.
Array a -> Array a -> Float -> InverseDeconvAlgo -> Array a
inverseDeconv Array a
in1 Array a
in2 Float
f1 (InverseDeconvAlgo -> AFInverseDeconvAlgo
fromInverseDeconvAlgo -> AFInverseDeconvAlgo
algo) =
Array a
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array a
forall b a c.
Array b
-> Array a
-> (Ptr AFArray -> AFArray -> AFArray -> IO AFErr)
-> Array c
op2 Array a
in1 Array a
in2 (\Ptr AFArray
p AFArray
a AFArray
k -> Ptr AFArray
-> AFArray -> AFArray -> Float -> AFInverseDeconvAlgo -> IO AFErr
af_inverse_deconv Ptr AFArray
p AFArray
a AFArray
k Float
f1 AFInverseDeconvAlgo
algo)