-- GENERATED by C->Haskell Compiler, version 0.16.3 Crystal Seed, 24 Jan 2009 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./CV/Gabor.chs" #-}{-#LANGUAGE ForeignFunctionInterface, ScopedTypeVariables#-}
module CV.Gabor where

import CV.Image
{-# LINE 5 "./CV/Gabor.chs" #-}
import CV.Filters
{-# LINE 6 "./CV/Gabor.chs" #-}
import CV.Image
import CV.Filters
import System.IO.Unsafe
import Foreign.C.Types
import Foreign.Ptr
import CV.Transforms

newtype GaborMask = GaborMask (CInt,CInt,CDouble,CDouble,CDouble,CDouble,CDouble) 

-- gaborFilterS 
--  (GaborMask (width,height,stdX,stdY,theta,phase,cycles)) image
--     = convolve2DI (width `div` 2,height `div` 2) kernel image
--  where
--   kernel = scale Cubic 0.5 
--              $ gaborImage 0 0 (GaborMask (2*width,2*height,stdX,stdY,theta,phase,cycles))
-- 

gaborImage (width,height,dx,dy,stdX,stdY,theta,phase,cycles) = 
    unsafePerformIO $ do
        img :: Image GrayScale D32<- create (width,height) 
        withGenImage img $ \i ->
            renderGabor i (fromIntegral width) (fromIntegral height) 
                                 dx dy stdX stdY theta phase cycles
        return img

gaborFiltering (GaborMask (width,height,stdX,stdY,theta,phase,cycles)) image = 
    unsafePerformIO $ 
        withClone image $ \img ->
        withGenImage img $ \clone ->
        withGenImage image $ \original ->
            gaborFilter original clone width height 
                                 stdX stdY theta phase cycles

radialGaborFiltering (width,height,sigma,phase
                      ,center,cycles) image = 
    unsafePerformIO $ 
        withClone image $ \img ->
        withGenImage img $ \clone ->
        withGenImage image $ \original ->
            radialGaborFilter original clone 
                width height 
                sigma phase center cycles

radialGaborImage (width,height,sigma,phase
                 ,center,cycles) = 
    unsafePerformIO $ do
        img :: Image GrayScale D32 <- create (width,height) 
        withGenImage img $ \i ->
            renderRadialGabor i (fromIntegral width) (fromIntegral height) sigma 
                                       phase center cycles
        return img


foreign import ccall safe "CV/Gabor.chs.h renderGabor"
  renderGabor :: ((Ptr ()) -> (CInt -> (CInt -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (IO ())))))))))))

foreign import ccall safe "CV/Gabor.chs.h gaborFilter"
  gaborFilter :: ((Ptr ()) -> ((Ptr ()) -> (CInt -> (CInt -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (IO ()))))))))))

foreign import ccall safe "CV/Gabor.chs.h radialGaborFilter"
  radialGaborFilter :: ((Ptr ()) -> ((Ptr ()) -> (CInt -> (CInt -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (IO ())))))))))

foreign import ccall safe "CV/Gabor.chs.h renderRadialGabor"
  renderRadialGabor :: ((Ptr ()) -> (CInt -> (CInt -> (CDouble -> (CDouble -> (CDouble -> (CDouble -> (IO ()))))))))