-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gamma invert transform #1309
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1371,6 +1371,8 @@ class RandomGamma(ImageOnlyTransform): | |
Args: | ||
gamma_limit (float or (float, float)): If gamma_limit is a single float value, | ||
the range will be (-gamma_limit, gamma_limit). Default: (80, 120). | ||
p_invert (float): Probability of applying transform symmetrical to gamma transform with respect to the y=x. | ||
Identical to sequentially applied InvertImg, RandomGamma and InvertImg. Default: 0.0. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
eps: Deprecated. | ||
|
||
Targets: | ||
|
@@ -1380,16 +1382,23 @@ class RandomGamma(ImageOnlyTransform): | |
uint8, float32 | ||
""" | ||
|
||
def __init__(self, gamma_limit=(80, 120), eps=None, always_apply=False, p=0.5): | ||
def __init__(self, gamma_limit=(80, 120), p_invert=0.0, eps=None, always_apply=False, p=0.5): | ||
super(RandomGamma, self).__init__(always_apply, p) | ||
self.gamma_limit = to_tuple(gamma_limit) | ||
self.p_invert = p_invert | ||
self.eps = eps | ||
|
||
def apply(self, img, gamma=1, **params): | ||
return F.gamma_transform(img, gamma=gamma) | ||
def apply(self, img, gamma=1, invert=False, **params): | ||
if invert: | ||
return F.gamma_invert_transform(img, gamma=gamma) | ||
else: | ||
return F.gamma_transform(img, gamma=gamma) | ||
|
||
def get_params(self): | ||
return {"gamma": random.uniform(self.gamma_limit[0], self.gamma_limit[1]) / 100.0} | ||
return { | ||
"gamma": random.uniform(self.gamma_limit[0], self.gamma_limit[1]) / 100.0, | ||
"invert": random.random() > self.p_invert, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect condition. Must be |
||
} | ||
|
||
def get_transform_init_args_names(self): | ||
return ("gamma_limit", "eps") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, add |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better to take max value from
MAX_VALUES_BY_DTYPE
because img might have int32 dtype