{-# LANGUAGE BangPatterns
, FlexibleContexts
, TypeFamilies #-}
module Vision.Image.Filter (
Filterable, Filter, SeparatelyFiltrable
, dilate, erode
, blur, gaussianBlur
, DerivativeType (..), scharr, sobel
, mean
) where
import Data.Int
import Foreign.Storable (Storable)
import Vision.Image.Class (MaskedImage (..), Image (..), FromFunction (..))
import Vision.Image.Filter.Internal (
Filterable, Filter, SeparatelyFiltrable (..)
, DerivativeType
)
import Vision.Primitive (Size)
import qualified Vision.Image.Filter.Internal as Internal
dilate, erode :: ( Image src, Ord (ImagePixel src)
, FromFunction res, FromFunctionPixel res ~ ImagePixel src
, SeparatelyFiltrable src res (ImagePixel src))
=> Int
-> src
-> res
dilate :: forall src res.
(Image src, Ord (ImagePixel src), FromFunction res,
FromFunctionPixel res ~ ImagePixel src,
SeparatelyFiltrable src res (ImagePixel src)) =>
Int -> src -> res
dilate Int
radius src
img = forall pix. Ord pix => Int -> Morphological pix
Internal.dilate Int
radius forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE dilate #-}
erode :: forall src res.
(Image src, Ord (ImagePixel src), FromFunction res,
FromFunctionPixel res ~ ImagePixel src,
SeparatelyFiltrable src res (ImagePixel src)) =>
Int -> src -> res
erode Int
radius src
img = forall pix. Ord pix => Int -> Morphological pix
Internal.erode Int
radius forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE erode #-}
blur :: ( Image src, Integral (ImagePixel src)
, FromFunction res, Num (FromFunctionPixel res)
, SeparatelyFiltrable src res Int32)
=> Int
-> src
-> res
blur :: forall src res.
(Image src, Integral (ImagePixel src), FromFunction res,
Num (FromFunctionPixel res), SeparatelyFiltrable src res Int32) =>
Int -> src -> res
blur Int
radius src
img =
let filt :: (Integral src, Num res) => Internal.Blur src Int32 res
filt :: forall src res. (Integral src, Num res) => Blur src Int32 res
filt = forall src acc res.
(Integral src, Integral acc, Num res) =>
Int -> Blur src acc res
Internal.blur Int
radius
in forall src res. (Integral src, Num res) => Blur src Int32 res
filt forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE blur #-}
gaussianBlur :: ( Image src, Integral (ImagePixel src)
, FromFunction res, Integral (FromFunctionPixel res)
, Floating acc, RealFrac acc, Storable acc
, SeparatelyFiltrable src res acc)
=> Int
-> Maybe acc
-> src
-> res
gaussianBlur :: forall src res acc.
(Image src, Integral (ImagePixel src), FromFunction res,
Integral (FromFunctionPixel res), Floating acc, RealFrac acc,
Storable acc, SeparatelyFiltrable src res acc) =>
Int -> Maybe acc -> src -> res
gaussianBlur Int
radius Maybe acc
mSig src
img =
forall src acc res.
(Integral src, Floating acc, RealFrac acc, Storable acc,
Integral res) =>
Int -> Maybe acc -> Blur src acc res
Internal.gaussianBlur Int
radius Maybe acc
mSig forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE gaussianBlur #-}
scharr :: ( Image src, Integral (ImagePixel src)
, FromFunction res, Integral (FromFunctionPixel res)
, Storable (FromFunctionPixel res)
, SeparatelyFiltrable src res (FromFunctionPixel res))
=> DerivativeType -> src -> res
scharr :: forall src res.
(Image src, Integral (ImagePixel src), FromFunction res,
Integral (FromFunctionPixel res), Storable (FromFunctionPixel res),
SeparatelyFiltrable src res (FromFunctionPixel res)) =>
DerivativeType -> src -> res
scharr DerivativeType
der src
img = forall src res.
(Integral src, Integral res) =>
DerivativeType -> Derivative src res
Internal.scharr DerivativeType
der forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE scharr #-}
sobel :: ( Image src, Integral (ImagePixel src)
, FromFunction res, Integral (FromFunctionPixel res)
, Storable (FromFunctionPixel res)
, SeparatelyFiltrable src res (FromFunctionPixel res))
=> Int
-> DerivativeType
-> src
-> res
sobel :: forall src res.
(Image src, Integral (ImagePixel src), FromFunction res,
Integral (FromFunctionPixel res), Storable (FromFunctionPixel res),
SeparatelyFiltrable src res (FromFunctionPixel res)) =>
Int -> DerivativeType -> src -> res
sobel Int
radius DerivativeType
der src
img = forall src res.
(Integral src, Integral res, Storable res) =>
Int -> DerivativeType -> Derivative src res
Internal.sobel Int
radius DerivativeType
der forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE sobel #-}
mean :: ( Image src, Integral (ImagePixel src)
, FromFunction res, Fractional (FromFunctionPixel res)
, SeparatelyFiltrable src res Int32)
=> Size -> src -> res
mean :: forall src res.
(Image src, Integral (ImagePixel src), FromFunction res,
Fractional (FromFunctionPixel res),
SeparatelyFiltrable src res Int32) =>
Size -> src -> res
mean Size
size src
img =
let filt :: (Integral src, Fractional res) => Internal.Mean src Int32 res
filt :: forall src res.
(Integral src, Fractional res) =>
Mean src Int32 res
filt = forall src acc res.
(Integral src, Integral acc, Fractional res) =>
Size -> SeparableFilter src () acc res
Internal.mean Size
size
in forall src res.
(Integral src, Fractional res) =>
Mean src Int32 res
filt forall src res f. Filterable src res f => f -> src -> res
`Internal.apply` src
img
{-# INLINABLE mean #-}