Skip to content

Commit a4cb102

Browse files
committed
Documentation for modules vision & seq
Minor additions to enum descriptions in defines module
1 parent ab1c7be commit a4cb102

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

src/defines.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::error::Error;
22
use std::fmt::{Display, Formatter};
33
use std::fmt::Error as FmtError;
44

5+
/// Error codes
56
#[repr(C)]
67
#[derive(Clone, Copy, Debug)]
78
pub enum AfError {
@@ -75,6 +76,7 @@ impl Error for AfError {
7576
}
7677
}
7778

79+
/// Types of Array data type
7880
#[derive(Copy, Clone)]
7981
pub enum Aftype {
8082
/// 32 bit float
@@ -99,6 +101,7 @@ pub enum Aftype {
99101
U64 = 9,
100102
}
101103

104+
/// Dictates the interpolation method to be used by a function
102105
#[derive(Copy, Clone)]
103106
pub enum InterpType {
104107
/// Nearest Neighbor interpolation method
@@ -111,6 +114,7 @@ pub enum InterpType {
111114
CUBIC = 3,
112115
}
113116

117+
/// Helps determine how to pad kernels along borders
114118
#[derive(Copy, Clone)]
115119
pub enum BorderType {
116120
/// Pad using zeros
@@ -119,6 +123,7 @@ pub enum BorderType {
119123
SYMMETRIC = 1,
120124
}
121125

126+
/// Used by `regions` function to identify type of connectivity
122127
#[derive(Copy, Clone)]
123128
pub enum Connectivity {
124129
/// North-East-South-West (N-E-S-W) connectivity from given pixel/point
@@ -127,6 +132,7 @@ pub enum Connectivity {
127132
EIGHT = 8
128133
}
129134

135+
/// Helps determine the size of output of convolution
130136
#[derive(Copy, Clone)]
131137
pub enum ConvMode {
132138
/// Default convolution mode where output size is same as input size
@@ -135,6 +141,7 @@ pub enum ConvMode {
135141
EXPAND = 1,
136142
}
137143

144+
/// Helps determine if convolution is in Spatial or Frequency domain
138145
#[derive(Copy, Clone)]
139146
pub enum ConvDomain {
140147
/// ArrayFire chooses whether the convolution will be in spatial domain or frequency domain
@@ -145,6 +152,7 @@ pub enum ConvDomain {
145152
FREQUENCY= 2,
146153
}
147154

155+
/// Error metric used by `matchTemplate` function
148156
#[derive(Copy, Clone)]
149157
pub enum MatchType {
150158
/// Sum of Absolute Differences
@@ -167,6 +175,7 @@ pub enum MatchType {
167175
SHD = 8,
168176
}
169177

178+
/// Identify the color space of given image(Array)
170179
#[derive(Copy, Clone)]
171180
pub enum ColorSpace {
172181
/// Grayscale color space
@@ -177,6 +186,7 @@ pub enum ColorSpace {
177186
HSV = 2,
178187
}
179188

189+
/// Helps determine the type of a Matrix
180190
#[derive(Copy, Clone)]
181191
pub enum MatProp {
182192
/// Default (no-op)
@@ -203,6 +213,7 @@ pub enum MatProp {
203213
BLOCKDIAG,
204214
}
205215

216+
/// Norm type
206217
#[allow(non_camel_case_types)]
207218
#[derive(Copy, Clone)]
208219
pub enum NormType {
@@ -224,6 +235,7 @@ pub enum NormType {
224235
MATRIX_L_PQ = 7,
225236
}
226237

238+
/// Dictates what color map is used for Image rendering
227239
#[repr(C)]
228240
#[derive(Copy, Clone)]
229241
pub enum ColorMap {

src/seq.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt;
44
use std::default::Default;
55
use self::libc::{c_double};
66

7+
/// Sequences are used for indexing Arrays
78
#[derive(Copy, Clone)]
89
#[repr(C)]
910
pub struct Seq {
@@ -12,31 +13,37 @@ pub struct Seq {
1213
step: c_double,
1314
}
1415

16+
/// Default `Seq` spans all the elements along a dimension
1517
impl Default for Seq {
1618
fn default() -> Seq {
1719
Seq { begin: 1.0, end: 1.0, step: 0.0, }
1820
}
1921
}
2022

23+
/// Enables use of `Seq` with `{}` format in print statements
2124
impl fmt::Display for Seq {
2225
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2326
write!(f, "[begin: {}, end: {}, step: {}]", self.begin, self.end, self.step)
2427
}
2528
}
2629

2730
impl Seq {
31+
/// Create a `Seq` that goes from `begin` to `end` at a step size of `step`
2832
pub fn new(begin: f64, end: f64, step: f64) -> Seq {
2933
Seq { begin: begin, end: end, step: step, }
3034
}
3135

36+
/// Get begin index of Seq
3237
pub fn begin(&self) -> f64 {
3338
self.begin as f64
3439
}
3540

41+
/// Get begin index of Seq
3642
pub fn end(&self) -> f64 {
3743
self.end as f64
3844
}
3945

46+
/// Get step size of Seq
4047
pub fn step(&self) -> f64 {
4148
self.step as f64
4249
}

src/vision/mod.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ extern {
3737
mtype: uint8_t) -> c_int;
3838
}
3939

40+
/// A set of Array objects (usually, used in Computer vision context)
41+
///
42+
/// `Features` struct is used by computer vision functions
43+
/// to return the outcome of their operation. Typically, such output
44+
/// has the following Arrays:
45+
///
46+
/// - X positions of the features
47+
/// - Y positions of the features
48+
/// - Scores of the features
49+
/// - Orientations of the features
50+
/// - Sizes of the features
4051
pub struct Features {
4152
feat: i64,
4253
}
@@ -70,6 +81,7 @@ impl Features {
7081
}
7182
}
7283

84+
/// Get total number of features found
7385
pub fn num_features(&self) -> Result<i64, AfError> {
7486
unsafe {
7587
let mut temp: i64 = 0;
@@ -119,6 +131,34 @@ impl Drop for Features {
119131
}
120132
}
121133

134+
/// Fast feature detector
135+
///
136+
/// A circle of radius 3 pixels, translating into a total of 16 pixels, is checked for sequential
137+
/// segments of pixels much brighter or much darker than the central one. For a pixel p to be
138+
/// considered a feature, there must exist a sequential segment of arc_length pixels in the circle
139+
/// around it such that all are greather than (p + thr) or smaller than (p - thr). After all
140+
/// features in the image are detected, if nonmax is true, the non-maximal suppression is applied,
141+
/// checking all detected features and the features detected in its 8-neighborhood and discard it
142+
/// if its score is non maximal.
143+
///
144+
/// # Parameters
145+
///
146+
/// - `input` - the input image Array
147+
/// - `thr` - FAST threshold for which pixel of the circle around the center pixel is considered to
148+
/// be greater or smaller
149+
/// - `arc_len` - length of arc (or sequential segment) to be tested, must be within range [9-16]
150+
/// - `non_max` - performs non-maximal supression if true
151+
/// - `feat_ratio` - maximum ratio of features to detect, the maximum number of features is
152+
/// calculated by `feature_ratio * num of elements`. The maximum number of features is not based on
153+
/// the score, instead, features detected after the limit is reached are discarded.
154+
/// - `edge` - is the length of the edges in the image to be discarded by FAST(minimum is 3, as the
155+
/// radius of the circle)
156+
///
157+
/// # Return Values
158+
///
159+
/// This function returns an object of struct [Features](./struct.Features.html) containing Arrays
160+
/// for x and y coordinates and score, while array oreientation is set to 0 as FAST does not
161+
/// compute orientation. Size is set to 1 as FAST does not compute multiple scales.
122162
#[allow(unused_mut)]
123163
pub fn fast(input: &Array, thr: f32, arc_len: u32,
124164
non_max: bool, feat_ratio: f32, edge: u32) -> Result<Features, AfError> {
@@ -134,6 +174,28 @@ pub fn fast(input: &Array, thr: f32, arc_len: u32,
134174
}
135175
}
136176

177+
/// ORB feature descriptor
178+
///
179+
/// Extract ORB descriptors from FAST features that hold higher Harris responses. FAST does not
180+
/// compute orientation, thus, orientation of features is calculated using the intensity centroid.
181+
/// As FAST is also not multi-scale enabled, a multi-scale pyramid is calculated by downsampling
182+
/// the input image multiple times followed by FAST feature detection on each scale.
183+
///
184+
/// # Parameters
185+
///
186+
/// - `input` - the input image Array
187+
/// - `fast_thr` - FAST threshold for which a pixel of the circle around the central pixel is
188+
/// considered to be brighter or darker
189+
/// - `max_feat` - maximum number of features to hold
190+
/// - `scl_fctr` - factor to downsample the input image, meaning that each level with hold prior
191+
/// level dimensions divided by `scl_fctr`
192+
/// - `levels` - number of levels to be computed for the image pyramid
193+
/// - `blur_img` - blur image with a Gaussian filter with sigma=2 before computing descriptors to
194+
/// increase robustness against noise if true
195+
///
196+
/// # Return Values
197+
///
198+
/// This function returns a tuple of [`Features`](./struct.Features.html) and [`Array`](./struct.Array.html). The features objects composed of Arrays for x and y coordinates, score, orientation and size of selected features. The Array object is a two dimensional Array of size Nx8 where N is number of selected features.
137199
#[allow(unused_mut)]
138200
pub fn orb(input: &Array, fast_thr: f32, max_feat: u32,
139201
scl_fctr: f32, levels: u32, blur_img: bool) -> Result<(Features, Array), AfError> {
@@ -150,6 +212,38 @@ pub fn orb(input: &Array, fast_thr: f32, max_feat: u32,
150212
}
151213
}
152214

215+
/// Hamming feature matcher
216+
///
217+
/// Calculates Hamming distances between two 2-dimensional arrays containing features, one of the
218+
/// arrays containing the training data and the other the query data. One of the dimensions of the
219+
/// both arrays must be equal among them, identifying the length of each feature. The other
220+
/// dimension indicates the total number of features in each of the training and query arrays. Two
221+
/// 1-dimensional arrays are created as results, one containg the smallest N distances of the query
222+
/// array and another containing the indices of these distances in the training array. The
223+
/// resulting 1-dimensional arrays have length equal to the number of features contained in the
224+
/// query array.
225+
///
226+
/// # Parameters
227+
///
228+
/// - `query` - Array containing the data to be queried
229+
/// - `train` - Array containing the data to be used as training data
230+
/// - `dist_dims` - indicates the dimension to analyze for distance (the dimension indicated here
231+
/// must be of equal length for both query and train arrays)
232+
/// - `n_dist` - is the number of smallest distances to return (currently, only 1 is supported)
233+
///
234+
///
235+
/// # Return Values
236+
///
237+
/// This function returns a tuple of [Array](./struct.Array.html)'s.
238+
///
239+
/// First Array is an array of MxN size, where M is equal to the number of query features and N is
240+
/// equal to n_dist. The value at position IxJ indicates the index of the Jth smallest distance to
241+
/// the Ith query value in the train data array. the index of the Ith smallest distance of the Mth
242+
/// query.
243+
///
244+
/// Second Array is an array of MxN size, where M is equal to the number of query features and N is
245+
/// equal to n_dist. The value at position IxJ indicates the Hamming distance of the Jth smallest
246+
/// distance to the Ith query value in the train data array.
153247
#[allow(unused_mut)]
154248
pub fn hamming_matcher(query: &Array, train: &Array,
155249
dist_dims: i64, n_dist: u32) -> Result<(Array, Array), AfError> {
@@ -166,6 +260,20 @@ pub fn hamming_matcher(query: &Array, train: &Array,
166260
}
167261
}
168262

263+
/// Image matching
264+
///
265+
/// Template matching is an image processing technique to find small patches of an image which
266+
/// match a given template image. A more in depth discussion on the topic can be found
267+
/// [here](https://en.wikipedia.org/wiki/Template_matching).
268+
///
269+
/// # Parameters
270+
///
271+
/// `search_img` - is an array with image data
272+
/// `template_img` - is the template we are looking for in the image
273+
/// `mtype` - 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 [MatchType](./enum.MatchType.html).
274+
/// # Return Values
275+
///
276+
/// This function returns an Array with disparity values for the window starting at corresponding pixel position.
169277
#[allow(unused_mut)]
170278
pub fn match_template(search_img: &Array, template_img: &Array,
171279
mtype: MatchType) -> Result<Array, AfError> {

0 commit comments

Comments
 (0)