Yes, certainly this is round to nearest for the luminance computation, and that 
is a good thing.

 

As far as the equation itself, this is a color science topic with many types of 
answers—engineering answers that cite various specifications, scientific 
answers that study human perception, and others. The logic of it is that the 
typical human eye is much more sensitive to green light, then reds, and then 
blue least of all. Basically this is just 6x, 3x and 1x the sensitivity.

 

However, the color responses in the eye are spectral—across a range of 
frequencies—not centered at just the one particular red, green, and blue 
wavelength of a particular display device, which is why there are so many 
engineering answers—one overall best fit per color triad for the original NTSC 
phosphor colors, for CRT computer monitors, etc.

 

That said, NONE OF THEM ARE VERY GOOD for common purposes.

 

Here is a survey:

http://cseweb.ucsd.edu/~ckanan/publications/Kanan_Cottrell_PloS_ONE_2012.pdf

 

And interesting approaches…

http://www.cs.northwestern.edu/~ago820/color2gray/color2gray.pdf

https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-649.pdf

 

What I tend to use is the perceptually pleasing, unofficial, non-standard, 
clever solution by Darel Rex Finley…

y  :=  math.Sqrt(0 .299*r*r + 0.587*g*g + 0.114*b*b)

 

You can see how well it works by looking at the child and building images on 
his web page. See how long it takes you to see what’s happening in the bottom 
row…  

 

Michael

 

 

From: <golang-nuts@googlegroups.com> on behalf of Patrick Smith 
<pat42sm...@gmail.com>
Date: Wednesday, September 28, 2016 at 4:51 PM
To: Rodolfo Carvalho <rhcarva...@gmail.com>
Cc: golang-nuts <golang-nuts@googlegroups.com>
Subject: Re: [go-nuts] image: algorithm to convert to grayscale

 

Looks like it's just rounding to the nearest integer.

 

On Wed, Sep 28, 2016 at 3:19 PM, Rodolfo Carvalho <rhcarva...@gmail.com> wrote:

Hello,

 

I'm not an image processing expert, but was trying to write a small program to 
convert images to grayscale, just for the fun of it [1].

 

First I managed to get something working with image/draw, then I discovered 
about github.com/disintegration/gift through an old post here.

 

I realized the output images had a different luminance, what led me to dig a 
bit deeper to see how the implementations differed.

 

 

image/color [2]:

 

    y := (299*r + 587*g + 114*b + 500) / 1000

 

 

gift [3]:

 

    y := 0.299*px.R + 0.587*px.G + 0.114*px.B

 

 

The initially funny numbers, weights, match those described in Wikipedia [4].

I went ahead and compared to what Matlab [5] and Octave [6] do and found a 
similar formula.

 

 

I did not understand why image/color adds an extra 0.5 (500/1000) to y.

Could anybody give me a clue?

 

 

 

 

[1] https://gist.github.com/rhcarvalho/5e97f310701528f5a0610415e317b992

[2] image/color: 
https://github.com/golang/go/blob/master/src/image/color/color.go#L249

[3] GIFT: https://github.com/disintegration/gift/blob/master/colors.go#L252

[4] https://en.wikipedia.org/wiki/Grayscale#Luma_coding_in_video_systems

[5] Matlab: 
https://www.mathworks.com/help/matlab/ref/rgb2gray.html#expand_body_buiz8mj-9

[6] Octave: 
https://sourceforge.net/p/octave/image/ci/default/tree/inst/rgb2gray.m#l43

 

 

Thanks,


Rodolfo Carvalho

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to