Page 1 of 1

Difference between -colorspace and -set colorspace with PNG

Posted: 2013-10-15T10:14:35-07:00
by fmw42
I am a bit puzzled about the difference between the use of -colorspace RGB and -set colorspace RGB on a linear (gamma=1) grayscale image. Using -set colorspace RGB does not change the data nor gamma=1, but -colorspace seems to change the data, but leaves gamma=1.

Can someone explain why the difference? I would have expected -colorspace RGB to make no changes since the image was already linear grayscale? Is the current result correct? If so, why the change? At most I would have thought it would only change the colorspace to RGB and not change the data.


# create linear (gamma=1) grayscale image
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:
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9087 (0.211407)


# apply -set colorspace (is exactly the same as above as expected)
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)

# apply -colorspace RGB (the min,max,mean,std and number of colors has changed)
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:
...
  Colormap entries: 256
  Colormap:
...
  Rendering intent: Undefined
  Gamma: 1
...
  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

Re: Difference between -colorspace and -set colorspace with

Posted: 2013-10-15T13:59:32-07:00
by snibgo
The problem here seems to be that "convert" reads a PNG file and assumes it is sRGB, even though the gamma (as recorded in the file) is 1.

Interestingly, "identify" does get it right:

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert xc:gray(50%) rf1.png

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\identify rf1.png
rf1.png PNG 1x1 1x1+0+0 16-bit sRGB 240B 0.000u 0:00.000

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert xc:gray(50%) -set colorspace RGB rf2.png

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\identify rf2.png
rf2.png PNG 1x1 1x1+0+0 16-bit RGB 196B 0.000u 0:00.000


EDIT to add that "identify" is also correct when reading a grayscale rec709luminance file:

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert xc:gray(50%) -grayscale rec709luminance rf3.png

D:\web\im>c:\im\ImageMagick-6.8.7-Q16\identify rf3.png
rf3.png PNG 1x1 1x1+0+0 16-bit RGB 196B 0.000u 0:00.000

Re: Difference between -colorspace and -set colorspace with

Posted: 2013-10-15T16:03:13-07:00
by fmw42
snibgo, you need to test this with the 6.8.7.1 beta since there were some fixes made that relate to this.

In IM 6.8.7.1 beta your command is not making a linear gray image. So there is another bug.


imbh convert xc:"gray(50%)" gray_linear.png

Code: Select all

Image: gray_linear.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 1x1+0+0
  Units: Undefined
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 16/1-bit
  Channel depth:
    gray: 16-bit
  Channel statistics:
    Gray:
      min: 32767 (0.499992)
      max: 32767 (0.499992)
      mean: 32767 (0.499992)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Colors: 1
  Histogram:
         1: (32767,32767,32767) #7FFF7FFF7FFF gray(49.999237048905165182%)
  Rendering intent: Undefined
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1x1+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2013-10-15T16:05:16-07:00
    date:modify: 2013-10-15T16:05:16-07:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45455 (See Gamma, above)
    png:IHDR.bit-depth-orig: 16
    png:IHDR.bit_depth: 16
    png:IHDR.color-type-orig: 0
    png:IHDR.color_type: 0 (Grayscale)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 1, 1
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    signature: a062f1b579409527e2ff138cd134ef5f124ff5de934c02151398d5742338cfb9
  Artifacts:
    filename: gray_linear.png
    verbose: true
  Tainted: True
  Filesize: 240B
  Number pixels: 1
  Pixels per second: 1000TB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.7-1 2013-10-08 Q16 http://www.imagemagick.org

Re: Difference between -colorspace and -set colorspace with

Posted: 2013-10-15T17:07:56-07:00
by snibgo
fmw42 wrote:imbh convert xc:"gray(50%)" gray_linear.png
I wouldn't expect that result to be linear. I would expect it to be sRGB, gamma 0.454545, with pixel values at 50%. And that's the result I get with both v6.8.7-0 and v6.8.7-1beta.

The weirdness occurs with the result of:

Code: Select all

convert xc:gray(50%) -grayscale rec709luminance rf3.png
"identify rf3.png" correctly says this is RGB (not sRGB). However, "identify -verbose rf3.png" says colorspace=Gray (which is treated the same as sRGB). 6.8.6-1beta correctly says the gamma is 1. Convert processes it as if the colorspace is sRGB.

I think that identify and convert should treat rf3.png as being RGB.

Re: Difference between -colorspace and -set colorspace with

Posted: 2013-10-15T17:28:59-07:00
by fmw42
see change log


2012-07-08 6.7.8-3 Cristy <quetzlzacatenango@image...>
Return linear grayscale for gradient:white-black.
gradient:white-black is sRGB whereas gradient:'icc-color(rgb,255,255,255)- icc-color(rgb,0,0,0)' is linear RGB whereas gradient:'gray(255)-gray(0)' is linear grayscale.

Re: Difference between -colorspace and -set colorspace with

Posted: 2013-10-15T18:08:56-07:00
by snibgo
On the gray(50%) issue, see my reply to your bug report viewtopic.php?f=3&t=24259