Applying channel multipliers to RGB channels

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

Applying channel multipliers to RGB channels

Post by geoland »

Hi.

Given the channel multiplier values

Code: Select all

      	R sRGB 	G sRGB 	B sRGB	
R raw	1.91	  -1  	0.09
G raw	-0.19	1.65   -0.46
B raw	0.07   	-0.7	1.64
Color matrix as defined in ISO standard 17321
Is there an IM method for applying multipliers to each channel, as follows?

Code: Select all

R = 1.91 * r   -  1 * g  + 0.09 * b
G =  -0.19* r  + 1.65 * g -  0.46 * b
B = 0.07 * r   -  0.7 * g  + 1.64 * b
R G B would then be combined to create an sRGB image.

There is likely no need to separate the channels - this just illustrates the process.
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: Applying channel multipliers to RGB channels

Post by snibgo »

snibgo's IM pages: im.snibgo.com
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: Applying channel multipliers to RGB channels

Post by geoland »

Thanks. This is what I came up with. Works quite well.

Code: Select all

#! /bin/bash

# Apply DSLR channel multipliers, obtained from 

# https://www.dxomark.com/Cameras/Canon/EOS-450D---Measurements

# ImageMagick -color-matrix 

# To run script from command line in Windows OS replace \ with ^ AFAIK...

# Canon 450D 
#	R sRGB	G sRGB	B sRGB	
# R raw	1.91	-1	0.09
# G raw	-0.19	1.65	-0.46
# B raw	0.07	-0.7	1.64

# Color matrix as defined in ISO standard 17321

# Play around with multipliers for Ha modded cameras

convert in.jpg -depth 16 -color-matrix \
	"1.81 -0.8 0.07 0.0, 0.0, 0.0 \
    	-0.16 1.51 -0.4 0.0, 0.0, 0.0 \
    	0.05 -0.5 1.5 0.0, 0.0, 0.0 \
    	0.0 0.0 0.0 0.0, 0.0, 0.0 \
    	0.0 0.0 0.0 0.0, 0.0, 0.0 \
    	0.0 0.0 0.0 0.0, 0.0, 0.0" -alpha off out.jpg

animate -delay 100 -loop 0 -resize 800x600 -page 800x600 in.jpg out.jpg

exit
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: Applying channel multipliers to RGB channels

Post by fmw42 »

If you only need the RGB channels, you can reduce the matrix to the top left 3x3 values

Code: Select all

convert in.jpg -depth 16 -color-matrix \
	"1.81 -0.8 0.07 \
    	-0.16 1.51 -0.4 \
    	 0.05 -0.5 1.5" -alpha off out.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Applying channel multipliers to RGB channels

Post by snibgo »

The data behind the matrix may assume pixels values are linear, not sRGB (or AdobeRGB or whatever). If so, put "-colorspace RGB" before the matrix and "-colorspace sRGB" after it.
snibgo's IM pages: im.snibgo.com
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: Applying channel multipliers to RGB channels

Post by geoland »

snibgo wrote: 2017-07-22T19:50:23-07:00 The data behind the matrix may assume pixels values are linear, not sRGB (or AdobeRGB or whatever). If so, put "-colorspace RGB" before the matrix and "-colorspace sRGB" after it.
That fits in with the workflow. Plan is to apply this to linear images.

The 4th and 5th column seem redundant and likely unnecessary in that case.
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
Post Reply