@@ -1190,7 +1190,7 @@ def invert(img: Tensor) -> Tensor:
1190
1190
dimensions.
1191
1191
1192
1192
Returns:
1193
- PIL Image: Color inverted image.
1193
+ PIL Image or Tensor : Color inverted image.
1194
1194
"""
1195
1195
if not isinstance (img , torch .Tensor ):
1196
1196
return F_pil .invert (img )
@@ -1208,7 +1208,7 @@ def posterize(img: Tensor, bits: int) -> Tensor:
1208
1208
it can have an arbitrary number of trailing dimensions.
1209
1209
bits (int): The number of bits to keep for each channel (0-8).
1210
1210
Returns:
1211
- PIL Image: Posterized image.
1211
+ PIL Image or Tensor : Posterized image.
1212
1212
"""
1213
1213
if not (0 <= bits <= 8 ):
1214
1214
raise ValueError ('The number if bits should be between 0 and 8. Got {}' .format (bits ))
@@ -1229,7 +1229,7 @@ def solarize(img: Tensor, threshold: float) -> Tensor:
1229
1229
dimensions.
1230
1230
threshold (float): All pixels equal or above this value are inverted.
1231
1231
Returns:
1232
- PIL Image: Solarized image.
1232
+ PIL Image or Tensor : Solarized image.
1233
1233
"""
1234
1234
if not isinstance (img , torch .Tensor ):
1235
1235
return F_pil .solarize (img , threshold )
@@ -1253,3 +1253,23 @@ def adjust_sharpness(img: Tensor, sharpness_factor: float) -> Tensor:
1253
1253
return F_pil .adjust_sharpness (img , sharpness_factor )
1254
1254
1255
1255
return F_t .adjust_sharpness (img , sharpness_factor )
1256
+
1257
+
1258
+ def autocontrast (img : Tensor ) -> Tensor :
1259
+ """Maximize contrast of a PIL Image or torch Tensor by remapping its
1260
+ pixels per channel so that the lowest becomes black and the lightest
1261
+ becomes white.
1262
+
1263
+ Args:
1264
+ img (PIL Image or Tensor): Image on which autocontrast is applied.
1265
+ If img is a Tensor, it is expected to be in [..., H, W] format,
1266
+ where ... means it can have an arbitrary number of trailing
1267
+ dimensions.
1268
+
1269
+ Returns:
1270
+ PIL Image or Tensor: An image that was autocontrasted.
1271
+ """
1272
+ if not isinstance (img , torch .Tensor ):
1273
+ return F_pil .autocontrast (img )
1274
+
1275
+ return F_t .autocontrast (img )
0 commit comments