| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -893,3 +893,226 @@ def color_space(image, to_type, from_type): | |||
| 893 | 893 | safe_call(backend.get().af_color_space(ct.pointer(output.arr), image.arr, | |
| 894 | 894 | to_type.value, from_type.value)) | |
| 895 | 895 | return output | |
| 896 | + | ||
| 897 | + def unwrap(image, wx, wy, sx, sy, px=0, py=0, is_column=True): | ||
| 898 | + """ | ||
| 899 | + Unrwap an image into an array. | ||
| 900 | + | ||
| 901 | + Parameters | ||
| 902 | + ---------- | ||
| 903 | + | ||
| 904 | + image : af.Array | ||
| 905 | + A multi dimensional array specifying an image or batch of images. | ||
| 906 | + | ||
| 907 | + wx : Integer. | ||
| 908 | + Block window size along the first dimension. | ||
| 909 | + | ||
| 910 | + wy : Integer. | ||
| 911 | + Block window size along the second dimension. | ||
| 912 | + | ||
| 913 | + sx : Integer. | ||
| 914 | + Stride along the first dimension. | ||
| 915 | + | ||
| 916 | + sy : Integer. | ||
| 917 | + Stride along the second dimension. | ||
| 918 | + | ||
| 919 | + px : Integer. Optional. Default: 0 | ||
| 920 | + Padding along the first dimension. | ||
| 921 | + | ||
| 922 | + py : Integer. Optional. Default: 0 | ||
| 923 | + Padding along the second dimension. | ||
| 924 | + | ||
| 925 | + is_column : Boolean. Optional. Default: True. | ||
| 926 | + Specifies if the patch should be laid along row or columns. | ||
| 927 | + | ||
| 928 | + Returns | ||
| 929 | + ------- | ||
| 930 | + | ||
| 931 | + out : af.Array | ||
| 932 | + A multi dimensional array contianing the image patches along specified dimension. | ||
| 933 | + | ||
| 934 | + Examples | ||
| 935 | + -------- | ||
| 936 | + >>> import arrayfire as af | ||
| 937 | + >>> a = af.randu(6, 6) | ||
| 938 | + >>> af.display(a) | ||
| 939 | + | ||
| 940 | + [6 6 1 1] | ||
| 941 | + 0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 | ||
| 942 | + 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 | ||
| 943 | + 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 | ||
| 944 | + 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 | ||
| 945 | + 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 | ||
| 946 | + 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387 | ||
| 947 | + | ||
| 948 | + >>> b = af.unwrap(a, 2, 2, 2, 2) | ||
| 949 | + >>> af.display(b) | ||
| 950 | + | ||
| 951 | + [4 9 1 1] | ||
| 952 | + 0.4107 0.9518 0.4198 0.0901 0.1098 0.8827 0.0012 0.5259 0.3253 | ||
| 953 | + 0.8224 0.1794 0.0081 0.5933 0.1046 0.1647 0.8703 0.1443 0.5081 | ||
| 954 | + 0.3775 0.6456 0.6600 0.8060 0.8395 0.7270 0.9250 0.9313 0.6592 | ||
| 955 | + 0.3027 0.5591 0.0764 0.5938 0.1933 0.0322 0.3063 0.8684 0.4387 | ||
| 956 | + """ | ||
| 957 | + | ||
| 958 | + out = Array() | ||
| 959 | + safe_call(backend.get().af_unwrap(ct.pointer(out.arr), image.arr, | ||
| 960 | + ct.c_longlong(wx), ct.c_longlong(wy), | ||
| 961 | + ct.c_longlong(sx), ct.c_longlong(sy), | ||
| 962 | + ct.c_longlong(px), ct.c_longlong(py), | ||
| 963 | + is_column)) | ||
| 964 | + return out | ||
| 965 | + | ||
| 966 | + def wrap(a, ox, oy, wx, wy, sx, sy, px=0, py=0, is_column=True): | ||
| 967 | + """ | ||
| 968 | + Wrap an array into an image. | ||
| 969 | + | ||
| 970 | + Parameters | ||
| 971 | + ---------- | ||
| 972 | + | ||
| 973 | + a : af.Array | ||
| 974 | + A multi dimensional array containing patches of images. | ||
| 975 | + | ||
| 976 | + wx : Integer. | ||
| 977 | + Block window size along the first dimension. | ||
| 978 | + | ||
| 979 | + wy : Integer. | ||
| 980 | + Block window size along the second dimension. | ||
| 981 | + | ||
| 982 | + sx : Integer. | ||
| 983 | + Stride along the first dimension. | ||
| 984 | + | ||
| 985 | + sy : Integer. | ||
| 986 | + Stride along the second dimension. | ||
| 987 | + | ||
| 988 | + px : Integer. Optional. Default: 0 | ||
| 989 | + Padding along the first dimension. | ||
| 990 | + | ||
| 991 | + py : Integer. Optional. Default: 0 | ||
| 992 | + Padding along the second dimension. | ||
| 993 | + | ||
| 994 | + is_column : Boolean. Optional. Default: True. | ||
| 995 | + Specifies if the patch should be laid along row or columns. | ||
| 996 | + | ||
| 997 | + Returns | ||
| 998 | + ------- | ||
| 999 | + | ||
| 1000 | + out : af.Array | ||
| 1001 | + A multi dimensional array contianing the images. | ||
| 1002 | + | ||
| 1003 | + | ||
| 1004 | + Examples | ||
| 1005 | + -------- | ||
| 1006 | + >>> import arrayfire as af | ||
| 1007 | + >>> a = af.randu(6, 6) | ||
| 1008 | + >>> af.display(a) | ||
| 1009 | + | ||
| 1010 | + [6 6 1 1] | ||
| 1011 | + 0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 | ||
| 1012 | + 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 | ||
| 1013 | + 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 | ||
| 1014 | + 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 | ||
| 1015 | + 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 | ||
| 1016 | + 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387 | ||
| 1017 | + | ||
| 1018 | + >>> b = af.unwrap(a, 2, 2, 2, 2) | ||
| 1019 | + >>> af.display(b) | ||
| 1020 | + | ||
| 1021 | + [4 9 1 1] | ||
| 1022 | + 0.4107 0.9518 0.4198 0.0901 0.1098 0.8827 0.0012 0.5259 0.3253 | ||
| 1023 | + 0.8224 0.1794 0.0081 0.5933 0.1046 0.1647 0.8703 0.1443 0.5081 | ||
| 1024 | + 0.3775 0.6456 0.6600 0.8060 0.8395 0.7270 0.9250 0.9313 0.6592 | ||
| 1025 | + 0.3027 0.5591 0.0764 0.5938 0.1933 0.0322 0.3063 0.8684 0.4387 | ||
| 1026 | + | ||
| 1027 | + >>> af.display(c) | ||
| 1028 | + | ||
| 1029 | + [6 6 1 1] | ||
| 1030 | + 0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 | ||
| 1031 | + 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 | ||
| 1032 | + 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 | ||
| 1033 | + 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 | ||
| 1034 | + 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 | ||
| 1035 | + 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387 | ||
| 1036 | + | ||
| 1037 | + | ||
| 1038 | + """ | ||
| 1039 | + | ||
| 1040 | + out = Array() | ||
| 1041 | + safe_call(backend.get().af_wrap(ct.pointer(out.arr), a.arr, | ||
| 1042 | + ct.c_longlong(ox), ct.c_longlong(oy), | ||
| 1043 | + ct.c_longlong(wx), ct.c_longlong(wy), | ||
| 1044 | + ct.c_longlong(sx), ct.c_longlong(sy), | ||
| 1045 | + ct.c_longlong(px), ct.c_longlong(py), | ||
| 1046 | + is_column)) | ||
| 1047 | + return out | ||
| 1048 | + | ||
| 1049 | + def sat(image): | ||
| 1050 | + """ | ||
| 1051 | + Summed Area Tables | ||
| 1052 | + | ||
| 1053 | + Parameters | ||
| 1054 | + ---------- | ||
| 1055 | + image : af.Array | ||
| 1056 | + A multi dimensional array specifying image or batch of images | ||
| 1057 | + | ||
| 1058 | + Returns | ||
| 1059 | + ------- | ||
| 1060 | + out : af.Array | ||
| 1061 | + A multi dimensional array containing the summed area table of input image | ||
| 1062 | + """ | ||
| 1063 | + | ||
| 1064 | + out = Array() | ||
| 1065 | + safe_call(backend.get().af_sat(ct.pointer(out.arr), image.arr)) | ||
| 1066 | + return out | ||
| 1067 | + | ||
| 1068 | + def ycbcr2rgb(image, standard=YCC_STD.BT_601): | ||
| 1069 | + """ | ||
| 1070 | + YCbCr to RGB colorspace conversion. | ||
| 1071 | + | ||
| 1072 | + Parameters | ||
| 1073 | + ---------- | ||
| 1074 | + | ||
| 1075 | + image : af.Array | ||
| 1076 | + A multi dimensional array containing an image or batch of images in YCbCr format. | ||
| 1077 | + | ||
| 1078 | + standard: YCC_STD. optional. default: YCC_STD.BT_601 | ||
| 1079 | + - Specifies the YCbCr format. | ||
| 1080 | + - Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020. | ||
| 1081 | + | ||
| 1082 | + Returns | ||
| 1083 | + -------- | ||
| 1084 | + | ||
| 1085 | + out : af.Array | ||
| 1086 | + A multi dimensional array containing an image or batch of images in RGB format | ||
| 1087 | + | ||
| 1088 | + """ | ||
| 1089 | + | ||
| 1090 | + out = Array() | ||
| 1091 | + safe_call(backend.get().af_ycbcr2rgb(ct.pointer(out.arr), image.arr, standard.value)) | ||
| 1092 | + return out | ||
| 1093 | + | ||
| 1094 | + def rgb2ycbcr(image, standard=YCC_STD.BT_601): | ||
| 1095 | + """ | ||
| 1096 | + RGB to YCbCr colorspace conversion. | ||
| 1097 | + | ||
| 1098 | + Parameters | ||
| 1099 | + ---------- | ||
| 1100 | + | ||
| 1101 | + image : af.Array | ||
| 1102 | + A multi dimensional array containing an image or batch of images in RGB format. | ||
| 1103 | + | ||
| 1104 | + standard: YCC_STD. optional. default: YCC_STD.BT_601 | ||
| 1105 | + - Specifies the YCbCr format. | ||
| 1106 | + - Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020. | ||
| 1107 | + | ||
| 1108 | + Returns | ||
| 1109 | + -------- | ||
| 1110 | + | ||
| 1111 | + out : af.Array | ||
| 1112 | + A multi dimensional array containing an image or batch of images in YCbCr format | ||
| 1113 | + | ||
| 1114 | + """ | ||
| 1115 | + | ||
| 1116 | + out = Array() | ||
| 1117 | + safe_call(backend.get().af_rgb2ycbcr(ct.pointer(out.arr), image.arr, standard.value)) | ||
| 1118 | + return out | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,7 @@ class ERR(_Enum): | |||
| 108 | 108 | # 300-399 Errors for missing software features | |
| 109 | 109 | NOT_SUPPORTED = _Enum_Type(301) | |
| 110 | 110 | NOT_CONFIGURED = _Enum_Type(302) | |
| 111 | + NONFREE = _Enum_Type(303) | ||
| 111 | 112 | ||
| 112 | 113 | # 400-499 Errors for missing hardware features | |
| 113 | 114 | NO_DBL = _Enum_Type(401) | |
@@ -147,6 +148,7 @@ class INTERP(_Enum): | |||
| 147 | 148 | LINEAR = _Enum_Type(1) | |
| 148 | 149 | BILINEAR = _Enum_Type(2) | |
| 149 | 150 | CUBIC = _Enum_Type(3) | |
| 151 | + LOWER = _Enum_Type(4) | ||
| 150 | 152 | ||
| 151 | 153 | class PAD(_Enum): | |
| 152 | 154 | """ | |
@@ -227,13 +229,23 @@ class MATCH(_Enum): | |||
| 227 | 229 | """ | |
| 228 | 230 | SHD = _Enum_Type(8) | |
| 229 | 231 | ||
| 232 | + | ||
| 233 | + class YCC_STD(_Enum): | ||
| 234 | + """ | ||
| 235 | + YCC Standard formats | ||
| 236 | + """ | ||
| 237 | + BT_601 = _Enum_Type(601) | ||
| 238 | + BT_709 = _Enum_Type(709) | ||
| 239 | + BT_2020 = _Enum_Type(2020) | ||
| 240 | + | ||
| 230 | 241 | class CSPACE(_Enum): | |
| 231 | 242 | """ | |
| 232 | 243 | Colorspace formats | |
| 233 | 244 | """ | |
| 234 | 245 | GRAY = _Enum_Type(0) | |
| 235 | 246 | RGB = _Enum_Type(1) | |
| 236 | 247 | HSV = _Enum_Type(2) | |
| 248 | + YCbCr= _Enum_Type(3) | ||
| 237 | 249 | ||
| 238 | 250 | class MATPROP(_Enum): | |
| 239 | 251 | """ | |
@@ -320,3 +332,21 @@ class COLORMAP(_Enum): | |||
| 320 | 332 | MOOD = _Enum_Type(4) | |
| 321 | 333 | HEAT = _Enum_Type(5) | |
| 322 | 334 | BLUE = _Enum_Type(6) | |
| 335 | + | ||
| 336 | + class IMAGE_FORMAT(_Enum): | ||
| 337 | + """ | ||
| 338 | + Image Formats | ||
| 339 | + """ | ||
| 340 | + BMP = _Enum_Type(0) | ||
| 341 | + ICO = _Enum_Type(1) | ||
| 342 | + JPEG = _Enum_Type(2) | ||
| 343 | + JNG = _Enum_Type(3) | ||
| 344 | + PNG = _Enum_Type(13) | ||
| 345 | + PPM = _Enum_Type(14) | ||
| 346 | + PPMRAW = _Enum_Type(15) | ||
| 347 | + TIFF = _Enum_Type(18) | ||
| 348 | + PSD = _Enum_Type(20) | ||
| 349 | + HDR = _Enum_Type(26) | ||
| 350 | + EXR = _Enum_Type(29) | ||
| 351 | + JP2 = _Enum_Type(31) | ||
| 352 | + RAW = _Enum_Type(34) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,7 +202,7 @@ def nearest_neighbour(query, database, dim = 0, num_nearest = 1, match_type=MATC | |||
| 202 | 202 | safe_call(backend.get().af_nearest_neighbour(ct.pointer(idx.arr), ct.pointer(dist.arr), | |
| 203 | 203 | query.arr, database.arr, | |
| 204 | 204 | ct.c_longlong(dim), ct.c_longlong(num_nearest), | |
| 205 | - match_type)) | ||
| 205 | + match_type.value)) | ||
| 206 | 206 | return index, dist | |
| 207 | 207 | ||
| 208 | 208 | def match_template(image, template, match_type = MATCH.SAD): | |
@@ -228,7 +228,9 @@ def match_template(image, template, match_type = MATCH.SAD): | |||
| 228 | 228 | ||
| 229 | 229 | """ | |
| 230 | 230 | out = Array() | |
| 231 | - safe_call(backend.get().af_match_template(ct.pointer(out.arr), image.arr, template.arr, match_type)) | ||
| 231 | + safe_call(backend.get().af_match_template(ct.pointer(out.arr), | ||
| 232 | + image.arr, template.arr, | ||
| 233 | + match_type.value)) | ||
| 232 | 234 | return out | |
| 233 | 235 | ||
| 234 | 236 | def susan(image, radius=3, diff_thr=32, geom_thr=10, feature_ratio=0.05, edge=3): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,4 +64,16 @@ def simple_image(verbose = False): | |||
| 64 | 64 | ||
| 65 | 65 | display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY)) | |
| 66 | 66 | ||
| 67 | + a = af.randu(6,6) | ||
| 68 | + b = af.unwrap(a, 2, 2, 2, 2) | ||
| 69 | + c = af.wrap(b, 6, 6, 2, 2, 2, 2) | ||
| 70 | + display_func(a) | ||
| 71 | + display_func(b) | ||
| 72 | + display_func(c) | ||
| 73 | + display_func(af.sat(a)) | ||
| 74 | + | ||
| 75 | + a = af.randu(10,10,3) | ||
| 76 | + display_func(af.rgb2ycbcr(a)) | ||
| 77 | + display_func(af.ycbcr2rgb(a)) | ||
| 78 | + | ||
| 67 | 79 | _util.tests['image'] = simple_image | |
| Back | FazBrowse Home | New Git URL |
0 commit comments