Page 1 of 1
Extracting HSL shift from base image to new
Posted: 2013-09-04T08:23:22-07:00
by patdavid
Hi all,
I'll get right to it...
I've got a base image that I apply some color modifications to (namely, HSL shifts, and then RGB curve shifts).
I'd like to find a way to extract the shift values between the base/identity image, and the color modified version.
For instance, I've got a HALD CLUT identity image. I also have a the same image, but with HSL modifications applied. Is there any way to retrieve the numerical shifts easily for a given base value?
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T09:02:54-07:00
by fmw42
Not that I know by any kind of comparison of the HALD images. You would have had to record them in the filename or comments of the new Hald image.
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T09:32:12-07:00
by patdavid
So, if I had an image that I know to be some pure red color ( rgb(255,0,0) ), and a second image identical in all ways, except there has been an HSL shift of some sort, there's not a way for me to determine what that shift was? (Sorry if I'm dense, just trying to understand a path forward).
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T10:06:38-07:00
by snibgo
I've tried to solve a similar question: given corresponding colour patches in two images, what transformation from one makes the other?
Sorry, I can't find my code. From memory, I needed to iterate to get the "-modulate" parameters, even when the only initial transformation was "-modulate". But it did give a complete solution, possibly including curves.
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T10:18:34-07:00
by patdavid
snibgo wrote:I've tried to solve a similar question: given corresponding colour patches in two images, what transformation from one makes the other?
Sorry, I can't find my code. From memory, I needed to iterate to get the "-modulate" parameters, even when the only initial transformation was "-modulate". But it did give a complete solution, possibly including curves.
Now we're talking!
modulate is where I should be looking then?
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T10:30:40-07:00
by snibgo
Yes, it is one way, and I found it successful. (I wish I could find my code!!)
From very vague memory:
1. Find the HSL difference between images A and B. This gives approximate parameters for "-modulate", to transform A to B.
2. "convert A -modulate {parameters} A2"
3. Find the HSL difference between images A2 and B. Use this to tweak the parameters.
4. Repeat from 2 until the difference is almost zero. It only takes 2 or 3 iterations.
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T10:52:50-07:00
by patdavid
snibgo wrote:Yes, it is one way, and I found it successful. (I wish I could find my code!!)
From very vague memory:
1. Find the HSL difference between images A and B. This gives approximate parameters for "-modulate", to transform A to B.
This is the black magic part for me. Is there a method for accomplishing this? (Reading through the docs doesn't immediately bring anything to mind...)
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T13:15:30-07:00
by snibgo
Yes, it's quite simple, but I don't have the time to work out the details.
The basic idea is to convert the two colours to HSL. Dump the pixel values as text. Compare the values. The lightness will have increased (or decreased) by a certain percentage. The is the first parameter for the "-modulate" operation.
Likewise, saturation.
Hue is a bit more awkward. We need to subtract the txt hue values and fiddle around. See
http://www.imagemagick.org/script/comma ... p#modulate
Re: Extracting HSL shift from base image to new
Posted: 2013-09-04T18:57:44-07:00
by snibgo
Here we go. With luck, I won't lose this one. A Windows script (that I call whatMod.bat).
It takes two images as parameters. These should have one pixel each. (If they have more, it will operate on the last pixel of each).
It returns the approximate "-modulate" parameters that will convert the first image to the second.
I say "approximate", but it seems to be exact for 16-bit images.
For non-Windows users, I'll explain the script:
1. Convert first image to HSL, setting HA, SA and LA to the channels (expressed as percentages).
2. Convert second image to HSL, setting HB, SB and LB to the channels (expressed as percentages).
3. dL = 100 * LB / LA
4. dS = 100 * SB / SA
5. dH = 100 + 2 * (HB - HA)
Code: Select all
rem Given %1 and %2, images with one pixel each,
rem returns dL, dS, dH,
rem the approximate "-modulate" parameters to convert %1 to %2.
for /F "usebackq tokens=7-9 delims=:,hsl()%% " %%L in (`%I%convert ^
%1 ^
-colorspace HSL ^
txt:`) DO (
set HA=%%L
set SA=%%M
set LA=%%N
)
for /F "usebackq tokens=7-9 delims=:,hsl()%% " %%L in (`%I%convert ^
%2 ^
-colorspace HSL ^
txt:`) DO (
set HB=%%L
set SB=%%M
set LB=%%N
)
for /F "usebackq" %%L in (`%I%identify -ping -format "%%[fx:100*%LB%/%LA%]" xc:`) DO set dL=%%L
for /F "usebackq" %%L in (`%I%identify -ping -format "%%[fx:100*%SB%/%SA%]" xc:`) DO set dS=%%L
for /F "usebackq" %%L in (`%I%identify -ping -format "%%[fx:100+2*(%HB%-%HA%)]" xc:`) DO set dH=%%L
echo %dL% %dS% %dH%
The source images might be single pixels cropped from larger images, of course.
Re: Extracting HSL shift from base image to new
Posted: 2013-09-05T08:34:26-07:00
by patdavid
snibgo wrote:Here we go. With luck, I won't lose this one. A Windows script (that I call whatMod.bat).
I wanted to drop in and thank you very much for taking the time to do this!
The script crashes my IM for some reason, but I've gotten exactly what I need to do it manually out of your script, so thank you.
Re: Extracting HSL shift from base image to new
Posted: 2013-09-05T08:59:04-07:00
by snibgo
Good stuff. Note that it gives a bad result if the first image is gray (ie LA==0 or SA==0). You should check for this.