Code Monkey home page Code Monkey logo

Comments (3)

disintegration avatar disintegration commented on July 20, 2024

Hi,

You're right. I'm aware of the colorspace issue. Adding a colorspace conversions into every processing function will drop the performance considerably, especially if you have several processing steps. I think it's better to do what the article suggests manually. With imaging you can apply a gamma correction before and after the image processing:

dst := imaging.AdjustGamma(src, 1/2.2)
dst = imaging.Resize(dst , src.Bounds().Dx()/2, src.Bounds().Dy()/2, imaging.Lanczos)
dst = imaging.AdjustGamma(dst, 2.2)

Please also take a look at the another package I created, that aims at the higher quality image processing: github.com/disintegration/gift. I've implemented special filters that use the right formula to convert the colorspace to linear and back. It also allows to use 16bit per channel images as a target. The respective example:

g := gift.New(
        gift.ColorspaceSRGBToLinear(),
        gift.Resize(src.Bounds().Dx()/2, src.Bounds().Dy()/2, gift.LanczosResampling),
        gift.ColorspaceLinearToSRGB(),
)
dst := image.NewRGBA64(g.Bounds(src.Bounds()))
g.Draw(dst, src)

from imaging.

pftbest avatar pftbest commented on July 20, 2024

Thanks for reply!
I understand that adding conversions into every step will incur a huge performance penalty, but the fact is it is not even possible to do it right with the current implementation.
The problem is that imaging library works on NRGBA images only, but linear RGB values require at least 16bit color depth.

small example:

dst := imaging.AdjustGamma(src, 1/2.2)
dst = imaging.AdjustGamma(dst, 2.2)
Original image Filtered image
original filtered

gift library on the other hand uses proper NRGBA64 temp images in between filter steps, so this code:

g := gift.New(
        gift.ColorspaceSRGBToLinear(),
        // some filtering...
        gift.ColorspaceLinearToSRGB(),
)
dst := image.NewRGBA(g.Bounds(src.Bounds()))
g.Draw(dst, src)

will work fine. and there is no need for destination image to be NRGBA64 because it is back to sRGB space after the ColorspaceLinearToSRGB step.

So at the end my suggestion is to add this information in README file, to make users aware of the issue and let them know how to deal with it.

P.S. Sorry for my bad english.

from imaging.

disintegration avatar disintegration commented on July 20, 2024

Yes, my AdjustGamma example was actually not very good. While it fixes the issue, the conversion can be quite lossy for 8-bit images. It's the limitation of this package. That's why I suggest to use gift if you need more quality. And it's one of the reasons why I even created gift and these sRGB<->Linear filters.

I think the difference between linear and sRGB resizing isn't critical for a lot of applications and it's the reason why lots of image libraries and editors don't implement this conversion. For these applications imaging works good enough. Maybe it's a good idea to write about it in the README, because sometimes people ask me what's the difference between these two packages. I'll think about it.

from imaging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.