<commit_before>module CV.Operations
( clear
, set
, NormType(..)
, normalize
, unitNormalize
, unitStretch
, logNormalize
) where

import CV.Bindings.Core
import CV.Bindings.Types
import CV.Image
import CV.ImageMath as IM
import CV.ImageMathOp
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (nullPtr,castPtr)
import System.IO.Unsafe

clear :: Image c d -> Image c d
clear i = unsafePerformIO $ do
  withImage i $ \i_ptr ->
    c'cvSetZero (castPtr i_ptr)
  return i

set :: Double -> Image c d -> Image c d
set v i = unsafePerformIO $ do
  withImage i $ \i_ptr ->
    c'wrapSetAll (castPtr i_ptr) (realToFrac v) nullPtr
  return i

data NormType =
  NormC |
  NormL1 |
  NormL2 |
  NormMask |
  NormRelative |
  NormDiff |
  NormMinMax |
  NormDiffC |
  NormDiffL1 |
  NormDiffL2 |
  NormDiffRelativeC |
  NormDiffRelativeL1 |
  NormDiffRelativeL2

cNormType t =
  case t of
    NormC              -> c'CV_C
    NormL1             -> c'CV_L1
    NormL2             -> c'CV_L2
    NormMask           -> c'CV_NORM_MASK
    NormRelative       -> c'CV_RELATIVE
    NormDiff           -> c'CV_DIFF
    NormMinMax         -> c'CV_MINMAX
    NormDiffC          -> c'CV_DIFF_C
    NormDiffL1         -> c'CV_DIFF_L1<commit_msg>add image expand operation<commit_after>module CV.Operations
( clear
, set
, expand
, NormType(..)
, normalize
, unitNormalize
, unitStretch
, logNormalize
) where

import CV.Bindings.Core
import CV.Bindings.ImgProc
import CV.Bindings.Types
import CV.Image
import CV.ImageMath as IM
import CV.ImageMathOp
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (nullPtr,castPtr)
import System.IO.Unsafe

clear :: Image c d -> Image c d
clear i = unsafePerformIO $ do
  withImage i $ \i_ptr ->
    c'cvSetZero (castPtr i_ptr)
  return i

set :: Double -> Image c d -> Image c d
set v i = unsafePerformIO $ do
  withImage i $ \i_ptr ->
    c'wrapSetAll (castPtr i_ptr) (realToFrac v) nullPtr
  return i


expand :: (Int,Int,Int,Int) -> Image d c -> Image d c
expand (top,bottom,left,right) i = unsafePerformIO $
  copyMakeBorder i top bottom left right BorderReplicate 0


data NormType =
  NormC |
  NormL1 |
  NormL2 |
  NormMask |
  NormRelative |
  NormDiff |
  NormMinMax |
  NormDiffC |
  NormDiffL1 |
  NormDiffL2 |
  NormDiffRelativeC |
  NormDiffRelativeL1 |
  NormDiffRelativeL2

cNormType t =
  case t of
    NormC              -> c'CV_C
    NormL1             -> c'CV_L1
    NormL2             -> c'CV_L2
    NormMask           -> c'CV_NORM_MASK
    NormRelative       -> c'CV_RELATIVE
    NormDiff           -> c'CV_DIFF
    NormMinMax         -> c'CV_MINMAX
    NormDiffC          -> c'CV_DIFF_C
    NormDiffL1         -> c'CV_DIFF_L1
{'fraction_non_alphanumeric': 0.08570359281437126, 'fraction_numerical': 0.0093562874251497, 'mean_word_length': 2.5263852242744065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2706823', 'n_tokens_mistral': 965, 'n_tokens_neox': 956, 'n_words': 247}