-
Notifications
You must be signed in to change notification settings - Fork 2.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
[Feature] Add Rerange transform #228
Changes from 2 commits
0b2ac67
f951e8e
bfba700
d0bc3c7
62462c6
f0c0272
982e3e9
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 |
---|---|---|
|
@@ -390,6 +390,54 @@ def __repr__(self): | |
return repr_str | ||
|
||
|
||
@PIPELINES.register_module() | ||
class Rerange(object): | ||
"""Rerange the image pixel value. | ||
|
||
Args: | ||
min_value (float or int): Minimum value of the reranged image. | ||
Default: 0. | ||
max_value (float or int): Maximum value of the reranged image. | ||
Default: 255. | ||
""" | ||
|
||
def __init__(self, min_value=0, max_value=255): | ||
assert isinstance(min_value, float) or isinstance(min_value, int) | ||
assert isinstance(max_value, float) or isinstance(max_value, int) | ||
assert min_value < max_value | ||
self.min_value = min_value | ||
self.max_value = max_value | ||
|
||
def __call__(self, results): | ||
"""Call function to rerange images. | ||
|
||
Args: | ||
results (dict): Result dict from loading pipeline. | ||
|
||
Returns: | ||
dict: Reranged results, 'img_rerange_cfg' key is added into | ||
result dict. | ||
""" | ||
|
||
img = results['img'] | ||
img_min_value = np.min(img) | ||
img_max_value = np.max(img) | ||
# rerange to [0, 1] | ||
img = (img - img_min_value) / (img_max_value - img_min_value) | ||
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. If we are reading an image with range [0.1, 1] (no pixel is black), 0.1 will be mapped to 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. That's exactly what it's going to do. |
||
# rerange to [min_value, max_value] | ||
img = img * (self.max_value - self.min_value) + self.min_value | ||
results['img'] = img | ||
|
||
results['img_rerange_cfg'] = dict( | ||
min_value=self.min_value, max_value=self.max_value) | ||
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. What's the purpose of |
||
return results | ||
|
||
def __repr__(self): | ||
repr_str = self.__class__.__name__ | ||
repr_str += f'(min_value={self.min_value}, max_value={self.max_value})' | ||
return repr_str | ||
|
||
|
||
@PIPELINES.register_module() | ||
class RandomCrop(object): | ||
"""Random crop the image & seg. | ||
|
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.
Not updated
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.
Sorry, I forget it!