How to set a particular colorspace for the output in imagemagick

Viewed 14

How to control the colorspace in the output file using convert. I tried

convert __targets/test_pattern_raw.png -set colorspace RGB -depth 16 -colorspace RGB PNG64:__targets/test_pattern.png

First I set colorspace to RGB, because the input file has falsely been tagged as sRGB. Now I want to save the image in linear space as well. However, the command above gives a non-linear image:

identify __targets/test_pattern.png

__targets/test_pattern.png PNG 1600x1000 1600x1000+0+0 16-bit sRGB 78794B 0.000u 0:00.000

When saving in EXR format, it becomes linear, because EXR does not support anything else, but I need it to work for png, and also for rgba (which is a dump without any headers).

2 Answers

It should work by simply using -colorspace RGB in Imagemagick.

Input:

enter image description here

 Filename: lena.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 256x256+0+0
  Units: Undefined
  Colorspace: sRGB

convert lena.png -colorspace RGB x.png

 Filename: x.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 256x256+0+0
  Units: Undefined
  Colorspace: RGB

The problem was a bug in ImageMagick. After the fix

convert -set colorspace RGB __targets/test_pattern_raw.png -depth 16 PNG64:__targets/test_pattern.png

Works as intended.

Related