Skip to content

Commit a42f9d9

Browse files
Howalsoumith
authored andcommitted
use PIL's point-function to accelerate adjust_gamma (#410)
1 parent f5d486c commit a42f9d9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

torchvision/transforms/functional.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,10 @@ def adjust_gamma(img, gamma, gain=1):
523523
input_mode = img.mode
524524
img = img.convert('RGB')
525525

526-
np_img = np.array(img, dtype=np.float32)
527-
np_img = 255 * gain * ((np_img / 255) ** gamma)
528-
np_img = np.uint8(np.clip(np_img, 0, 255))
526+
gamma_map = [255 * gain * pow(ele / 255., gamma) for ele in range(256)] * 3
527+
img = img.point(gamma_map) # use PIL's point-function to accelerate this part
529528

530-
img = Image.fromarray(np_img, 'RGB').convert(input_mode)
529+
img = img.convert(input_mode)
531530
return img
532531

533532

0 commit comments

Comments
 (0)