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

x/image/draw: color space-correct interpolation #11420

Open
aclements opened this issue Jun 26, 2015 · 4 comments
Open

x/image/draw: color space-correct interpolation #11420

aclements opened this issue Jun 26, 2015 · 4 comments
Labels
Milestone

Comments

@aclements
Copy link
Member

@aclements aclements commented Jun 26, 2015

The BiLinear and CatmullRom interpolators assume the luminance of the source image's color space is linear. But the vast majority of images are in the sRGB color space, which has a highly non-linear luminance curve. As a result, scaled images can look quite different from the source image.

For example, on a reasonably calibrated monitor (and at 100% scaling in the browser), the left and right columns of the following image have the same average luminance:
gamma_colors
But scaling this down by a factor of 2 using x/image/draw yields the following:
out
Here, the two columns appear very different.

For an in-depth (possibly too in-depth) discussion of this problem and many test images, including the one I used above, see http://www.4p8.com/eric.brasseur/gamma.html. My test program is here: https://gist.github.com/aclements/599107a2e3f187f8a2c0.

A lot of software (including browsers) gets this wrong, and that's really unfortunate. It would be fantastic if Go software using x/image got this right out of the box.

Probably the best solution to this would be to thread color space information throughout the image library. At the other extreme, given the general recommendation to assume sRGB in the absence of other information (since virtually every image created in the past two decades is sRGB), it may make sense to simply assume sRGB when interpolating. We could also do the latter first and then later add more complete color space support, with the default being sRGB. Another option is to add this information to the x/image/draw.Options structure, though I fear that may interfere with later adding proper color space support to image.

/cc @nigeltao. (We discussed this a few weeks ago in person, but I figured I should open an issue so it doesn't get lost.)

@aclements aclements added the Suggested label Jun 26, 2015
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jul 11, 2015
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 11, 2015

@rselph
Copy link

@rselph rselph commented Dec 22, 2017

Just wanted to bump this issue. I'm working on creating test images from golang, and it's a constant headache having to do proper color space encoding myself. It's an issue that the vast majority of casual users are oblivious to, but one that affects image quality profoundly, as @aclements pointed out.

@nigeltao
Copy link
Contributor

@nigeltao nigeltao commented Jan 5, 2018

Yes, it's a valid feature request. No, I don't know anyone with all three of the time, expertise and inclination to work on it any time soon. Sorry.

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 8, 2020

Change https://golang.org/cl/253497 mentions this issue: x/image/draw: gamma corrected non linear interpolation

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.