Page 3 of 3

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T10:26:41-07:00
by fmw42
glennrp wrote:Yes, the PNG reader now sets image->gamma=1.0 when it reads a gAMA chunk with gamma==1.0.
The bug fix to make gamma=1 for the IM gamma (PNG gamma is already 1) seems to have been lost in the current beta.

see
viewtopic.php?f=3&t=24205#p103692

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T11:09:57-07:00
by Dabrosny
glennrp wrote:Yes, the PNG reader now sets image->gamma=1.0 when it reads a gAMA chunk with gamma==1.0.
Okay, thanks!

Now I'd like to read this image back into IM, which now knows it's linear, and make it a 3-channel linear image (all channels initially equal of course), so that I can do some further linear processing that will change some of these color channels.

So I guess this will accomplish this, right?

Code: Select all

convert rose_luminance.png -colorspace RGB ....some processing... result.png
...or will it instead try to "linearize" the data with an sRGB-->RGB gamma expansion even though the gamma=1 indicates that it was already linear?

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T11:16:42-07:00
by fmw42
convert rose_luminance.png -colorspace RGB ....some processing... result.png
But my images were not properly linear since the IM gamma=0.4545

Also IM does not have single channel grayscale images. So separating the channels into linear grayscale channels will all be the same as the input and 3 channel gray.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T11:34:15-07:00
by Dabrosny
fmw42 wrote:
But my images were not properly linear since the IM gamma=0.4545
But what I'm asking is, once the fix is (back) in place, and I read into IM a 1-channel linear image properly identified as linear by gamma=1, can I explicitly expand it to a 3-channel linear RGB image via -colorspace so that I can do some further linear processing that will change some of these color channels.

Code: Select all

    convert rose_luminance.png -colorspace RGB ....some processing... result.png
...or will this instead try to "linearize" the data with an sRGB-->RGB gamma expansion even though the gamma=1 indicates that it was already linear?

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T14:10:22-07:00
by fmw42
Dabrosny wrote: But what I'm asking is, once the fix is (back) in place, and I read into IM a 1-channel linear image properly identified as linear by gamma=1, can I explicitly expand it to a 3-channel linear RGB image via -colorspace so that I can do some further linear processing that will change some of these color channels.

Code: Select all

    convert rose_luminance.png -colorspace RGB ....some processing... result.png
...or will this instead try to "linearize" the data with an sRGB-->RGB gamma expansion even though the gamma=1 indicates that it was already linear?

I am not sure, but I believe that it should not matter if you do

convert rose_luminance.png -colorspace RGB ....some processing... result.png

or

convert rose_luminance.png -set colorspace RGB ....some processing... result.png

or just leave it out

convert rose_luminance.png ....some processing... result.png

I would think that IM would know it is linear by the gamma=1 which any of the above would still maintain. Once the image is linear, IM should know and -colorspace RGB will not matter nor will -set colorspace RGB.

But I think it would be best to wait until the bug gets fixed so that I can be sure.

The only issue would be if you use some function or image format for the output that may generate non-linear results. That would be the case for example if you composite a linear image with a non-linear image.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-08T21:32:07-07:00
by fmw42
The bug fix is in place. I had checked the verbose info with an older release and that misread the gamma value. So


imbh convert rose: -colorspace sRGB -grayscale rec709luminance rose_luminance.png
imbh convert rose_luminance.png -format "%[gamma]\n" info:
1

imbh convert rose_luminance.png -level 0x90% rose_luminance_level.png
imbh convert rose_luminance_level.png -format "%[gamma]\n" info:
1


imbh convert rose_luminance.png -resize 200% rose_luminance_resize.png
imbh convert rose_luminance_resize.png -format "%[gamma]\n" info:
1

So IM knows that the image is linear and processes it to preserve the gamma=1 linearity

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T06:03:40-07:00
by Dabrosny
fmw42 wrote: I am not sure, but I believe that it should not matter if you do

convert rose_luminance.png -colorspace RGB ....some processing... result.png

or

convert rose_luminance.png -set colorspace RGB ....some processing... result.png

or just leave it out
...<snip/>...
I would think that IM would know it is linear by the gamma=1 which any of the above would still maintain. Once the image is linear, IM should know and -colorspace RGB will not matter nor will -set colorspace RGB.

But I think it would be best to wait until the bug gets fixed so that I can be sure.
Okay, can you try those two with the beta? (even without "...some processing..." for starters).

I hope you're right that the resulting png file is the same ({edit:} the data values themselves as well as gamma and colorspace) -- that would certainly make sense.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T10:02:58-07:00
by fmw42
imbh convert rose: -colorspace sRGB -grayscale rec709luminance rose_luminance.png

Code: Select all

Image: rose_luminance.png
Geometry: 70x46+0+0
Page geometry: 70x46+0+0
Class: PseudoClass
Colorspace: Gray
Type: Grayscale
Depth: 8/1-bit
Alpha: False
Channels: gray
Rendering intent: Undefined
Gamma: 1
Colors: 200
Gray:


see http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=24256
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9087 (0.211407)

imbh convert rose_luminance.png -colorspace RGB rose_luminance_1.png

Code: Select all

Image: rose_luminance_1.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: PseudoClass
  Geometry: 70x46+0+0
  Units: Undefined
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8/1-bit
  Channel depth:
    gray: 8-bit
  Channel statistics:
    Gray:
      min: 0 (0)
      max: 255 (1)
      mean: 19.8901 (0.0780002)
      standard deviation: 52.26 (0.204941)
      kurtosis: 12.7353
      skewness: 3.72498
  Colors: 134
  Histogram:
        56: (  0,  0,  0) #000000 gray(0)
       710: (  1,  1,  1) #010101 gray(1)
       373: (  2,  2,  2) #020202 gray(2)
       223: (  3,  3,  3) #030303 gray(3)
       271: (  4,  4,  4) #040404 gray(4)
       144: (  5,  5,  5) #050505 gray(5)
       161: (  6,  6,  6) #060606 gray(6)
       127: (  7,  7,  7) #070707 gray(7)
       196: (  8,  8,  8) #080808 gray(8)
       128: (  9,  9,  9) #090909 gray(9)
        97: ( 10, 10, 10) #0A0A0A gray(10)
        56: ( 11, 11, 11) #0B0B0B gray(11)
        61: ( 12, 12, 12) #0C0C0C gray(12)
        61: ( 13, 13, 13) #0D0D0D gray(13)
        35: ( 14, 14, 14) #0E0E0E gray(14)
        27: ( 15, 15, 15) #0F0F0F gray(15)
        20: ( 16, 16, 16) #101010 gray(16)
        45: ( 17, 17, 17) #111111 gray(17)
        23: ( 18, 18, 18) #121212 gray(18)
        11: ( 19, 19, 19) #131313 gray(19)
        16: ( 20, 20, 20) #141414 gray(20)
        10: ( 21, 21, 21) #151515 gray(21)
        16: ( 22, 22, 22) #161616 gray(22)
        12: ( 23, 23, 23) #171717 gray(23)
        14: ( 24, 24, 24) #181818 gray(24)
         8: ( 25, 25, 25) #191919 gray(25)
         5: ( 26, 26, 26) #1A1A1A gray(26)
         8: ( 27, 27, 27) #1B1B1B gray(27)
         8: ( 28, 28, 28) #1C1C1C gray(28)
         6: ( 29, 29, 29) #1D1D1D gray(29)
         7: ( 30, 30, 30) #1E1E1E gray(30)
         2: ( 31, 31, 31) #1F1F1F gray(31)
         3: ( 32, 32, 32) #202020 gray(32)
         2: ( 33, 33, 33) #212121 gray(33)
         4: ( 35, 35, 35) #232323 gray(35)
         2: ( 36, 36, 36) #242424 gray(36)
         6: ( 37, 37, 37) #252525 gray(37)
         1: ( 38, 38, 38) #262626 gray(38)
         2: ( 39, 39, 39) #272727 gray(39)
         2: ( 40, 40, 40) #282828 gray(40)
         6: ( 41, 41, 41) #292929 gray(41)
         2: ( 42, 42, 42) #2A2A2A gray(42)
         2: ( 43, 43, 43) #2B2B2B gray(43)
         3: ( 44, 44, 44) #2C2C2C gray(44)
         4: ( 45, 45, 45) #2D2D2D gray(45)
         1: ( 48, 48, 48) #303030 gray(48)
         1: ( 49, 49, 49) #313131 gray(49)
         2: ( 50, 50, 50) #323232 gray(50)
         4: ( 51, 51, 51) #333333 gray(51)
         1: ( 52, 52, 52) #343434 gray(52)
         1: ( 53, 53, 53) #353535 gray(53)
         1: ( 54, 54, 54) #363636 gray(54)
         1: ( 55, 55, 55) #373737 gray(55)
         1: ( 57, 57, 57) #393939 gray(57)
         1: ( 58, 58, 58) #3A3A3A gray(58)
         2: ( 59, 59, 59) #3B3B3B gray(59)
         4: ( 61, 61, 61) #3D3D3D gray(61)
         1: ( 63, 63, 63) #3F3F3F gray(63)
         3: ( 64, 64, 64) #404040 gray(64)
         1: ( 65, 65, 65) #414141 gray(65)
         1: ( 66, 66, 66) #424242 gray(66)
         1: ( 68, 68, 68) #444444 gray(68)
         1: ( 71, 71, 71) #474747 gray(71)
         1: ( 72, 72, 72) #484848 gray(72)
         1: ( 73, 73, 73) #494949 gray(73)
         4: ( 78, 78, 78) #4E4E4E gray(78)
         3: ( 81, 81, 81) #515151 gray(81)
         2: ( 82, 82, 82) #525252 gray(82)
         1: ( 86, 86, 86) #565656 gray(86)
         2: ( 87, 87, 87) #575757 gray(87)
         1: ( 90, 90, 90) #5A5A5A gray(90)
         1: ( 91, 91, 91) #5B5B5B gray(91)
         4: ( 92, 92, 92) #5C5C5C gray(92)
         1: ( 95, 95, 95) #5F5F5F gray(95)
         1: ( 99, 99, 99) #636363 gray(99)
         1: (103,103,103) #676767 gray(103)
         1: (105,105,105) #696969 gray(105)
         2: (107,107,107) #6B6B6B gray(107)
         1: (108,108,108) #6C6C6C gray(108)
         2: (112,112,112) #707070 gray(112)
         1: (114,114,114) #727272 gray(114)
         1: (118,118,118) #767676 gray(118)
         1: (119,119,119) #777777 gray(119)
         1: (124,124,124) #7C7C7C gray(124)
         2: (128,128,128) #808080 gray(128)
         1: (130,130,130) #828282 gray(130)
         2: (133,133,133) #858585 gray(133)
         3: (134,134,134) #868686 gray(134)
         1: (136,136,136) #888888 gray(136)
         1: (138,138,138) #8A8A8A gray(138)
         1: (139,139,139) #8B8B8B gray(139)
         1: (142,142,142) #8E8E8E gray(142)
         3: (147,147,147) #939393 gray(147)
         1: (151,151,151) #979797 gray(151)
         4: (152,152,152) #989898 gray(152)
         3: (154,154,154) #9A9A9A gray(154)
         1: (156,156,156) #9C9C9C gray(156)
         1: (157,157,157) #9D9D9D gray(157)
         2: (159,159,159) #9F9F9F gray(159)
         1: (163,163,163) #A3A3A3 gray(163)
         2: (166,166,166) #A6A6A6 gray(166)
         2: (168,168,168) #A8A8A8 gray(168)
         1: (170,170,170) #AAAAAA gray(170)
         1: (171,171,171) #ABABAB gray(171)
         1: (173,173,173) #ADADAD gray(173)
         1: (179,179,179) #B3B3B3 gray(179)
         1: (181,181,181) #B5B5B5 gray(181)
         2: (183,183,183) #B7B7B7 gray(183)
         1: (186,186,186) #BABABA gray(186)
         1: (192,192,192) #C0C0C0 gray(192)
         1: (194,194,194) #C2C2C2 gray(194)
         1: (196,196,196) #C4C4C4 gray(196)
         2: (200,200,200) #C8C8C8 gray(200)
         1: (202,202,202) #CACACA gray(202)
         2: (204,204,204) #CCCCCC gray(204)
         1: (210,210,210) #D2D2D2 gray(210)
         1: (212,212,212) #D4D4D4 gray(212)
         1: (214,214,214) #D6D6D6 gray(214)
         1: (218,218,218) #DADADA gray(218)
         3: (220,220,220) #DCDCDC gray(220)
         4: (224,224,224) #E0E0E0 gray(224)
         1: (226,226,226) #E2E2E2 gray(226)
         3: (229,229,229) #E5E5E5 gray(229)
         5: (231,231,231) #E7E7E7 gray(231)
         6: (233,233,233) #E9E9E9 gray(233)
         4: (235,235,235) #EBEBEB gray(235)
         1: (237,237,237) #EDEDED gray(237)
         1: (239,239,239) #EFEFEF gray(239)
         4: (244,244,244) #F4F4F4 gray(244)
         9: (246,246,246) #F6F6F6 gray(246)
        29: (248,248,248) #F8F8F8 gray(248)
        15: (250,250,250) #FAFAFA gray(250)
        10: (253,253,253) #FDFDFD gray(253)
        36: (255,255,255) #FFFFFF gray(255)
  Colormap entries: 256
  Colormap:
         0: (  0,  0,  0) #000000 gray(0)
         1: (  1,  1,  1) #010101 gray(1)
         2: (  2,  2,  2) #020202 gray(2)
         3: (  3,  3,  3) #030303 gray(3)
         4: (  4,  4,  4) #040404 gray(4)
         5: (  5,  5,  5) #050505 gray(5)
         6: (  6,  6,  6) #060606 gray(6)
         7: (  7,  7,  7) #070707 gray(7)
         8: (  8,  8,  8) #080808 gray(8)
         9: (  9,  9,  9) #090909 gray(9)
        10: ( 10, 10, 10) #0A0A0A gray(10)
        11: ( 11, 11, 11) #0B0B0B gray(11)
        12: ( 12, 12, 12) #0C0C0C gray(12)
        13: ( 13, 13, 13) #0D0D0D gray(13)
        14: ( 14, 14, 14) #0E0E0E gray(14)
        15: ( 15, 15, 15) #0F0F0F gray(15)
        16: ( 16, 16, 16) #101010 gray(16)
        17: ( 17, 17, 17) #111111 gray(17)
        18: ( 18, 18, 18) #121212 gray(18)
        19: ( 19, 19, 19) #131313 gray(19)
        20: ( 20, 20, 20) #141414 gray(20)
        21: ( 21, 21, 21) #151515 gray(21)
        22: ( 22, 22, 22) #161616 gray(22)
        23: ( 23, 23, 23) #171717 gray(23)
        24: ( 24, 24, 24) #181818 gray(24)
        25: ( 25, 25, 25) #191919 gray(25)
        26: ( 26, 26, 26) #1A1A1A gray(26)
        27: ( 27, 27, 27) #1B1B1B gray(27)
        28: ( 28, 28, 28) #1C1C1C gray(28)
        29: ( 29, 29, 29) #1D1D1D gray(29)
        30: ( 30, 30, 30) #1E1E1E gray(30)
        31: ( 31, 31, 31) #1F1F1F gray(31)
        32: ( 32, 32, 32) #202020 gray(32)
        33: ( 33, 33, 33) #212121 gray(33)
        34: ( 34, 34, 34) #222222 gray(34)
        35: ( 35, 35, 35) #232323 gray(35)
        36: ( 36, 36, 36) #242424 gray(36)
        37: ( 37, 37, 37) #252525 gray(37)
        38: ( 38, 38, 38) #262626 gray(38)
        39: ( 39, 39, 39) #272727 gray(39)
        40: ( 40, 40, 40) #282828 gray(40)
        41: ( 41, 41, 41) #292929 gray(41)
        42: ( 42, 42, 42) #2A2A2A gray(42)
        43: ( 43, 43, 43) #2B2B2B gray(43)
        44: ( 44, 44, 44) #2C2C2C gray(44)
        45: ( 45, 45, 45) #2D2D2D gray(45)
        46: ( 46, 46, 46) #2E2E2E gray(46)
        47: ( 47, 47, 47) #2F2F2F gray(47)
        48: ( 48, 48, 48) #303030 gray(48)
        49: ( 49, 49, 49) #313131 gray(49)
        50: ( 50, 50, 50) #323232 gray(50)
        51: ( 51, 51, 51) #333333 gray(51)
        52: ( 52, 52, 52) #343434 gray(52)
        53: ( 53, 53, 53) #353535 gray(53)
        54: ( 54, 54, 54) #363636 gray(54)
        55: ( 55, 55, 55) #373737 gray(55)
        56: ( 56, 56, 56) #383838 gray(56)
        57: ( 57, 57, 57) #393939 gray(57)
        58: ( 58, 58, 58) #3A3A3A gray(58)
        59: ( 59, 59, 59) #3B3B3B gray(59)
        60: ( 60, 60, 60) #3C3C3C gray(60)
        61: ( 61, 61, 61) #3D3D3D gray(61)
        62: ( 62, 62, 62) #3E3E3E gray(62)
        63: ( 63, 63, 63) #3F3F3F gray(63)
        64: ( 64, 64, 64) #404040 gray(64)
        65: ( 65, 65, 65) #414141 gray(65)
        66: ( 66, 66, 66) #424242 gray(66)
        67: ( 67, 67, 67) #434343 gray(67)
        68: ( 68, 68, 68) #444444 gray(68)
        69: ( 69, 69, 69) #454545 gray(69)
        70: ( 70, 70, 70) #464646 gray(70)
        71: ( 71, 71, 71) #474747 gray(71)
        72: ( 72, 72, 72) #484848 gray(72)
        73: ( 73, 73, 73) #494949 gray(73)
        74: ( 74, 74, 74) #4A4A4A gray(74)
        75: ( 75, 75, 75) #4B4B4B gray(75)
        76: ( 76, 76, 76) #4C4C4C gray(76)
        77: ( 77, 77, 77) #4D4D4D gray(77)
        78: ( 78, 78, 78) #4E4E4E gray(78)
        79: ( 79, 79, 79) #4F4F4F gray(79)
        80: ( 80, 80, 80) #505050 gray(80)
        81: ( 81, 81, 81) #515151 gray(81)
        82: ( 82, 82, 82) #525252 gray(82)
        83: ( 83, 83, 83) #535353 gray(83)
        84: ( 84, 84, 84) #545454 gray(84)
        85: ( 85, 85, 85) #555555 gray(85)
        86: ( 86, 86, 86) #565656 gray(86)
        87: ( 87, 87, 87) #575757 gray(87)
        88: ( 88, 88, 88) #585858 gray(88)
        89: ( 89, 89, 89) #595959 gray(89)
        90: ( 90, 90, 90) #5A5A5A gray(90)
        91: ( 91, 91, 91) #5B5B5B gray(91)
        92: ( 92, 92, 92) #5C5C5C gray(92)
        93: ( 93, 93, 93) #5D5D5D gray(93)
        94: ( 94, 94, 94) #5E5E5E gray(94)
        95: ( 95, 95, 95) #5F5F5F gray(95)
        96: ( 96, 96, 96) #606060 gray(96)
        97: ( 97, 97, 97) #616161 gray(97)
        98: ( 98, 98, 98) #626262 gray(98)
        99: ( 99, 99, 99) #636363 gray(99)
       100: (100,100,100) #646464 gray(100)
       101: (101,101,101) #656565 gray(101)
       102: (102,102,102) #666666 gray(102)
       103: (103,103,103) #676767 gray(103)
       104: (104,104,104) #686868 gray(104)
       105: (105,105,105) #696969 gray(105)
       106: (106,106,106) #6A6A6A gray(106)
       107: (107,107,107) #6B6B6B gray(107)
       108: (108,108,108) #6C6C6C gray(108)
       109: (109,109,109) #6D6D6D gray(109)
       110: (110,110,110) #6E6E6E gray(110)
       111: (111,111,111) #6F6F6F gray(111)
       112: (112,112,112) #707070 gray(112)
       113: (113,113,113) #717171 gray(113)
       114: (114,114,114) #727272 gray(114)
       115: (115,115,115) #737373 gray(115)
       116: (116,116,116) #747474 gray(116)
       117: (117,117,117) #757575 gray(117)
       118: (118,118,118) #767676 gray(118)
       119: (119,119,119) #777777 gray(119)
       120: (120,120,120) #787878 gray(120)
       121: (121,121,121) #797979 gray(121)
       122: (122,122,122) #7A7A7A gray(122)
       123: (123,123,123) #7B7B7B gray(123)
       124: (124,124,124) #7C7C7C gray(124)
       125: (125,125,125) #7D7D7D gray(125)
       126: (126,126,126) #7E7E7E gray(126)
       127: (127,127,127) #7F7F7F gray(127)
       128: (128,128,128) #808080 gray(128)
       129: (129,129,129) #818181 gray(129)
       130: (130,130,130) #828282 gray(130)
       131: (131,131,131) #838383 gray(131)
       132: (132,132,132) #848484 gray(132)
       133: (133,133,133) #858585 gray(133)
       134: (134,134,134) #868686 gray(134)
       135: (135,135,135) #878787 gray(135)
       136: (136,136,136) #888888 gray(136)
       137: (137,137,137) #898989 gray(137)
       138: (138,138,138) #8A8A8A gray(138)
       139: (139,139,139) #8B8B8B gray(139)
       140: (140,140,140) #8C8C8C gray(140)
       141: (141,141,141) #8D8D8D gray(141)
       142: (142,142,142) #8E8E8E gray(142)
       143: (143,143,143) #8F8F8F gray(143)
       144: (144,144,144) #909090 gray(144)
       145: (145,145,145) #919191 gray(145)
       146: (146,146,146) #929292 gray(146)
       147: (147,147,147) #939393 gray(147)
       148: (148,148,148) #949494 gray(148)
       149: (149,149,149) #959595 gray(149)
       150: (150,150,150) #969696 gray(150)
       151: (151,151,151) #979797 gray(151)
       152: (152,152,152) #989898 gray(152)
       153: (153,153,153) #999999 gray(153)
       154: (154,154,154) #9A9A9A gray(154)
       155: (155,155,155) #9B9B9B gray(155)
       156: (156,156,156) #9C9C9C gray(156)
       157: (157,157,157) #9D9D9D gray(157)
       158: (158,158,158) #9E9E9E gray(158)
       159: (159,159,159) #9F9F9F gray(159)
       160: (160,160,160) #A0A0A0 gray(160)
       161: (161,161,161) #A1A1A1 gray(161)
       162: (162,162,162) #A2A2A2 gray(162)
       163: (163,163,163) #A3A3A3 gray(163)
       164: (164,164,164) #A4A4A4 gray(164)
       165: (165,165,165) #A5A5A5 gray(165)
       166: (166,166,166) #A6A6A6 gray(166)
       167: (167,167,167) #A7A7A7 gray(167)
       168: (168,168,168) #A8A8A8 gray(168)
       169: (169,169,169) #A9A9A9 gray(169)
       170: (170,170,170) #AAAAAA gray(170)
       171: (171,171,171) #ABABAB gray(171)
       172: (172,172,172) #ACACAC gray(172)
       173: (173,173,173) #ADADAD gray(173)
       174: (174,174,174) #AEAEAE gray(174)
       175: (175,175,175) #AFAFAF gray(175)
       176: (176,176,176) #B0B0B0 gray(176)
       177: (177,177,177) #B1B1B1 gray(177)
       178: (178,178,178) #B2B2B2 gray(178)
       179: (179,179,179) #B3B3B3 gray(179)
       180: (180,180,180) #B4B4B4 gray(180)
       181: (181,181,181) #B5B5B5 gray(181)
       182: (182,182,182) #B6B6B6 gray(182)
       183: (183,183,183) #B7B7B7 gray(183)
       184: (184,184,184) #B8B8B8 gray(184)
       185: (185,185,185) #B9B9B9 gray(185)
       186: (186,186,186) #BABABA gray(186)
       187: (187,187,187) #BBBBBB gray(187)
       188: (188,188,188) #BCBCBC gray(188)
       189: (189,189,189) #BDBDBD gray(189)
       190: (190,190,190) #BEBEBE gray(190)
       191: (191,191,191) #BFBFBF gray(191)
       192: (192,192,192) #C0C0C0 gray(192)
       193: (193,193,193) #C1C1C1 gray(193)
       194: (194,194,194) #C2C2C2 gray(194)
       195: (195,195,195) #C3C3C3 gray(195)
       196: (196,196,196) #C4C4C4 gray(196)
       197: (197,197,197) #C5C5C5 gray(197)
       198: (198,198,198) #C6C6C6 gray(198)
       199: (199,199,199) #C7C7C7 gray(199)
       200: (200,200,200) #C8C8C8 gray(200)
       201: (201,201,201) #C9C9C9 gray(201)
       202: (202,202,202) #CACACA gray(202)
       203: (203,203,203) #CBCBCB gray(203)
       204: (204,204,204) #CCCCCC gray(204)
       205: (205,205,205) #CDCDCD gray(205)
       206: (206,206,206) #CECECE gray(206)
       207: (207,207,207) #CFCFCF gray(207)
       208: (208,208,208) #D0D0D0 gray(208)
       209: (209,209,209) #D1D1D1 gray(209)
       210: (210,210,210) #D2D2D2 gray(210)
       211: (211,211,211) #D3D3D3 gray(211)
       212: (212,212,212) #D4D4D4 gray(212)
       213: (213,213,213) #D5D5D5 gray(213)
       214: (214,214,214) #D6D6D6 gray(214)
       215: (215,215,215) #D7D7D7 gray(215)
       216: (216,216,216) #D8D8D8 gray(216)
       217: (217,217,217) #D9D9D9 gray(217)
       218: (218,218,218) #DADADA gray(218)
       219: (219,219,219) #DBDBDB gray(219)
       220: (220,220,220) #DCDCDC gray(220)
       221: (221,221,221) #DDDDDD gray(221)
       222: (222,222,222) #DEDEDE gray(222)
       223: (223,223,223) #DFDFDF gray(223)
       224: (224,224,224) #E0E0E0 gray(224)
       225: (225,225,225) #E1E1E1 gray(225)
       226: (226,226,226) #E2E2E2 gray(226)
       227: (227,227,227) #E3E3E3 gray(227)
       228: (228,228,228) #E4E4E4 gray(228)
       229: (229,229,229) #E5E5E5 gray(229)
       230: (230,230,230) #E6E6E6 gray(230)
       231: (231,231,231) #E7E7E7 gray(231)
       232: (232,232,232) #E8E8E8 gray(232)
       233: (233,233,233) #E9E9E9 gray(233)
       234: (234,234,234) #EAEAEA gray(234)
       235: (235,235,235) #EBEBEB gray(235)
       236: (236,236,236) #ECECEC gray(236)
       237: (237,237,237) #EDEDED gray(237)
       238: (238,238,238) #EEEEEE gray(238)
       239: (239,239,239) #EFEFEF gray(239)
       240: (240,240,240) #F0F0F0 gray(240)
       241: (241,241,241) #F1F1F1 gray(241)
       242: (242,242,242) #F2F2F2 gray(242)
       243: (243,243,243) #F3F3F3 gray(243)
       244: (244,244,244) #F4F4F4 gray(244)
       245: (245,245,245) #F5F5F5 gray(245)
       246: (246,246,246) #F6F6F6 gray(246)
       247: (247,247,247) #F7F7F7 gray(247)
       248: (248,248,248) #F8F8F8 gray(248)
       249: (249,249,249) #F9F9F9 gray(249)
       250: (250,250,250) #FAFAFA gray(250)
       251: (251,251,251) #FBFBFB gray(251)
       252: (252,252,252) #FCFCFC gray(252)
       253: (253,253,253) #FDFDFD gray(253)
       254: (254,254,254) #FEFEFE gray(254)
       255: (255,255,255) #FFFFFF gray(255)
  Rendering intent: Undefined
  Gamma: 1
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Rec709Luminance
  Compose: Over
  Page geometry: 70x46+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2013-10-15T09:49:07-07:00
    date:modify: 2013-10-15T09:49:07-07:00
    png:bKGD: chunk was found (see Background color, above)
    png:gAMA: gamma=1 (See Gamma, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 0
    png:IHDR.color_type: 0 (Grayscale)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 70, 46
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    signature: 6c40361a5da66526ad84d455db2743f96ce3d551608fc16d9f7ef75030e83eac
  Artifacts:
    filename: rose_luminance_1.png
    verbose: true
  Tainted: True
  Filesize: 1.88KB
  Number pixels: 3.22K
  Pixels per second: 3.22EB
  User time: 0.010u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.7-1 2013-10-08 Q16 http://www.imagemagick.org


imbh convert rose_luminance.png -set colorspace RGB rose_luminance_2.png

Code: Select all

Image: rose_luminance_2.png
Geometry: 70x46+0+0
Page geometry: 70x46+0+0
Class: PseudoClass
Colorspace: Gray
Type: Grayscale
Depth: 8/1-bit
Alpha: False
Channels: gray
Rendering intent: Undefined
Gamma: 1
Colors: 200
Gray:
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9087 (0.211407)
rose_luminance_2 is the same as rose_luminance. Both are colorspace gray, type grayscale and gamma=1 and the min,max,mean,std are all the same.

rose_luminance_1 is different. It has apparently undergone some change by the -colorspace RGB, which I did not expect, since it still results in gamma=1. The IM developers would have to explain.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T14:18:09-07:00
by Dabrosny
I believe it is treating the grayscale colorspace as being nonlinear similar to sRGB (regardless of the gamma value), so -colorspace RGB does an sRGB-to-RGB gamma expansion, thus the data has been "doubly-expanded".

This should be fixed.

A "Gray" colorspace image with gama=1 should be treated similarly to RGB when it is converted (explicitly or implicitly) to any other colorspace.

I.e. the result should be the same as if we started with an RGB (linear) image having three equal channels (equal to the single grayscale channel).

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T16:11:57-07:00
by fmw42
Yes, I agree. That is why I posted to the Developers forum to be sure before I report as a bug.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T17:46:22-07:00
by Dabrosny
I still think it might be cleaner to have a CieLuminance (linear grayscale) colorspace so that colorspace conversion for grayscale doesn't require a completely different internal identification mechanism (image->gamma) compared to all other colorspaces (where gamma has no effect).

Somebody said we shouldn't have a colorspace that isn't externally recognized, but in fact CIE Y is very well recognized and used. The representation in a PNG file would be exactly the same as it is today for linear RGB (and now the result of -grayscale rec709luminance), i.e. simply setting png chunk gAMA=1. But when reading in the PNG file with gamma=1, the IM colorspace would be set to CIELuminance internally so that colorspace conversion could be performed accurately without relying on image->gamma which is otherwise ignored (just propagated) for purposes of other colorspaces.

But so long as grayscale with gamma=1 can be consistently treated as if it were a linear Luminance colorspace (like linear RGB with R=G=B), that would certainly be much, much better than what we have today.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T18:16:02-07:00
by fmw42
IM has -colorspace rec709luma which is the same as -grayscale rec709luma. I suppose IM could have -colorspace rec709luminance, but that is the same as -grayscale rec709luminance. At least that was the way it was supposed to be apart from a recent bug that changed its behavior and which in principle should be fixed in 6.8.7.1 when it is released.

Re: need explicitly linear and nonlinear GRAY colorspaces

Posted: 2013-10-15T20:47:13-07:00
by Dabrosny
fmw42 wrote:I suppose IM could have -colorspace rec709luminance, but that is the same as -grayscale rec709luminance. At least that was the way it was supposed to be apart from a recent bug that changed its behavior and which in principle should be fixed in 6.8.7.1 when it is released.
I'm not just looking for a method to perform the conversion, but a colorspace that would tag the image internally (and at least in miff) as to what kind of grayscale data your image represents. If -colorspace rec709luminance would actually set a colorspace called rec709luminance (not just "gray"), that would be a step in the right direction.

(Aside from the name being strange -- the difference between rec709luminance and rec601luminance is just the coefficients you use to get from linear 709 primaries or 601 primaries to CIE Y. If calculated correctly from where ever you start, you should end up with the same linear CIE Luminance Y (as in CIE 1931 XYZ) in both cases as the final colorspace, so I'm not sure why they should be tagged as different colorspaces at that point)