Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bf7c01

Browse files
committed
FEAT: Adding canny edge detector
1 parent 8e84d60 commit 8bf7c01

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

‎arrayfire/image.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,47 @@ def moments(image, moment = MOMENT.FIRST_ORDER):
11941194
safe_call(backend.get().af_moments(c_pointer(output.arr), image.arr, moment.value))
11951195
return output
11961196

1197+
def canny(image,
1198+
low_threshold, high_threshold = None,
1199+
treshold_type = CANNY_THRESHOLD.MANUAL,
1200+
sobel_window = 3, is_fast = False):
1201+
"""
1202+
Canny edge detector.
1203+
1204+
Parameters
1205+
----------
1206+
image : af.Array
1207+
- A 2 D arrayfire array representing an image
1208+
1209+
threshold_type : optional: af.CANNY_THRESHOLD. default: af.CANNY_THRESHOLD.MANUAL.
1210+
Can be one of:
1211+
- af.CANNY_THRESHOLD.MANUAL
1212+
- af.CANNY_THRESHOLD.AUTO_OTSU
1213+
1214+
low_threshold : required: float.
1215+
Specifies the % of maximum in gradient image if threshold_type is MANUAL.
1216+
Specifies the % of auto dervied high value if threshold_type is AUTO_OTSU.
1217+
1218+
high_threshold : optional: float. default: None
1219+
Specifies the % of maximum in gradient image if threshold_type is MANUAL.
1220+
Ignored if threshold_type is AUTO_OTSU
1221+
1222+
sobel_window : optional: int. default: 3
1223+
Specifies the size of sobel kernel when computing the gradient image.
1224+
1225+
Returns
1226+
--------
1227+
1228+
out : af.Array
1229+
- A binary image containing the edges
1230+
1231+
"""
1232+
output = Array()
1233+
safe_call(backend.get().af_canny(c_pointer(output.arr), threshold_type.value,
1234+
low_threshold, high_threshold and high_threshold.value or 0,
1235+
c_uint(sobel_window), c_bool(is_fast)))
1236+
return output
1237+
11971238
def is_image_io_available():
11981239
"""
11991240
Function to check if the arrayfire library was built with Image IO support.

‎arrayfire/library.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ class STORAGE(_Enum):
413413
CSC = _Enum_Type(2)
414414
COO = _Enum_Type(3)
415415

416+
class CANNY_THRESHOLD(_Enum):
417+
"""
418+
Canny Edge Threshold types
419+
"""
420+
MANUAL = _Enum_Type(0)
421+
AUTO_OTSU = _Enum_Type(1)
422+
416423
_VER_MAJOR_PLACEHOLDER = "__VER_MAJOR__"
417424

418425
def _setup():

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /