Skip to content

Commit d489bf2

Browse files
committed
Add more haddocks
1 parent 7d9e548 commit d489bf2

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/ArrayFire/Util.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import ArrayFire.Types
3030

3131
type Version = (Int,Int,Int)
3232

33+
-- | Retrieve version for ArrayFire API
3334
getVersion :: IO Version
3435
getVersion =
3536
alloca $ \x ->
@@ -40,14 +41,18 @@ getVersion =
4041
<*> (fromIntegral <$> peek y)
4142
<*> (fromIntegral <$> peek z)
4243

44+
-- | Prints array to stdout
4345
printArray :: Array a -> IO ()
4446
printArray (Array fptr) =
4547
mask_ . withForeignPtr fptr $ \ptr ->
4648
throwAFError =<< af_print_array ptr
4749

50+
-- | Gets git revision of ArrayFire
4851
getRevision :: IO String
4952
getRevision = peekCString =<< af_get_revision
5053

54+
55+
-- | Saves 'Array' to disk
5156
printArrayGen
5257
:: String
5358
-> Array a
@@ -58,6 +63,7 @@ printArrayGen s (Array fptr) (fromIntegral -> prec) = do
5863
withCString s $ \cstr ->
5964
throwAFError =<< af_print_array_gen cstr ptr prec
6065

66+
-- | Saves 'Array' to disk
6167
saveArray
6268
:: Int
6369
-> String
@@ -75,6 +81,7 @@ saveArray (fromIntegral -> idx) key (Array fptr) filename (fromIntegral . fromEn
7581
af_save_array ptrIdx keyCstr
7682
ptr filenameCstr append
7783

84+
-- | Reads Array by index
7885
readArrayIndex
7986
:: String
8087
-> Int
@@ -83,6 +90,7 @@ readArrayIndex str (fromIntegral -> idx) =
8390
withCString str $ \cstr ->
8491
createArray' (\p -> af_read_array_index p cstr idx)
8592

93+
-- | Reads Array by key
8694
readArrayKey
8795
:: String
8896
-> String
@@ -92,6 +100,7 @@ readArrayKey fn key =
92100
withCString key $ \kcstr ->
93101
createArray' (\p -> af_read_array_key p fcstr kcstr)
94102

103+
-- | Reads Array
95104
readArrayKeyCheck
96105
:: String
97106
-> String
@@ -102,9 +111,11 @@ readArrayKeyCheck a b =
102111
fromIntegral <$>
103112
afCall1 (\p -> af_read_array_key_check p acstr bcstr)
104113

114+
-- | Convert ArrayFire Array to String, used for 'Show' instance
105115
arrayString :: Array a -> String
106116
arrayString a = arrayToString "ArrayFire Array" a 4 False
107117

118+
-- | Convert ArrayFire Array to String
108119
arrayToString
109120
:: String
110121
-> Array a
@@ -120,6 +131,7 @@ arrayToString expr (Array fptr) (fromIntegral -> prec) (fromIntegral . fromEnum
120131

121132
-- af_err af_example_function(af_array* out, const af_array in, const af_someenum_t param);
122133

134+
-- | Retrieve size of ArrayFire data type
123135
getSizeOf :: forall a . AFType a => Proxy a -> Int
124136
getSizeOf proxy =
125137
unsafePerformIO . mask_ . alloca $ \csize -> do

src/ArrayFire/Vision.hs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,36 @@ matchTemplate
158158
matchTemplate a b (fromMatchType -> match)
159159
= op2 a b (\p c d -> af_match_template p c d match)
160160

161+
-- | SUSAN corner detector.
162+
--
163+
-- SUSAN is an acronym standing for Smallest Univalue Segment Assimilating Nucleus. This method places a circular disc over the pixel to be tested (a.k.a nucleus) to compute the corner measure of that corresponding pixel. The region covered by the circular disc is M, and a pixel in this region is represented by m⃗ ∈M where m⃗ 0 is the nucleus. Every pixel in the region is compared to the nucleus using the following comparison function:
164+
--
165+
-- c(m⃗ )=e−((I(m⃗ )−I(m⃗ 0))/t)6
166+
-- where t is radius of the region, I is the brightness of the pixel.
167+
--
168+
-- Response of SUSAN operator is given by the following equation:
169+
--
170+
-- R(M)={g−n(M)if n(M)<g0otherwise,
171+
-- where n(M)=∑m⃗ ∈Mc(m⃗ ), g is named the geometric threshold and n is the number of pixels in the mask which are within t of the nucleus.
172+
--
173+
-- Importance of the parameters, t and g is explained below:
174+
--
175+
-- t determines how similar points have to be to the nucleusbefore they are considered to be a part of the univalue segment
176+
--
177+
-- g determines the minimum size of the univalue segment. For a large enough g, SUSAN operator becomes an edge dectector.
161178
susan
162179
:: Array a
180+
-- ^ is input grayscale/intensity image
163181
-> Int
182+
-- ^ nucleus radius for each pixel neighborhood
164183
-> Float
184+
-- ^ intensity difference threshold a.k.a t from equations in description
165185
-> Float
186+
-- ^ geometric threshold
166187
-> Float
188+
-- ^ is maximum number of features that will be returned by the function
167189
-> Int
190+
-- ^ indicates how many pixels width area should be skipped for corner detection
168191
-> Features
169192
susan (Array fptr) (fromIntegral -> a) b c d (fromIntegral -> e)
170193
= unsafePerformIO . mask_ . withForeignPtr fptr $ \inptr ->
@@ -174,23 +197,58 @@ susan (Array fptr) (fromIntegral -> a) b c d (fromIntegral -> e)
174197
peek aptr
175198
Features <$> newForeignPtr af_release_features feat
176199

200+
-- | Difference of Gaussians.
201+
--
202+
-- Given an image, this function computes two different versions of smoothed input image using the difference smoothing parameters and subtracts one from the other and returns the result.
203+
--
177204
dog
178205
:: Array a
206+
-- ^ is input image
179207
-> Int
208+
-- ^ is the radius of first gaussian kernel
180209
-> Int
210+
-- ^ is the radius of second gaussian kernel
181211
-> Array a
182-
dog a (fromIntegral -> x) (fromIntegral -> y) =
212+
-- ^ is difference of smoothed inputs
213+
dog a (fromIntegral -> x) (fromIntegral -> y) =
183214
op1 a (\p c -> af_dog p c x y)
184215

216+
-- | Homography Estimation.
217+
--
218+
-- Homography estimation find a perspective transform between two sets of 2D points.
219+
-- Currently, two methods are supported for the estimation, RANSAC (RANdom SAmple Consensus)
220+
-- and LMedS (Least Median of Squares). Both methods work by randomly selecting a subset of 4 points
221+
-- of the set of source points, computing the eigenvectors of that set and finding the perspective transform.
222+
-- The process is repeated several times, a maximum of times given by the value passed to the iterations arguments
223+
-- for RANSAC (for the CPU backend, usually less than that, depending on the quality of the dataset,
224+
-- but for CUDA and OpenCL backends the transformation will be computed exactly the amount of times passed via
225+
-- the iterations parameter), the returned value is the one that matches the best number of inliers, which are
226+
-- all of the points that fall within a maximum L2 distance from the value passed to the inlier_thr argument.
227+
-- For the LMedS case, the number of iterations is currently hardcoded to meet the following equation:
228+
--
229+
-- m=log(1−P)log[1−(1−ϵ)p],
230+
--
231+
-- where P=0.99, ϵ=40% and p=4.
185232
homography
186233
:: forall a . AFType a
187234
=> Array a
235+
-- ^ x coordinates of the source points.
188236
-> Array a
237+
-- ^ y coordinates of the source points.
189238
-> Array a
239+
-- ^ x coordinates of the destination points.
190240
-> Array a
241+
-- ^ y coordinates of the destination points.
191242
-> HomographyType
243+
-- ^ htype, can be AF_HOMOGRAPHY_RANSAC, for which a
244+
-- RANdom SAmple Consensus will be used to evaluate
245+
-- the homography quality (e.g., number of inliers),
246+
-- or AF_HOMOGRAPHY_LMEDS, which will use
247+
-- Least Median of Squares method to evaluate homography quality.
192248
-> Float
249+
-- ^ If htype is AF_HOMOGRAPHY_RANSAC, this parameter will five the maximum L2-distance for a point to be considered an inlier.
193250
-> Int
251+
-- ^ maximum number of iterations when htype is AF_HOMOGRAPHY_RANSAC and backend is CPU, if backend is CUDA or OpenCL, iterations is the total number of iterations, an iteration is a selection of 4 random points for which the homography is estimated and evaluated for number of inliers.
194252
-> (Int, Array a)
195253
homography
196254
(Array a)

0 commit comments

Comments
 (0)