[python-arrayfire] 136/250: FEAT: adding new image processing functions from 3.1 - wrap - unwrap - sat - ycbcr2rgb - rgb2ycbcr

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit dc83b492a707c7df8758197280d92d17402ccc32
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Nov 10 12:14:04 2015 -0500

    FEAT: adding new image processing functions from 3.1
    - wrap
    - unwrap
    - sat
    - ycbcr2rgb
    - rgb2ycbcr
    
    Added missing enums
---
 arrayfire/image.py    | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++
 arrayfire/library.py  |  30 +++++++
 arrayfire/vision.py   |   6 +-
 tests/simple/image.py |  12 +++
 4 files changed, 269 insertions(+), 2 deletions(-)

diff --git a/arrayfire/image.py b/arrayfire/image.py
index 36a279a..c46cc3a 100644
--- a/arrayfire/image.py
+++ b/arrayfire/image.py
@@ -893,3 +893,226 @@ def color_space(image, to_type, from_type):
     safe_call(backend.get().af_color_space(ct.pointer(output.arr), image.arr,
                                            to_type.value, from_type.value))
     return output
+
+def unwrap(image, wx, wy, sx, sy, px=0, py=0, is_column=True):
+    """
+    Unrwap an image into an array.
+
+    Parameters
+    ----------
+
+    image  : af.Array
+           A multi dimensional array specifying an image or batch of images.
+
+    wx     : Integer.
+           Block window size along the first dimension.
+
+    wy     : Integer.
+           Block window size along the second dimension.
+
+    sx     : Integer.
+           Stride along the first dimension.
+
+    sy     : Integer.
+           Stride along the second dimension.
+
+    px     : Integer. Optional. Default: 0
+           Padding along the first dimension.
+
+    py     : Integer. Optional. Default: 0
+           Padding along the second dimension.
+
+    is_column : Boolean. Optional. Default: True.
+           Specifies if the patch should be laid along row or columns.
+
+    Returns
+    -------
+
+    out   : af.Array
+          A multi dimensional array contianing the image patches along specified dimension.
+
+    Examples
+    --------
+    >>> import arrayfire as af
+    >>> a = af.randu(6, 6)
+    >>> af.display(a)
+
+    [6 6 1 1]
+        0.4107     0.3775     0.0901     0.8060     0.0012     0.9250
+        0.8224     0.3027     0.5933     0.5938     0.8703     0.3063
+        0.9518     0.6456     0.1098     0.8395     0.5259     0.9313
+        0.1794     0.5591     0.1046     0.1933     0.1443     0.8684
+        0.4198     0.6600     0.8827     0.7270     0.3253     0.6592
+        0.0081     0.0764     0.1647     0.0322     0.5081     0.4387
+
+    >>> b = af.unwrap(a, 2, 2, 2, 2)
+    >>> af.display(b)
+
+    [4 9 1 1]
+        0.4107     0.9518     0.4198     0.0901     0.1098     0.8827     0.0012     0.5259     0.3253
+        0.8224     0.1794     0.0081     0.5933     0.1046     0.1647     0.8703     0.1443     0.5081
+        0.3775     0.6456     0.6600     0.8060     0.8395     0.7270     0.9250     0.9313     0.6592
+        0.3027     0.5591     0.0764     0.5938     0.1933     0.0322     0.3063     0.8684     0.4387
+    """
+
+    out = Array()
+    safe_call(backend.get().af_unwrap(ct.pointer(out.arr), image.arr,
+                                      ct.c_longlong(wx), ct.c_longlong(wy),
+                                      ct.c_longlong(sx), ct.c_longlong(sy),
+                                      ct.c_longlong(px), ct.c_longlong(py),
+                                      is_column))
+    return out
+
+def wrap(a, ox, oy, wx, wy, sx, sy, px=0, py=0, is_column=True):
+    """
+    Wrap an array into an image.
+
+    Parameters
+    ----------
+
+    a      : af.Array
+           A multi dimensional array containing patches of images.
+
+    wx     : Integer.
+           Block window size along the first dimension.
+
+    wy     : Integer.
+           Block window size along the second dimension.
+
+    sx     : Integer.
+           Stride along the first dimension.
+
+    sy     : Integer.
+           Stride along the second dimension.
+
+    px     : Integer. Optional. Default: 0
+           Padding along the first dimension.
+
+    py     : Integer. Optional. Default: 0
+           Padding along the second dimension.
+
+    is_column : Boolean. Optional. Default: True.
+           Specifies if the patch should be laid along row or columns.
+
+    Returns
+    -------
+
+    out   : af.Array
+          A multi dimensional array contianing the images.
+
+
+    Examples
+    --------
+    >>> import arrayfire as af
+    >>> a = af.randu(6, 6)
+    >>> af.display(a)
+
+    [6 6 1 1]
+        0.4107     0.3775     0.0901     0.8060     0.0012     0.9250
+        0.8224     0.3027     0.5933     0.5938     0.8703     0.3063
+        0.9518     0.6456     0.1098     0.8395     0.5259     0.9313
+        0.1794     0.5591     0.1046     0.1933     0.1443     0.8684
+        0.4198     0.6600     0.8827     0.7270     0.3253     0.6592
+        0.0081     0.0764     0.1647     0.0322     0.5081     0.4387
+
+    >>> b = af.unwrap(a, 2, 2, 2, 2)
+    >>> af.display(b)
+
+    [4 9 1 1]
+        0.4107     0.9518     0.4198     0.0901     0.1098     0.8827     0.0012     0.5259     0.3253
+        0.8224     0.1794     0.0081     0.5933     0.1046     0.1647     0.8703     0.1443     0.5081
+        0.3775     0.6456     0.6600     0.8060     0.8395     0.7270     0.9250     0.9313     0.6592
+        0.3027     0.5591     0.0764     0.5938     0.1933     0.0322     0.3063     0.8684     0.4387
+
+    >>> af.display(c)
+
+    [6 6 1 1]
+        0.4107     0.3775     0.0901     0.8060     0.0012     0.9250
+        0.8224     0.3027     0.5933     0.5938     0.8703     0.3063
+        0.9518     0.6456     0.1098     0.8395     0.5259     0.9313
+        0.1794     0.5591     0.1046     0.1933     0.1443     0.8684
+        0.4198     0.6600     0.8827     0.7270     0.3253     0.6592
+        0.0081     0.0764     0.1647     0.0322     0.5081     0.4387
+
+
+    """
+
+    out = Array()
+    safe_call(backend.get().af_wrap(ct.pointer(out.arr), a.arr,
+                                    ct.c_longlong(ox), ct.c_longlong(oy),
+                                    ct.c_longlong(wx), ct.c_longlong(wy),
+                                    ct.c_longlong(sx), ct.c_longlong(sy),
+                                    ct.c_longlong(px), ct.c_longlong(py),
+                                    is_column))
+    return out
+
+def sat(image):
+    """
+    Summed Area Tables
+
+    Parameters
+    ----------
+    image : af.Array
+          A multi dimensional array specifying image or batch of images
+
+    Returns
+    -------
+    out  : af.Array
+         A multi dimensional array containing the summed area table of input image
+    """
+
+    out = Array()
+    safe_call(backend.get().af_sat(ct.pointer(out.arr), image.arr))
+    return out
+
+def ycbcr2rgb(image, standard=YCC_STD.BT_601):
+    """
+    YCbCr to RGB colorspace conversion.
+
+    Parameters
+    ----------
+
+    image   : af.Array
+              A multi dimensional array containing an image or batch of images in YCbCr format.
+
+    standard: YCC_STD. optional. default: YCC_STD.BT_601
+            - Specifies the YCbCr format.
+            - Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020.
+
+    Returns
+    --------
+
+    out     : af.Array
+            A multi dimensional array containing an image or batch of images in RGB format
+
+    """
+
+    out = Array()
+    safe_call(backend.get().af_ycbcr2rgb(ct.pointer(out.arr), image.arr, standard.value))
+    return out
+
+def rgb2ycbcr(image, standard=YCC_STD.BT_601):
+    """
+    RGB to YCbCr colorspace conversion.
+
+    Parameters
+    ----------
+
+    image   : af.Array
+              A multi dimensional array containing an image or batch of images in RGB format.
+
+    standard: YCC_STD. optional. default: YCC_STD.BT_601
+            - Specifies the YCbCr format.
+            - Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020.
+
+    Returns
+    --------
+
+    out     : af.Array
+            A multi dimensional array containing an image or batch of images in YCbCr format
+
+    """
+
+    out = Array()
+    safe_call(backend.get().af_rgb2ycbcr(ct.pointer(out.arr), image.arr, standard.value))
+    return out
diff --git a/arrayfire/library.py b/arrayfire/library.py
index ce833b5..49f1a37 100644
--- a/arrayfire/library.py
+++ b/arrayfire/library.py
@@ -108,6 +108,7 @@ class ERR(_Enum):
     # 300-399 Errors for missing software features
     NOT_SUPPORTED  = _Enum_Type(301)
     NOT_CONFIGURED = _Enum_Type(302)
+    NONFREE        = _Enum_Type(303)
 
     # 400-499 Errors for missing hardware features
     NO_DBL         = _Enum_Type(401)
@@ -147,6 +148,7 @@ class INTERP(_Enum):
     LINEAR    = _Enum_Type(1)
     BILINEAR  = _Enum_Type(2)
     CUBIC     = _Enum_Type(3)
+    LOWER     = _Enum_Type(4)
 
 class PAD(_Enum):
     """
@@ -227,6 +229,15 @@ class MATCH(_Enum):
     """
     SHD  = _Enum_Type(8)
 
+
+class YCC_STD(_Enum):
+    """
+    YCC Standard formats
+    """
+    BT_601   = _Enum_Type(601)
+    BT_709   = _Enum_Type(709)
+    BT_2020  = _Enum_Type(2020)
+
 class CSPACE(_Enum):
     """
     Colorspace formats
@@ -234,6 +245,7 @@ class CSPACE(_Enum):
     GRAY = _Enum_Type(0)
     RGB  = _Enum_Type(1)
     HSV  = _Enum_Type(2)
+    YCbCr= _Enum_Type(3)
 
 class MATPROP(_Enum):
     """
@@ -320,3 +332,21 @@ class COLORMAP(_Enum):
     MOOD     = _Enum_Type(4)
     HEAT     = _Enum_Type(5)
     BLUE     = _Enum_Type(6)
+
+class IMAGE_FORMAT(_Enum):
+    """
+    Image Formats
+    """
+    BMP      = _Enum_Type(0)
+    ICO      = _Enum_Type(1)
+    JPEG     = _Enum_Type(2)
+    JNG      = _Enum_Type(3)
+    PNG      = _Enum_Type(13)
+    PPM      = _Enum_Type(14)
+    PPMRAW   = _Enum_Type(15)
+    TIFF     = _Enum_Type(18)
+    PSD      = _Enum_Type(20)
+    HDR      = _Enum_Type(26)
+    EXR      = _Enum_Type(29)
+    JP2      = _Enum_Type(31)
+    RAW      = _Enum_Type(34)
diff --git a/arrayfire/vision.py b/arrayfire/vision.py
index 877a8a8..b345c7c 100644
--- a/arrayfire/vision.py
+++ b/arrayfire/vision.py
@@ -202,7 +202,7 @@ def nearest_neighbour(query, database, dim = 0, num_nearest = 1, match_type=MATC
     safe_call(backend.get().af_nearest_neighbour(ct.pointer(idx.arr), ct.pointer(dist.arr),
                                                  query.arr, database.arr,
                                                  ct.c_longlong(dim), ct.c_longlong(num_nearest),
-                                                 match_type))
+                                                 match_type.value))
     return index, dist
 
 def match_template(image, template, match_type = MATCH.SAD):
@@ -228,7 +228,9 @@ def match_template(image, template, match_type = MATCH.SAD):
 
     """
     out = Array()
-    safe_call(backend.get().af_match_template(ct.pointer(out.arr), image.arr, template.arr, match_type))
+    safe_call(backend.get().af_match_template(ct.pointer(out.arr),
+                                              image.arr, template.arr,
+                                              match_type.value))
     return out
 
 def susan(image, radius=3, diff_thr=32, geom_thr=10, feature_ratio=0.05, edge=3):
diff --git a/tests/simple/image.py b/tests/simple/image.py
index 31f0abd..7fdfa90 100644
--- a/tests/simple/image.py
+++ b/tests/simple/image.py
@@ -64,4 +64,16 @@ def simple_image(verbose = False):
 
     display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))
 
+    a = af.randu(6,6)
+    b = af.unwrap(a, 2, 2, 2, 2)
+    c = af.wrap(b, 6, 6, 2, 2, 2, 2)
+    display_func(a)
+    display_func(b)
+    display_func(c)
+    display_func(af.sat(a))
+
+    a = af.randu(10,10,3)
+    display_func(af.rgb2ycbcr(a))
+    display_func(af.ycbcr2rgb(a))
+
 _util.tests['image'] = simple_image

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list