IM separate combine syntax

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

IM separate combine syntax

Post by geoland »

I want to check the syntax is correct to perform the following operations - the examples adapted from the colour space pages.

The workflow is linear to sRGB with no exposure, brightness, gamma, saturation adjustments.

separate RGB.tiff image into R G B channels. Process each channel and combine as sRGB.tiff

Code: Select all

convert RGB.tiff -colorspace RGB -separate %d.miff

convert 0.miff 1.miff 2.miff -set colorspace RGB -combine -set colorspace sRGB sRGB.tiff
separate RGB.tiff image into L A B channels. Process each channel and combine as sRGB.tiff

Code: Select all

convert RGB.tiff -colorspace LAB -separate %d.miff

convert 0.miff 1.miff 2.miff -set colorspace LAB -combine -colorspace sRGB sRGB.tiff
This command does not use -set -colorspace sRGB as in the previous example when combining RGB channels and setting colorspace to sRGB.

separate RGB.tiff into R G B channels then convert RGB.tiff to LAB and separate L

Code: Select all

convert RGB.tiff -separate %d.tiff
	
convert RGB.tiff -colorspace LAB -channel R -separate L.tiff
combine L R G B -

Code: Select all

convert L.tiff 0.tiff 1.tiff 2.tiff -colorspace RGB -combine -set colorspace sRGB LsRGB.tiff
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM separate combine syntax

Post by fmw42 »

Your input Tiff is most likely already sRGB. If you are on a current version of IM, then -set colorspace RGB will make that into linear RGB channels. So your first set of commands go from sRGB to linear RGB and back to sRGB.

The same for the your second process. You go from sRGB to LAB and back to sRGB.

In your third set of commands your first convert is never used (until your fourth set). Your second convert extracts the L channel of LAB.

Your fourth command will not work as expected, since it has 4 input channels and your -combine will only make a 3 channel tiff. The fourth channel appears to be ignored. It does not become an alpha channel. I am not sure why IM 6 does not complain.

Please always provide your IM version and platform!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM separate combine syntax

Post by snibgo »

As Fred says about "RGB". You probably mean "sRGB".

What version of ImageMagick? If the input file is grayscale or has an alpha channel (even fully opaque), v6 and v6 have different default channels for "-separate". If you want to separate into 3 channels, for v7 you should ensure you have at least three channels, and that the RGB channels are selected. Doing this also for v6 won't cause problems.

Your last command has four colour channels. I don't think v6 or v7 can do that (yet).
snibgo's IM pages: im.snibgo.com
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: IM separate combine syntax

Post by geoland »

The tiff files are converted RAW using dcraw -4 option with a view to retaining the raw data as much as possible. This works well when converting to grayscale, but not sure of the advantage when working in color, in which case the following syntax
IM v6.8.x.x?

Code: Select all

convert input.tiff -separate %d.miff

convert 0.miff 1.miff 2.miff -set colorspace sRGB -combine output.tiff
I see no way to avoid the LAB linear conversion unless this will do it?

Code: Select all

convert input.tiff LAB -separate %d.miff

convert 0.miff 1.miff 2.miff -set colorspace sRGB -combine output.tiff
Adding L to sRGB

Code: Select all

convert input.tiff LAB -channel R -separate L.tiff

convert input.tiff L.tiff -set colorspace sRGB -combine output.tiff
Last edited by geoland on 2016-06-09T00:02:24-07:00, edited 1 time in total.
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM separate combine syntax

Post by fmw42 »

None of your last two sets of commands contains -combine, so in the last sets, you will get a 4 layer image, not 3 channels. Each layer should be grayscale. In the previous set of commands, you will end up with 3 layers, not channels.

Your first set is just going from sRGB to sRGB. This does nothing. The output will be the same as the input, unless you plan to add other processing imbetween.

Not sure what you are trying to achieve!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM separate combine syntax

Post by snibgo »

Despite the documentation, "-4" isn't enough to get linear from dcraw. Add "-v" to see what it does. Also give "-o 0" (letter o, digit zero).

Even then, IM will think the image is non-linear sRGB. When you want to convert it to sRGB, you need to tell IM it is currently RGB:

Code: Select all

convert in.tiff -set colorspace RGB -colorspace sRGB out.tiff
I don't know what you want "-separate" and "-combine" to achieve.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM separate combine syntax

Post by fmw42 »

snibgo, does the dcraw command output linear or non-linear tiff data?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM separate combine syntax

Post by snibgo »

Either, or anywhere inbetween. sRGB is defined by a gamma and a slope, and we can tell dcraw to use any value for each of gamma and slope. By default, it then assigns an sRGB profile. Or does it convert to that profile? I'm not entirely sure. Anyhow, to make a linear output, we use "-6 -o 0 -W -g 1 1" or similar.
snibgo's IM pages: im.snibgo.com
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: IM separate combine syntax

Post by geoland »

Thanks.
Typo corrected in post.

I have left out the in between processing. So between separate and -combine the files are subtracted and or divided as required.

Is there any advantage then in a linear dcraw output if the files will only be subtracted and divided between -separate and -combine?
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM separate combine syntax

Post by snibgo »

There are many ways of organising a workflow, depending on whether you need to automatically batch-process a large number of images, or manually adjust each sub-process of each photo, and how much you are prepared to switch colorspaces back and forth between sRGB and RGB, and so on.

Personally, I do initial automatic gamma and level adjustment in RGB, convert to sRGB and stick with that for most other processing.
snibgo's IM pages: im.snibgo.com
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: IM separate combine syntax

Post by geoland »

I am attempting to stay as linear as possible for the workflow, as follows, then convert to sRGB. I don't want any adjustments to the images - realistically as little as possible. Post processing external to the calibration script.

I checked the dcraw man page.

These are the options used in my script

Code: Select all

dcraw -4 -o 0 q 1 -t 0 -H 1 -T *.CR2
-4 Linear 16-bit, same as -6 -W -g 1 1.

q 1 VNG deBayer

-t 0 no flip

-H 1 no highlight clipping

-T output tiff

I realise that it is not strictly linear from a RAW file.

I am attempting to process the images as near linear as possible and then recombine as sRGB. Though I'm not really sure whether there is an advantage converting to 'linear', in this case. sRGB all the way would simplify things a little - how is LAB handled in that case?

There are 4 image sets B D F L. Each color channel is processed as follows after '-separate', using R channel as an example;

Code: Select all

R.miff=(L.miff - D.miff)/(F.miff - B.miff) - same for G and B channels
then

Code: Select all

convert R.miff G.miff B.miff -set colorspace sRGB -combine output.tiff
This line is confusing me at the moment

Code: Select all

convert R.miff G.miff B.miff -set colorspace RGB -combine -set colorspce sRGB output.tiff
I understand from the documentation lets IM know the input files are RGB and then sets colorspace to sRGB - It would seem to me that if -set colorspace RGB is used in the -separate command before processing, there should be no need to reiterate in the -combine command after processing???

If no colorspace is defined is sRGB the default or RGB?
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM separate combine syntax

Post by snibgo »

You can convert from any colorspace directly to any other colorspace, for example from either RGB to sRGB to Lab.
geoland wrote:convert R.miff G.miff B.miff -set colorspace RGB -combine -set colorspce sRGB output.tiff
I expect you could remove the first "-set colorspace RGB" with no difference at all to the result.

If you "-combine" from grayscale images with no "-set colorspace", the output will be sRGB. That is, the exact pixels values from the first image will go into the Red channel, the second into the Green channel and the third into the Blue channel, and the resulting image will be marked as sRGB.
snibgo's IM pages: im.snibgo.com
Post Reply