Skip to content

Commit

Permalink
Added 1 channel support to CLAHE (albumentations-team#190)
Browse files Browse the repository at this point in the history
* Added 1 channel support to CLAHE

* PEP8
  • Loading branch information
ternaus authored Feb 15, 2019
1 parent 97eb72d commit 8d02597
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import division

import math
from functools import wraps
import random
from functools import wraps
from warnings import warn

import cv2
Expand Down Expand Up @@ -297,10 +297,16 @@ def shift_rgb(img, r_shift, g_shift, b_shift):
def clahe(img, clip_limit=2.0, tile_grid_size=(8, 8)):
if img.dtype != np.uint8:
raise TypeError('clahe supports only uint8 inputs')
img = cv2.cvtColor(img, cv2.COLOR_RGB2LAB)

clahe = cv2.createCLAHE(clipLimit=clip_limit, tileGridSize=tile_grid_size)
img[:, :, 0] = clahe.apply(img[:, :, 0])
img = cv2.cvtColor(img, cv2.COLOR_LAB2RGB)

if len(img.shape) == 2:
img = clahe.apply(img)
else:
img = cv2.cvtColor(img, cv2.COLOR_RGB2LAB)
img[:, :, 0] = clahe.apply(img[:, :, 0])
img = cv2.cvtColor(img, cv2.COLOR_LAB2RGB)

return img


Expand Down

0 comments on commit 8d02597

Please sign in to comment.