@@ -893,3 +893,226 @@ def color_space(image, to_type, from_type):
893893 safe_call (backend .get ().af_color_space (ct .pointer (output .arr ), image .arr ,
894894 to_type .value , from_type .value ))
895895 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
0 commit comments