Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

added augment_equalize_adapthist(img) #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions yolox/data/data_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def augment_hsv(img, hgain=5, sgain=30, vgain=30):
cv2.cvtColor(img_hsv.astype(img.dtype), cv2.COLOR_HSV2BGR, dst=img) # no return needed


def augment_equalize_adapthist(img):
from skimage.exposure import equalize_adapthist
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV).astype(np.int16)

img_hsv[..., 0] = equalize_adapthist(img_hsv[..., 0]).astype(np.int16)

cv2.cvtColor(img_hsv.astype(img.dtype), cv2.COLOR_HSV2BGR, dst=img) # no return needed

def get_aug_params(value, center=0):
if isinstance(value, float):
return random.uniform(center - value, center + value)
Expand Down Expand Up @@ -138,6 +146,11 @@ def _mirror(image, boxes, prob=0.5):
boxes[:, 0::2] = width - boxes[:, 2::-2]
return image, boxes

def _equalize_adapthist(image, boxes, prob=0.1):
if random.random() < prob:
image = augment_equalize_adapthist(image)
return image, boxes


def preproc(img, input_size, swap=(2, 0, 1)):
if len(img.shape) == 3:
Expand Down Expand Up @@ -182,6 +195,7 @@ def __call__(self, image, targets, input_dim):

if random.random() < self.hsv_prob:
augment_hsv(image)
image, boxes = _equalize_adapthist(image, boxes, prob=0.1)
image_t, boxes = _mirror(image, boxes, self.flip_prob)
height, width, _ = image_t.shape
image_t, r_ = preproc(image_t, input_dim)
Expand Down