|
1 | 1 | extern crate libc;
|
2 | 2 |
|
3 | 3 | use array::Array;
|
4 |
| -use defines::{AfError, BorderType, ColorSpace, Connectivity, InterpType, YCCStd, MomentType}; |
| 4 | +use defines::{AfError, BorderType, CannyThresholdType, ColorSpace, Connectivity, InterpType, YCCStd, MomentType}; |
5 | 5 | use error::HANDLE_ERROR;
|
6 | 6 | use util::{AfArray, DimT, HasAfEnum, MutAfArray};
|
7 | 7 | use self::libc::{uint8_t, c_uint, c_int, c_float, c_double, c_char};
|
@@ -95,6 +95,9 @@ extern {
|
95 | 95 |
|
96 | 96 | fn af_moments(out: MutAfArray, input: AfArray, moment: c_int) ->c_int;
|
97 | 97 | fn af_moments_all(out: *mut c_double, input: AfArray, moment: c_int) ->c_int;
|
| 98 | + |
| 99 | + fn af_canny(out: MutAfArray, input: AfArray, thres_type: c_int, low: c_float, high: c_float, |
| 100 | + swindow: c_uint, is_fast: c_int) -> c_int; |
98 | 101 | }
|
99 | 102 |
|
100 | 103 | /// Calculate the gradients
|
@@ -1216,3 +1219,32 @@ pub fn medfilt1(input: &Array, wlen: u64, etype: BorderType) -> Array {
|
1216 | 1219 | Array::from(temp)
|
1217 | 1220 | }
|
1218 | 1221 | }
|
| 1222 | + |
| 1223 | +/// Canny edge detection operator |
| 1224 | +/// |
| 1225 | +/// The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. A more in depth discussion on it can be found [here](https://en.wikipedia.org/wiki/Canny_edge_detector). |
| 1226 | +/// |
| 1227 | +/// # Parameters |
| 1228 | +/// |
| 1229 | +/// - `input` is the input image |
| 1230 | +/// - `threshold_type` helps determine if user set high threshold is to be used or not. It can take values defined by the enum [CannyThresholdType](./enum.CannyThresholdType.html) |
| 1231 | +/// - `low` is the lower threshold % of the maximum or auto-derived high |
| 1232 | +/// - `hight` is the higher threshold % of maximum value in gradient image used in hysteresis procedure. This value is ignored if [CannyThresholdType::OTSU](./enum.CannyThresholdType.html) is chosen. |
| 1233 | +/// - `sobel_window` is the window size of sobel kernel for computing gradient direction and magnitude. |
| 1234 | +/// - `is_fast` indicates if L<SUB>1</SUB> norm(faster but less accurate) is used to compute image gradient magnitude instead of L<SUB>2</SUB> norm. |
| 1235 | +/// |
| 1236 | +/// # Return Values |
| 1237 | +/// |
| 1238 | +/// An Array of binary type [DType::B8](./enum.DType.html) indicating edges(All pixels with |
| 1239 | +/// non-zero values are edges). |
| 1240 | +pub fn canny(input: &Array, threshold_type: CannyThresholdType, low: f32, hight: f32, |
| 1241 | + sobel_window: u32, is_fast: bool) -> Array { |
| 1242 | + unsafe { |
| 1243 | + let mut temp: i64 = 0; |
| 1244 | + let err_val = af_canny(&mut temp as MutAfArray, input.get() as AfArray, |
| 1245 | + threshold_type as c_int, low as c_float, hight as c_float, |
| 1246 | + sobel_window as c_uint, is_fast as c_int); |
| 1247 | + HANDLE_ERROR(AfError::from(err_val)); |
| 1248 | + Array::from(temp) |
| 1249 | + } |
| 1250 | +} |
0 commit comments