Page 1 of 1

Generate a gradient from a image?

Posted: 2015-06-24T11:42:50-07:00
by Lassar
I would like make a gradient from a color image, and apply it to another black and white image.

How would I get the gradient from the color image?

An example is to get a gradient from a photo of clouds at sunset, and apply it another photo of black and white clouds.

How would you do this with ImageMagick?

Re: Generate a gradient from a image?

Posted: 2015-06-30T16:49:07-07:00
by fmw42
A perfect solution is not possible, because many colors may map to the same gray intensity. There is no way to know which color to use.

My best suggestion is to correlate a few colors from locations in the colored image with shades of gray in your grayscale image. Then build a clut image (what you call the gradient) and apply it using -clut.

For example:

Here is a color image:
Image

Here is a corresponding grayscale image:
Image

My command, where I have selected just a few colors (unix syntax):

Code: Select all

convert gray_image.jpg \
\( xc:black xc:blue xc:green1 xc:red xc:white +append -resize 256x1! \) \
-clut gray_image_colored.jpg
(windows syntax, I think)

Code: Select all

convert gray_image.jpg ^
( xc:black xc:blue xc:green1 xc:red xc:white +append -resize 256x1^! ) ^
-clut gray_image_colored.jpg
Resulting image:
Image