Comments (3)
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.
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 |
---|---|
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.
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)
- How to get image width from imaging HOT 1
- Cannot apply transparency HOT 1
- imaging.Open throw error: image: unknown format HOT 2
- How to get file from postman HOT 2
- how can we resize image HOT 3
- Does imaging support wartermark text?
- Images not get fully processed even if background is filled with base color? HOT 1
- resize image become bigger HOT 1
- What is the different Resize and Thumbnail functions? HOT 1
- How to convert png-24 to png-8? HOT 1
- Support HEIF (.heic) files with AutoOrientation HOT 1
- Panic in the Rotate90 function.
- Export fixOrientation HOT 1
- Paste function panics
- Rotated image background won't blend according to Alpha when pasting
- Specific image will cause the index of the scan function in scanner.go to go out of bounds
- Snyk reports vulnerability HOT 1
- Maybe it's time to release version 1.6.3 so as not to have to go to the master branch for it
- 5 years doesn't update?
- [Help] Is it possible to blur only part of an image?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imaging.