Is this possible? (colour + detail = colour&detail)

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?".
Locked
LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

Is this possible? (colour + detail = colour&detail)

Post by LDAsh »

I basically want to influence the hue of every pixel in one image by using another image as source information. Black and white wouldn't (can't) change, but the colourisation of all grey pixels would match that of another input to give a desired output, like in this example:-
Image

The only way I can imagine myself doing this is to process the middle greyscale image to isolate the highest and lowest ranges, making 2 alphas, and then brightening/darkening the first coloured image so it resembles the final outcome on the right, which might just be another way of saying what I want to do, but I don't think it would be accurate for all use-cases since I won't know how much to adjust each image. It's the best idea I can achieve with my current skills.

So, any advice is greatly appreciated.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is this possible? (colour + detail = colour&detail)

Post by snibgo »

Do you want to take an image then break it down into two images? Or do you have two input images and need to combine them?

Your middle image seems to be the lightness of the right-hand image. I'm not sure what you have or want in the left-hand image.

Colour images usually have three channels. We can separate them to put two channels in one image and the third channel in a separate image. For example, in L*a*b* space, we can record the a* and b* in one image, and L* in another.
snibgo's IM pages: im.snibgo.com

LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

Re: Is this possible? (colour + detail = colour&detail)

Post by LDAsh »

I'd like to take the colour information from every pixel of the first image to colourise/hue-shift every pixel in the second image to get an outcome such as the third image. Where black and white wouldn't change because it's being colourised by gray, but the sky becomes blue and the shorts become red with yellow dots.

Is that possible in any way?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is this possible? (colour + detail = colour&detail)

Post by snibgo »

I think you want to make every gray pixel in the first image transparent, then composite that over the second image.

If you supply the three actual images, we can check that. They should be PNG sources or similar that have not been through JPEG compression.
snibgo's IM pages: im.snibgo.com

LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

Re: Is this possible? (colour + detail = colour&detail)

Post by LDAsh »

Your idea sounds okay but there's a huge caveat - what if the image with the colour is lower resolution than what I want to composite over? I'd like to keep the clarity of the greyscale details but colourise it as much as I can from another image. I was thinking about what you said about splitting all of the colour channels, cleaning those up by filtering each one with the others (to remove all greys too) and then using those as masks to colourise.

Here are the source images:-
http://www.violae.net/temp/IM_colplusgreycom.zip

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Is this possible? (colour + detail = colour&detail)

Post by snibgo »

I make a mask that is white where ele_a has any colour, and black where ele_a is a shade of gray. Then I composite with that mask.

Code: Select all

%IMG7%magick ^
  ele_a.png ^
  -colorspace HSL -channel 1 -separate +channel ^
  -threshold 0 ^
  ele_mask.png

%IMG7%magick ^
  ele_b.png ^
  ele_a.png ^
  ele_mask.png ^
  -compose Over -composite ^
  ele_out.png
(The two commands could be combined into one.)

The result is almost correct:
Image
There are differences. I don't see how to correct that.


If your two images are different sizes, then first resize one to the same size as the other.
snibgo's IM pages: im.snibgo.com

Locked