@@ -1232,6 +1232,48 @@ def test_adjust_hue(self):
1232
1232
y_ans = np .array (y_ans , dtype = np .uint8 ).reshape (x_shape )
1233
1233
self .assertTrue (np .allclose (y_np , y_ans ))
1234
1234
1235
+ def test_adjust_sharpness (self ):
1236
+ x_shape = [4 , 4 , 3 ]
1237
+ x_data = [75 , 121 , 114 , 105 , 97 , 107 , 105 , 32 , 66 , 111 , 117 , 114 , 99 , 104 , 97 , 0 ,
1238
+ 0 , 65 , 108 , 101 , 120 , 97 , 110 , 100 , 101 , 114 , 32 , 86 , 114 , 121 , 110 , 105 ,
1239
+ 111 , 116 , 105 , 115 , 0 , 0 , 73 , 32 , 108 , 111 , 118 , 101 , 32 , 121 , 111 , 117 ]
1240
+ x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1241
+ x_pil = Image .fromarray (x_np , mode = 'RGB' )
1242
+
1243
+ # test 0
1244
+ y_pil = F .adjust_sharpness (x_pil , 1 )
1245
+ y_np = np .array (y_pil )
1246
+ self .assertTrue (np .allclose (y_np , x_np ))
1247
+
1248
+ # test 1
1249
+ y_pil = F .adjust_sharpness (x_pil , 0.5 )
1250
+ y_np = np .array (y_pil )
1251
+ y_ans = [75 , 121 , 114 , 105 , 97 , 107 , 105 , 32 , 66 , 111 , 117 , 114 , 99 , 104 , 97 , 30 ,
1252
+ 30 , 74 , 103 , 96 , 114 , 97 , 110 , 100 , 101 , 114 , 32 , 81 , 103 , 108 , 102 , 101 ,
1253
+ 107 , 116 , 105 , 115 , 0 , 0 , 73 , 32 , 108 , 111 , 118 , 101 , 32 , 121 , 111 , 117 ]
1254
+ y_ans = np .array (y_ans , dtype = np .uint8 ).reshape (x_shape )
1255
+ self .assertTrue (np .allclose (y_np , y_ans ))
1256
+
1257
+ # test 2
1258
+ y_pil = F .adjust_sharpness (x_pil , 2 )
1259
+ y_np = np .array (y_pil )
1260
+ y_ans = [75 , 121 , 114 , 105 , 97 , 107 , 105 , 32 , 66 , 111 , 117 , 114 , 99 , 104 , 97 , 0 ,
1261
+ 0 , 46 , 118 , 111 , 132 , 97 , 110 , 100 , 101 , 114 , 32 , 95 , 135 , 146 , 126 , 112 ,
1262
+ 119 , 116 , 105 , 115 , 0 , 0 , 73 , 32 , 108 , 111 , 118 , 101 , 32 , 121 , 111 , 117 ]
1263
+ y_ans = np .array (y_ans , dtype = np .uint8 ).reshape (x_shape )
1264
+ self .assertTrue (np .allclose (y_np , y_ans ))
1265
+
1266
+ # test 3
1267
+ x_shape = [2 , 2 , 3 ]
1268
+ x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
1269
+ x_np = np .array (x_data , dtype = np .uint8 ).reshape (x_shape )
1270
+ x_pil = Image .fromarray (x_np , mode = 'RGB' )
1271
+ x_th = torch .tensor (x_np .transpose (2 , 0 , 1 ))
1272
+ y_pil = F .adjust_sharpness (x_pil , 2 )
1273
+ y_np = np .array (y_pil ).transpose (2 , 0 , 1 )
1274
+ y_th = F .adjust_sharpness (x_th , 2 )
1275
+ self .assertTrue (np .allclose (y_np , y_th .numpy ()))
1276
+
1235
1277
def test_adjust_gamma (self ):
1236
1278
x_shape = [2 , 2 , 3 ]
1237
1279
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
@@ -1268,10 +1310,11 @@ def test_adjusts_L_mode(self):
1268
1310
self .assertEqual (F .adjust_saturation (x_l , 2 ).mode , 'L' )
1269
1311
self .assertEqual (F .adjust_contrast (x_l , 2 ).mode , 'L' )
1270
1312
self .assertEqual (F .adjust_hue (x_l , 0.4 ).mode , 'L' )
1313
+ self .assertEqual (F .adjust_sharpness (x_l , 2 ).mode , 'L' )
1271
1314
self .assertEqual (F .adjust_gamma (x_l , 0.5 ).mode , 'L' )
1272
1315
1273
1316
def test_color_jitter (self ):
1274
- color_jitter = transforms .ColorJitter (2 , 2 , 2 , 0.1 )
1317
+ color_jitter = transforms .ColorJitter (2 , 2 , 2 , 0.1 , 2 )
1275
1318
1276
1319
x_shape = [2 , 2 , 3 ]
1277
1320
x_data = [0 , 5 , 13 , 54 , 135 , 226 , 37 , 8 , 234 , 90 , 255 , 1 ]
0 commit comments