Page 1 of 1

.jpg to .rgb, -colorspace vs. -set colorspace

Posted: 2017-04-01T11:56:33-07:00
by vmartin
I have an sRGB-encoded JPEG image.
I would like to convert it to "RGB" format, i.e., pure image data in R-G-B triplets with no headers, etc.
In addition, I would like to convert it in two ways, one so that the R-G-B output is sRGB-encoded, and
one so that the R-G-B output is linear.

To convert to sRGB-encoded R-G-B, I did

Code: Select all

convert input.jpg output.rgb
And to convert to linear R-G-B, I did

Code: Select all

convert input.jpg -colorspace RGB output.rgb
but that produced output identical to the first case.

When I do

Code: Select all

convert input.jpg -set colorspace RGB -colorspace RGB output.rgb
then the output is different, but I'm unclear why or whether it did what I intended.

Looking at viewtopic.php?t=17207, it says
-colorspace : change the way actual pixel are represented
-set colorspace : tell image the data is represented this way, but does not touch the data
which matches my reading of the docs, but since .rgb format has no header I don't understand what
-set colorspace is "setting" in my case, or why it makes a difference.

Can someone please set me on the right path.
MV

Re: .jpg to .rgb, -colorspace vs. -set colorspace

Posted: 2017-04-01T12:05:10-07:00
by snibgo
First things first: What version IM are you using?

Re: .jpg to .rgb, -colorspace vs. -set colorspace

Posted: 2017-04-01T14:07:36-07:00
by vmartin
Sorry, meant to include in the question

Code: Select all

Version: ImageMagick 7.0.5-4 Q16 x86_64 2017-04-01 http://www.imagemagick.org
MV

Re: .jpg to .rgb, -colorspace vs. -set colorspace

Posted: 2017-04-01T14:26:42-07:00
by fmw42
There is no header with .rgb (it is just raw data). So if you want to change the data from sRGB (gamma 0.4545) to linear RGB (gamma 0.1), I think you can try doing that by using -gamma to do the conversion. I am not 100% sure about that. I would have thought -colorspace RGB might do the same. So try assuming your input jpg is sRGB.

convert input.jpg -gamma 1 output.rgb

If that fails then perhaps raw rgb is always linear?

Re: .jpg to .rgb, -colorspace vs. -set colorspace

Posted: 2017-04-01T14:31:14-07:00
by snibgo
Raw RGB is always assumed to be sRGB, I think.

Using "-gamma" or "-evaluate pow" will approximately change between RGB and sRGB. "-colorspace" is more accurate.


"-colorspace XXX" if image isn't already in colorspace XXX (according to the metadata), this changes pixel values and metadata.

"-set colorspace XXX" if image isn't already in colorspace XXX (according to the metadata), this changes metadata only.

A third fact you need to know: not all filetypes support all colorspaces. When the image is written to a file that doesn't support the colorspace, it is automatically converted a colorspace that is supported, as if "-colorspace XXX" was used.

I think the .RGB format supports only the sRGB colorspace.

If your image is in RGB colorspace and you want to write those values, unchanged, to a .RGB file, first use "-set colorspace sRGB". Then IM won't automatically convert it.