Skip to content
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 Color transforms #275

Merged
merged 10 commits into from
Oct 4, 2017
Merged

Add Color transforms #275

merged 10 commits into from
Oct 4, 2017

Conversation

chsasank
Copy link
Contributor

Please see #271 for the discussion.

Currently added Hue and saturation colour transforms based on tf code: https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/python/ops/image_ops_impl.py

@chsasank
Copy link
Contributor Author

chsasank commented Sep 27, 2017

@alykhantejani just to confirm, gamma correction should be done on V channel of HSV right?

Edit: looks like not. RGB channels are corrected together. Ref

Also
* Change adjust_saturation to use pillow implementation
* Documentation made clear
@chsasank
Copy link
Contributor Author

I'm not using code from #27 because implementations are on tensors not on PIL images.

@chsasank
Copy link
Contributor Author

chsasank commented Sep 27, 2017

Hey @alykhantejani, I have actually implemented all the transforms: brightness, contrast, saturation and gamma. I need to implement a transform class (and tests) using these functions and PR would be complete. I think this makes #27 redundant actually.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
I have only one comment that I think should be addressed (the overflow warning), the rest are minor details.
Also, could you add basic tests to those transforms?


np_h = np.array(h, dtype='uint8')
# uint8 addition take cares of rotation across boundaries
np_h += np.uint8(hue_factor * 255)

This comment was marked as off-topic.


h, s, v = img.convert('HSV').split()

np_h = np.array(h, dtype='uint8')

This comment was marked as off-topic.

This comment was marked as off-topic.


img = img.convert('RGB')

np_img = np.array(img)

This comment was marked as off-topic.

np.random.shuffle(transforms)
transform = Compose(transforms)

return transform

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@alykhantejani alykhantejani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chsasank!

LGTM once we change the requirement for input images to be RGB.



def adjust_contrast(img, contrast_factor):
"""Adjust brightness of an Image.

This comment was marked as off-topic.

2 will enhance the saturation by a factor of 2.

Returns:
Adjusted image(s), same shape and DType as `image`.

This comment was marked as off-topic.

"""Adjust hue of an image.

`image` is an RGB image. The image hue is adjusted by converting the
image to HSV and cyclically shifting the intensities in hue channel (H).

This comment was marked as off-topic.

Returns:
PIL.Image: Hue adjusted image.
"""
if not(hue_factor <= 0.5 and hue_factor >= -0.5):

This comment was marked as off-topic.

PIL.Image: Hue adjusted image.
"""
if not(hue_factor <= 0.5 and hue_factor >= -0.5):
raise ValueError('hue_factor {} out of range.'.format(hue_factor))

This comment was marked as off-topic.

def adjust_hue(img, hue_factor):
"""Adjust hue of an image.

`image` is an RGB image. The image hue is adjusted by converting the

This comment was marked as off-topic.

np_img = 255 * gain * ((np_img / 255) ** gamma)
np_img = np.uint8(np.clip(np_img, 0, 255))

img = Image.fromarray(np_img, 'RGB')

This comment was marked as off-topic.

@chsasank
Copy link
Contributor Author

chsasank commented Oct 2, 2017

Can somebody guide me how to write tests for these? As in what do I check for etc.

@alykhantejani
Copy link
Contributor

@chsasank you can use the TF tests for these transforms as reference, located here

input_mode = img.mode
img = img.convert('RGB')

np_img = np.array(img, dtype='float32')

This comment was marked as off-topic.

@fmassa fmassa merged commit 618072b into pytorch:master Oct 4, 2017
@fmassa
Copy link
Member

fmassa commented Oct 4, 2017

Thanks a lot @chsasank !

@Kaixhin
Copy link
Contributor

Kaixhin commented Oct 5, 2017

Quick! Thanks @chsasank! Would it be possible to also document these on the readme?

@alykhantejani
Copy link
Contributor

@Kaixhin I think we actually should solve the root issue and get these docs autogenerated from the docstrings themselves, like it's done in the pytorch repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants