Permalink
Browse files

Fiddling with types

  • Loading branch information...
1 parent 159101a commit 7e5af1be24fa9f25396b71955472c751cc98e4ce @aleator committed Feb 8, 2012
Showing with 35 additions and 15 deletions.
  1. +19 −2 CV/Edges.chs
  2. +5 −3 CV/Matrix.hs
  3. +11 −10 examples/Fuse.hs
View
@@ -1,4 +1,4 @@
-{-#LANGUAGE ForeignFunctionInterface #-}
+{-#LANGUAGE ForeignFunctionInterface, DataKinds, PolyKinds, TypeFamilies #-}
#include "cvWrapLEO.h"
-- | This module is a collection of simple edge detectors.
@@ -23,12 +23,29 @@ import CV.ImageOp
import CV.Image
{#import CV.Image#}
-import C2HSTools
+import C2HSTools hiding (unsafePerformIO)
+import System.IO.Unsafe
-- | Perform Sobel filtering on image. First argument gives order of horizontal and vertical
-- derivative estimates and second one is the aperture. This function can also calculate
-- Scharr filter with aperture specification of sScharr
+data Orders = O0_1
+ | O0_2
+ | O1_0
+ | O1_1
+ | O1_2
+ | O2_0
+ | O2_1
+ | O2_2
+ deriving (Eq,Ord,Show)
+
+type family Larger a b :: Bool
+type instance Larger D8 D32 = True
+type instance Larger D8 D64 = True
+type instance Larger D32 D32 = True
+type instance Larger D32 D64 = True
+
sobelOp :: (Int,Int) -> SobelAperture -> ImageOperation GrayScale D32
sobelOp (dx,dy) (Sb aperture)
View
@@ -1,4 +1,5 @@
-{-#LANGUAGE ParallelListComp, TypeFamilies, FlexibleInstances, FlexibleContexts, ScopedTypeVariables#-}
+{-#LANGUAGE ParallelListComp, TypeFamilies, FlexibleInstances, FlexibleContexts, ScopedTypeVariables,
+ ConstraintKinds#-}
-- | This module provides wrappers for CvMat type. This is still preliminary as the type of the
-- matrix isn't coded in the haskell type.
module CV.Matrix
@@ -128,9 +129,10 @@ mxm m1@(Matrix a_m) m2@(Matrix b_m) = unsafePerformIO $ do
withMatPtr :: Matrix x -> (Ptr C'CvMat -> IO a) -> IO a
withMatPtr (Matrix m) op = withForeignPtr m op
+type StdElement t = (Storable t, Exists (Matrix t), Args (Matrix t) ~ (Int,Int))
+
-- | Convert a list of floats into Matrix
-fromList :: forall t . (Storable t, Exists (Matrix t), Args (Matrix t) ~ (Int,Int))
- => (Int,Int) -> [t] -> Matrix t
+fromList :: forall t . (StdElement t) => (Int,Int) -> [t] -> Matrix t
fromList (w,h) lst = unsafePerformIO $ do
let m@(Matrix e) = emptyMatrix (w,h)
withForeignPtr e $ \mat -> do
View
@@ -1,28 +1,29 @@
-{-#LANGUAGE ScopedTypeVariables #-}
+{-#LANGUAGE ScopedTypeVariables, ParallelListComp #-}
module Main where
import CV.Drawing
import CV.Filters
import CV.Image
import CV.ColourUtils
import CV.ImageMathOp
-import CV.MultiresolutionSpline
+import CV.Pixelwise
+import CV.MultiresolutionSpline
import Control.Applicative
import Control.Monad
import Data.Maybe
import System.Environment
import qualified CV.ImageMath as IM
import qualified CV.Transforms as T
-merge :: Image GrayScale D32 -> Image GrayScale D32 -> Image GrayScale D32
-merge a b = (IM.invert mask #* a) #+ (mask #* b)
- where
- mask = unsafeImageTo32F $ (IM.abs a::Image GrayScale D32) #> (IM.abs b::Image GrayScale D32)
+merge :: D32 -> D32 -> D32
+merge a b | abs a < abs b = b
+ | otherwise = a
+laplacianFusion :: Image GrayScale D32 -> Image GrayScale D32 -> Image GrayScale D32
laplacianFusion a b = T.reconstructFromLaplacian $
- zipWith merge
- (T.laplacianPyramid 5 a)
- (T.laplacianPyramid 5 b)
+ [toImage $ merge <$$> x <+> y
+ | x <- T.laplacianPyramid 5 a
+ | y <- T.laplacianPyramid 5 b]
sFuser i1 fn = do
Just i2 <- loadImage fn >>= return . fmap (T.enlarge 5)
@@ -31,7 +32,7 @@ sFuser i1 fn = do
main = do
- (fn1:fns) <- getArgs
+ (fn1:fns) <- getArgs
Just i1 <- loadImage fn1 >>= return . fmap (T.enlarge 5)
r <- foldM sFuser i1 fns
saveImage "fusing_result.png" $ stretchHistogram r

0 comments on commit 7e5af1b

Please sign in to comment.