Generating and then applying color transformation matrices

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
dada78641
Posts: 3
Joined: 2014-05-28T19:55:23-07:00
Authentication code: 6789

Generating and then applying color transformation matrices

Post by dada78641 »

Hi there. I've got a question, I'm not sure if Imagemagick is right for what I'm trying to do. Here's a simplified explanation of my problem:

Say I've got Photo A. And I've also got Photo B, which is the same as Photo A except it's had its colors/histogram modified in some way.

Now let's say I've also got Photo C, which is the same as Photo A except it's bigger has much nicer quality.

The question: how do I create Photo D, which is Photo C except with the same color transformations applied to it as Photo B?


In fact, I've got about 900 photos like this, and I want to run a script to examine them and then apply these modifications to all of them. (Looping through all of them is no problem, so if you could help me get it working with one example that'd be fine.) I was originally writing some programming code in PHP to create an image matrix based on examining the differences between Photo A and Photo B, but it's kind of daunting and I'd prefer to use Imagemagick if it has these things already built in.

If you have any leads or ideas, that'd be great! :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generating and then applying color transformation matric

Post by fmw42 »

What version of IM and what platform? Post one set of images A,B,C to dropbox.com (public folder) and put links to them here. Then we get a better idea of what you want to do and can experiment with your images.

If you want to capture the color transformation of an image and know how it was processed, you can use -hald to create the color processing and -hald-clut to apply it. If you do not know how to reproduce the color transformation, then histogram matching may work. If on unix (Linux, Mac OSX or Windows with Cygwin), you can try my script histmatch at the link below. Other approaches are possible if it is just contrast and brightness. But it would be best to see your example.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Generating and then applying color transformation matric

Post by snibgo »

I suspect the most effective way and general method for unknown processing is to automatically create a hald that gives the transformation from A to B. This should be fairly easy for the colours that are in A, and all other colours would be interpolated, perhaps using "-sparse-colour". I haven't done this, and it wouldn't be trivial as a hald is really a 3-D image, and IM only works in 2-D.

Meanwhile, simple solutions are possible when the transformations are simple, eg curve manipulations for R, G, B or tone, saturation, colour-shift, etc. As Fred says, put up samples.
snibgo's IM pages: im.snibgo.com
dada78641
Posts: 3
Joined: 2014-05-28T19:55:23-07:00
Authentication code: 6789

Re: Generating and then applying color transformation matric

Post by dada78641 »

Hi there. Thanks for your replies, so quickly too!

Here's an example Photo A.

Here's an example Photo B (the difference is subtle).

My photo C is also an example, as the real ones are much larger. But this is what I'm testing with for now. All files can be found here.
What version of IM and what platform?
At the moment I'm using 6.8.8.10-1 (x86_64).
If you want to capture the color transformation of an image and know how it was processed, you can use -hald to create the color processing and -hald-clut to apply it. If you do not know how to reproduce the color transformation, then histogram matching may work. If on unix (Linux, Mac OSX or Windows with Cygwin), you can try my script histmatch at the link below. Other approaches are possible if it is just contrast and brightness. But it would be best to see your example.
I'm gonna give your script a try as soon as I can. I didn't do the color transformations myself so I don't know exactly what was done to the images, but I believe it's Photoshop's "Channel Mixer" plus maybe channel rotation (hue shift), plus changing the image's levels. So basically I doubt there's anything going on that can't be done by modifying histograms for each channel. Since each image has custom color modifications, I have to do this programmatically and based on an examination of each individual image rather than one common formula.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generating and then applying color transformation matric

Post by fmw42 »

try this. it seems to work pretty well

Code: Select all

histmatch -c rgb img_b.png img_c.png img_c2b_rgb.png
dada78641
Posts: 3
Joined: 2014-05-28T19:55:23-07:00
Authentication code: 6789

Re: Generating and then applying color transformation matric

Post by dada78641 »

Thanks so much! Sorry for replying so late, but it's been super busy so I haven't been able to return to this until now. But your script works perfectly for my purposes. Didn't expect it to be this easy... :D
Post Reply