|
1 | 1 | extern crate libc; |
2 | 2 |
|
3 | 3 | use array::Array; |
4 | | -use defines::{AfError, BorderType, ColorSpace, Connectivity, InterpType, YCCStd}; |
| 4 | +use defines::{AfError, BorderType, ColorSpace, Connectivity, InterpType, YCCStd, MomentType}; |
5 | 5 | use error::HANDLE_ERROR; |
6 | 6 | use util::HasAfEnum; |
7 | 7 | use self::libc::{uint8_t, c_uint, c_int, c_float, c_double}; |
@@ -93,6 +93,9 @@ extern { |
93 | 93 | fn af_rgb2ycbcr(out: MutAfArray, input: AfArray, stnd: c_int) -> c_int; |
94 | 94 | fn af_is_image_io_available(out: *mut c_int) -> c_int; |
95 | 95 | fn af_transform_coordinates(out: MutAfArray, tf: AfArray, d0: c_float, d1: c_float) -> c_int; |
| 96 | + |
| 97 | + fn af_moments(out: MutAfArray, input: AfArray, moment: c_int) ->c_int; |
| 98 | + fn af_moments_all(out: *mut c_double, input: AfArray, moment: c_int) ->c_int; |
96 | 99 | } |
97 | 100 |
|
98 | 101 | /// Calculate the gradients |
@@ -1136,3 +1139,47 @@ pub fn transform_coords(tf: &Array, d0: f32, d1: f32) -> Array { |
1136 | 1139 | Array::from(temp) |
1137 | 1140 | } |
1138 | 1141 | } |
| 1142 | + |
| 1143 | +/// Find Image moments |
| 1144 | +/// |
| 1145 | +/// # Parameters |
| 1146 | +/// |
| 1147 | +/// - `input` is the input image |
| 1148 | +/// - `moment` is the type of moment to be computed, takes a value of |
| 1149 | +/// [enum](./enum.MomentType.html) |
| 1150 | +/// |
| 1151 | +/// # Return Values |
| 1152 | +/// |
| 1153 | +/// Moments Array |
| 1154 | +pub fn moments(input: &Array, moment: MomentType) -> Array { |
| 1155 | + unsafe { |
| 1156 | + let mut temp: i64 = 0; |
| 1157 | + let err_val = af_moments(&mut temp as MutAfArray, |
| 1158 | + input.get() as AfArray, |
| 1159 | + moment as c_int); |
| 1160 | + HANDLE_ERROR(AfError::from(err_val)); |
| 1161 | + Array::from(temp) |
| 1162 | + } |
| 1163 | +} |
| 1164 | + |
| 1165 | +/// Find Image moment for whole image |
| 1166 | +/// |
| 1167 | +/// # Parameters |
| 1168 | +/// |
| 1169 | +/// - `input` is the input image |
| 1170 | +/// - `moment` is the type of moment to be computed, takes a value of |
| 1171 | +/// [enum](./enum.MomentType.html) |
| 1172 | +/// |
| 1173 | +/// # Return Values |
| 1174 | +/// |
| 1175 | +/// Moment value of the whole image |
| 1176 | +pub fn moments_all(input: &Array, moment: MomentType) -> f64 { |
| 1177 | + unsafe { |
| 1178 | + let mut temp: f64 = 0.0; |
| 1179 | + let err_val = af_moments_all(&mut temp as *mut c_double, |
| 1180 | + input.get() as AfArray, |
| 1181 | + moment as c_int); |
| 1182 | + HANDLE_ERROR(AfError::from(err_val)); |
| 1183 | + temp |
| 1184 | + } |
| 1185 | +} |
0 commit comments