Skip to content

Commit 0fc23d8

Browse files
committed
Update Vision documentation.
1 parent 8ac1491 commit 0fc23d8

File tree

3 files changed

+108
-30
lines changed

3 files changed

+108
-30
lines changed

src/ArrayFire/BLAS.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
--
1313
-- @
1414
-- main :: IO ()
15-
-- main = 'print' ('matmul' x y xProp yProp)
15+
-- main = print (matmul x y xProp yProp)
1616
-- where
17-
-- x,y :: 'Array' 'Double'
18-
-- x = 'matrix' (2,3) [1..]
19-
-- y = 'matrix' (3,2) [1..]
17+
-- x,y :: Array Double
18+
-- x = matrix (2,3) [1..]
19+
-- y = matrix (3,2) [1..]
2020
--
21-
-- xProp, yProp :: 'MatProp'
21+
-- xProp, yProp :: MatProp
2222
-- xProp = None
2323
-- yProp = None
2424
-- @

src/ArrayFire/LAPACK.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ norm arr (fromNormType -> a) b c =
263263
-- | Is LAPACK available
264264
--
265265
-- [ArrayFire Docs](http://arrayfire.org/docs/group__lapack__helper__func__available.htm)
266+
--
266267
isLAPACKAvailable
267268
:: Bool
268269
-- ^ Returns if LAPACK is available

src/ArrayFire/Vision.hs

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import ArrayFire.Internal.Types
2828

2929
-- | FAST feature detectors
3030
--
31+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__fast.htm)
32+
--
3133
-- A circle of radius 3 pixels, translating into a total of 16 pixels, is checked for sequential segments of pixels much brighter or much darker than the central one.
3234
-- For a pixel p to be considered a feature, there must exist a sequential segment of arc_length pixels in the circle around it such that all are greather than (p + thr) or smaller than (p - thr).
3335
-- After all features in the image are detected, if nonmax is true, the non-maximal suppression is applied, checking all detected features and the features detected in its 8-neighborhood and discard it if its score is non maximal.
@@ -54,13 +56,25 @@ fast (Array fptr) thr (fromIntegral -> arc) (fromIntegral . fromEnum -> non) rat
5456
Features <$>
5557
newForeignPtr af_release_features feat
5658

59+
-- | Harris corner detection
60+
--
61+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__harris.htm)
62+
--
63+
-- Harris corner detector.
64+
--
5765
harris
5866
:: Array a
67+
-- ^ array containing a grayscale image (color images are not supported)
5968
-> Int
69+
-- ^ maximum number of corners to keep, only retains those with highest Harris responses
6070
-> Float
71+
-- ^ minimum response in order for a corner to be retained, only used if max_corners = 0
6172
-> Float
73+
-- ^ the standard deviation of a circular window (its dimensions will be calculated according to the standard deviation), the covariation matrix will be calculated to a circular neighborhood of this standard deviation (only used when block_size == 0, must be >= 0.5f and <= 5.0f)
6274
-> Int
75+
-- ^ square window size, the covariation matrix will be calculated to a square neighborhood of this size (must be >= 3 and <= 31)
6376
-> Float
77+
-- ^ struct containing arrays for x and y coordinates and score (Harris response), while arrays orientation and size are set to 0 and 1, respectively, because Harris does not compute that information
6478
-> Features
6579
harris (Array fptr) (fromIntegral -> maxc) minresp sigma (fromIntegral -> bs) thr
6680
= unsafePerformIO . mask_ . withForeignPtr fptr $ \aptr ->
@@ -70,14 +84,27 @@ harris (Array fptr) (fromIntegral -> maxc) minresp sigma (fromIntegral -> bs) th
7084
Features <$>
7185
newForeignPtr af_release_features feat
7286

87+
-- | ORB Feature descriptor
88+
--
89+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__orb.htm)
90+
--
91+
-- Extract ORB descriptors from FAST features that hold higher Harris responses. FAST does not compute orientation, thus, orientation of features is calculated using the intensity centroid. As FAST is also not multi-scale enabled, a multi-scale pyramid is calculated by downsampling the input image multiple times followed by FAST feature detection on each scale.
92+
--
7393
orb
7494
:: Array a
95+
-- ^ 'Array' containing a grayscale image (color images are not supported)
7596
-> Float
97+
-- ^ FAST threshold for which a pixel of the circle around the central pixel is considered to be brighter or darker
7698
-> Int
99+
-- ^ maximum number of features to hold (will only keep the max_feat features with higher Harris responses)
77100
-> Float
101+
-- ^ factor to downsample the input image, meaning that each level will hold prior level dimensions divided by scl_fctr
78102
-> Int
103+
-- ^ number of levels to be computed for the image pyramid
79104
-> Bool
105+
-- ^ blur image with a Gaussian filter with sigma=2 before computing descriptors to increase robustness against noise if true
80106
-> (Features, Array a)
107+
-- ^ 'Features' struct composed of arrays for x and y coordinates, score, orientation and size of selected features
81108
orb (Array fptr) thr (fromIntegral -> feat) scl (fromIntegral -> levels) (fromIntegral . fromEnum -> blur)
82109
= unsafePerformIO . mask_ . withForeignPtr fptr $ \inptr ->
83110
do (feature, arr) <-
@@ -89,16 +116,32 @@ orb (Array fptr) thr (fromIntegral -> feat) scl (fromIntegral -> levels) (fromIn
89116
array <- Array <$> newForeignPtr af_release_array_finalizer arr
90117
pure (feats, array)
91118

119+
-- | SIFT feature detector and descriptor extractor.
120+
--
121+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__sift.htm)
122+
--
123+
-- C Interface for SIFT feature detector and descriptor.
124+
--
92125
sift
93126
:: Array a
127+
-- ^ Array containing a grayscale image (color images are not supported)
94128
-> Int
129+
-- ^ number of layers per octave, the number of octaves is computed automatically according to the input image dimensions, the original SIFT paper suggests 3
95130
-> Float
131+
-- ^ threshold used to filter out features that have low contrast, the original SIFT paper suggests 0.04
96132
-> Float
133+
-- ^ threshold used to filter out features that are too edge-like, the original SIFT paper suggests 10.0
97134
-> Float
135+
-- ^ the sigma value used to filter the input image at the first octave, the original SIFT paper suggests 1.6
98136
-> Bool
137+
-- ^ if true, the input image dimensions will be doubled and the doubled image will be used for the first octave
99138
-> Float
139+
-- ^ the inverse of the difference between the minimum and maximum grayscale intensity value, e.g.: if the ranges are 0-256, the proper intensity_scale value is 1/256, if the ranges are 0-1, the proper intensity-scale value is 1/1
100140
-> Float
141+
-- ^ maximum ratio of features to detect, the maximum number of features is calculated by feature_ratio * in.elements(). The maximum number of features is not based on the score, instead, features detected after the limit is reached are discarded
101142
-> (Features, Array a)
143+
-- ^ Features object composed of arrays for x and y coordinates, score, orientation and size of selected features
144+
-- Nx128 array containing extracted descriptors, where N is the number of features found by SIFT
102145
sift (Array fptr) (fromIntegral -> a) b c d (fromIntegral . fromEnum -> e) f g
103146
= unsafePerformIO . mask_ . withForeignPtr fptr $ \inptr ->
104147
do (feat, arr) <-
@@ -110,16 +153,32 @@ sift (Array fptr) (fromIntegral -> a) b c d (fromIntegral . fromEnum -> e) f g
110153
array <- Array <$> newForeignPtr af_release_array_finalizer arr
111154
pure (feats, array)
112155

156+
-- | SIFT feature detector and descriptor extractor.
157+
--
158+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__gloh.htm)
159+
--
160+
-- C Interface for SIFT feature detector and descriptor.
161+
--
113162
gloh
114163
:: Array a
164+
-- ^ 'Array' containing a grayscale image (color images are not supported)
115165
-> Int
166+
-- ^ number of layers per octave, the number of octaves is computed automatically according to the input image dimensions, the original SIFT paper suggests 3
116167
-> Float
168+
-- ^ threshold used to filter out features that have low contrast, the original SIFT paper suggests 0.04
117169
-> Float
170+
-- ^ threshold used to filter out features that are too edge-like, the original SIFT paper suggests 10.0
118171
-> Float
172+
-- ^ the sigma value used to filter the input image at the first octave, the original SIFT paper suggests 1.6
119173
-> Bool
174+
-- ^ if true, the input image dimensions will be doubled and the doubled image will be used for the first octave
120175
-> Float
176+
-- ^ the inverse of the difference between the minimum and maximum grayscale intensity value, e.g.: if the ranges are 0-256, the proper intensity_scale value is 1/256, if the ranges are 0-1, the proper intensity-scale value is 1/1
121177
-> Float
178+
-- ^ maximum ratio of features to detect, the maximum number of features is calculated by feature_ratio * in.elements(). The maximum number of features is not based on the score, instead, features detected after the limit is reached are discarded
122179
-> (Features, Array a)
180+
-- ^ 'Features' object composed of arrays for x and y coordinates, score, orientation and size of selected features
181+
-- ^ Nx272 array containing extracted GLOH descriptors, where N is the number of features found by SIFT
123182
gloh (Array fptr) (fromIntegral -> a) b c d (fromIntegral . fromEnum -> e) f g
124183
= unsafePerformIO . mask_ . withForeignPtr fptr $ \inptr ->
125184
do (feat, arr) <-
@@ -131,50 +190,74 @@ gloh (Array fptr) (fromIntegral -> a) b c d (fromIntegral . fromEnum -> e) f g
131190
array <- Array <$> newForeignPtr af_release_array_finalizer arr
132191
pure (feats, array)
133192

193+
-- | Hamming Matcher
194+
--
195+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__hamming__matcher.htm)
196+
--
197+
-- Calculates Hamming distances between two 2-dimensional arrays containing features, one of the arrays containing the training data and the other the query data. One of the dimensions of the both arrays must be equal among them, identifying the length of each feature. The other dimension indicates the total number of features in each of the training and query arrays. Two 1-dimensional arrays are created as results, one containg the smallest N distances of the query array and another containing the indices of these distances in the training array. The resulting 1-dimensional arrays have length equal to the number of features contained in the query array.
198+
--
134199
hammingMatcher
135200
:: Array a
201+
-- ^ is the 'Array' containing the data to be queried
136202
-> Array a
203+
-- ^ is the 'Array' containing the data used as training data
137204
-> Int
205+
-- ^ indicates the dimension to analyze for distance (the dimension indicated here must be of equal length for both query and train arrays)
138206
-> Int
207+
-- ^ is the number of smallest distances to return (currently, only 1 is supported)
139208
-> (Array a, Array a)
209+
-- ^ is an array of MxN size, where M is equal to the number of query features and N is equal to n_dist. The value at position IxJ indicates the index of the Jth smallest distance to the Ith query value in the train data array. the index of the Ith smallest distance of the Mth query.
210+
-- is an array of MxN size, where M is equal to the number of query features and N is equal to n_dist. The value at position IxJ indicates the Hamming distance of the Jth smallest distance to the Ith query value in the train data array.
140211
hammingMatcher a b (fromIntegral -> x) (fromIntegral -> y)
141212
= op2p2 a b (\p c d e -> af_hamming_matcher p c d e x y)
142213

214+
-- | Nearest Neighbor
215+
--
216+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__nearest__neighbour.htm)
217+
--
218+
-- Calculates nearest distances between two 2-dimensional arrays containing features based on the type of distance computation chosen. Currently, AF_SAD (sum of absolute differences), AF_SSD (sum of squared differences) and AF_SHD (hamming distance) are supported. One of the arrays containing the training data and the other the query data. One of the dimensions of the both arrays must be equal among them, identifying the length of each feature. The other dimension indicates the total number of features in each of the training and query arrays. Two 1-dimensional arrays are created as results, one containg the smallest N distances of the query array and another containing the indices of these distances in the training array. The resulting 1-dimensional arrays have length equal to the number of features contained in the query array.
219+
--
143220
nearestNeighbor
144221
:: Array a
222+
-- ^ is the array containing the data to be queried
145223
-> Array a
224+
-- ^ is the array containing the data used as training data
146225
-> Int
226+
-- ^ indicates the dimension to analyze for distance (the dimension indicated here must be of equal length for both query and train arrays)
147227
-> Int
228+
-- ^ is the number of smallest distances to return (currently, only values <= 256 are supported)
148229
-> MatchType
230+
-- ^ is the distance computation type. Currently AF_SAD (sum of absolute differences), AF_SSD (sum of squared differences), and AF_SHD (hamming distances) are supported.
149231
-> (Array a, Array a)
232+
-- ^ is an array of MxN size, where M is equal to the number of query features and N is equal to n_dist. The value at position IxJ indicates the index of the Jth smallest distance to the Ith query value in the train data array. the index of the Ith smallest distance of the Mth query.
233+
-- is an array of MxN size, where M is equal to the number of query features and N is equal to n_dist. The value at position IxJ indicates the distance of the Jth smallest distance to the Ith query value in the train data array based on the dist_type chosen.
150234
nearestNeighbor a b (fromIntegral -> x) (fromIntegral -> y) (fromMatchType -> match)
151235
= op2p2 a b (\p c d e -> af_nearest_neighbour p c d e x y match)
152236

237+
-- | Nearest Neighbor
238+
--
239+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__match__template.htm)
240+
--
241+
-- C Interface for image template matching.
242+
--
153243
matchTemplate
154244
:: Array a
245+
-- ^ is an 'Array' with image data
155246
-> Array a
247+
-- ^ is the template we are looking for in the image
156248
-> MatchType
249+
-- ^ is metric that should be used to calculate the disparity between window in the image and the template image. It can be one of the values defined by the enum af_match_type
157250
-> Array a
251+
-- ^ will have disparity values for the window starting at corresponding pixel position
158252
matchTemplate a b (fromMatchType -> match)
159253
= op2 a b (\p c d -> af_match_template p c d match)
160254

161255
-- | SUSAN corner detector.
162256
--
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:
257+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__susan.htm)
169258
--
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
259+
-- 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:
176260
--
177-
-- g determines the minimum size of the univalue segment. For a large enough g, SUSAN operator becomes an edge dectector.
178261
susan
179262
:: Array a
180263
-- ^ is input grayscale/intensity image
@@ -199,6 +282,8 @@ susan (Array fptr) (fromIntegral -> a) b c d (fromIntegral -> e)
199282

200283
-- | Difference of Gaussians.
201284
--
285+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__dog.htm)
286+
--
202287
-- 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.
203288
--
204289
dog
@@ -215,20 +300,10 @@ dog a (fromIntegral -> x) (fromIntegral -> y) =
215300

216301
-- | Homography Estimation.
217302
--
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:
303+
-- [ArrayFire Docs](http://arrayfire.org/docs/group__cv__func__homography.htm)
228304
--
229-
-- m=log(1−P)log[1−(1−ϵ)p],
305+
-- Homography estimation find a perspective transform between two sets of 2D points.
230306
--
231-
-- where P=0.99, ϵ=40% and p=4.
232307
homography
233308
:: forall a . AFType a
234309
=> Array a
@@ -250,6 +325,8 @@ homography
250325
-> Int
251326
-- ^ 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.
252327
-> (Int, Array a)
328+
-- ^ is a 3x3 array containing the estimated homography.
329+
-- is the number of inliers that the homography was estimated to comprise, in the case that htype is AF_HOMOGRAPHY_RANSAC, a higher inlier_thr value will increase the estimated inliers. Note that if the number of inliers is too low, it is likely that a bad homography will be returned.
253330
homography
254331
(Array a)
255332
(Array b)

0 commit comments

Comments
 (0)