# Image blending dependent on image column

I have two images:

I can blend them:

img1 = Import["https://i.stack.imgur.com/1PJxM.png"];
img2 = Import["https://i.stack.imgur.com/blxtM.png"];
x = 0.5;
Blend[{img1, img2}, x]


Output:

Now how do I do the blending in such a way that "x" varies with image column? I want to get an image that is red on the left side, then transitions smoothly in the middle and is yellow on the right side

One way is:

img3 = ImageMultiply[img1,
img4 = ImageMultiply[img2,


• That looks good. Now I just need a way to make it so that transition is more focused in the middle. Using image that is 1/3 black, 1/3gradient and 1/3 white instead of gradient should do it. Do you know how to accomplish this? – Adam Sikora Nov 19 '16 at 11:20
• @AdamSikora I suggest you fiddle with the gradient lists yourself until you get what you want. You could do for instance: LinearGradientImage[{Red, White, Black}, ImageDimensions[img1] and LinearGradientImage[{Black, White, Yellow}, ImageDimensions[img1], and even make lists of different lengths. – Feyre Nov 19 '16 at 11:23
• Or make varying lists with the colors White,Gray,Black. – Feyre Nov 19 '16 at 11:29
• {White, White, White, Gray, Black, Black, Black} did the trick perfectly. Thanks Feyre – Adam Sikora Nov 19 '16 at 11:33

This is basically a custom version of Blend that takes a function, which can depend on x and y, that should return the fraction:

blend[{i1_, i2_}, f_] := ImageAdd[

{w, h} = ImageDimensions[img1];