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.