mixing images

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
manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

mixing images

Post by manit »

i have a fantastic idea.
Suppose I have two images one contains red colour only while other contains only yellow colour & I want that both images should be combined such that when they overlap at a point then resultant colour appears that is red+yellow=orange.
How can this be done ?
Will I have to take a pixel from each file then combine both colours.I hope there is an easy way ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mixing images

Post by fmw42 »

manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

Draw line with red color over yellow then orange be outcome

Post by manit »

I tried blend & dissolve but image intensity decreases if I want to mix two images equally.
My idea is to draw series of red coloured circled then draw yellow on same image so that at points of intersection I get orange . Is that possible ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw line with red color over yellow then orange be outcome

Post by fmw42 »

manit wrote:I tried blend & dissolve but image intensity decreases if I want to mix two images equally.
My idea is to draw series of red coloured circled then draw yellow on same image so that at points of intersection I get orange . Is that possible ?

Try -compose plus -composite, see http://www.imagemagick.org/Usage/compose/#plus
manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

Re: mixing images

Post by manit »

It has been a long long time .
But , better late than never .
Here are the results .

creating blue concentric circles of varying intensity

Code: Select all

cd "C:\Program Files\ImageMagick-6.9.2-Q16"
c:
imconvert -size 510x488 xc:none -fill "rgb(0,0,16)" -draw "circle 250,170 250,180" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,32)" -draw "circle 250,170 250,180" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,48)" -draw "circle 250,170 250,190" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,64)" -draw "circle 250,170 250,200" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,80)" -draw "circle 250,170 250,210" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,96)" -draw "circle 250,170 250,220" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,112)" -draw "circle 250,170 250,230" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,128)" -draw "circle 250,170 250,240" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,144)" -draw "circle 250,170 250,250" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,160)" -draw "circle 250,170 250,260" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,176)" -draw "circle 250,170 250,270" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,192)" -draw "circle 250,170 250,280" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,208)" -draw "circle 250,170 250,290" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,224)" -draw "circle 250,170 250,300" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,240)" -draw "circle 250,170 250,310" d:\im\compose_B.png
imconvert d:\im\compose_B.png -fill none -strokewidth 10 -stroke "rgb(0,0,255)" -draw "circle 250,170 250,320" d:\im\compose_B.png
creating green concentric circles of varying intensity

Code: Select all

cd "C:\Program Files\ImageMagick-6.9.2-Q16"
c:
imconvert -size 510x488 xc:none -fill "rgb(0,16,0)" -draw "circle 340,318 340,328" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,32,0)" -draw "circle 340,318 340,328" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,48,0)" -draw "circle 340,318 340,338" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,64,0)" -draw "circle 340,318 340,348" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,80,0)" -draw "circle 340,318 340,358" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,96,0)" -draw "circle 340,318 340,368" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,112,0)" -draw "circle 340,318 340,378" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,128,0)" -draw "circle 340,318 340,388" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,144,0)" -draw "circle 340,318 340,398" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,160,0)" -draw "circle 340,318 340,408" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,176,0)" -draw "circle 340,318 340,418" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,192,0)" -draw "circle 340,318 340,428" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,208,0)" -draw "circle 340,318 340,438" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,224,0)" -draw "circle 340,318 340,448" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,240,0)" -draw "circle 340,318 340,458" d:\im\compose_G.png
imconvert d:\im\compose_G.png -fill none -strokewidth 10 -stroke "rgb(0,255,0)" -draw "circle 340,318 340,468" d:\im\compose_G.png
creating red concentric circles of varying intensity

Code: Select all

cd "C:\Program Files\ImageMagick-6.9.2-Q16"
c:
imconvert -size 510x488 xc:none -fill "rgb(16,0,0)" -draw "circle 170,318 170,328" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(32,0,0)" -draw "circle 170,318 170,328" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(48,0,0)" -draw "circle 170,318 170,338" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(64,0,0)" -draw "circle 170,318 170,348" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(80,0,0)" -draw "circle 170,318 170,358" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(96,0,0)" -draw "circle 170,318 170,368" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(112,0,0)" -draw "circle 170,318 170,378" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(128,0,0)" -draw "circle 170,318 170,388" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(144,0,0)" -draw "circle 170,318 170,398" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(160,0,0)" -draw "circle 170,318 170,408" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(176,0,0)" -draw "circle 170,318 170,418" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(192,0,0)" -draw "circle 170,318 170,428" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(208,0,0)" -draw "circle 170,318 170,438" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(224,0,0)" -draw "circle 170,318 170,448" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(240,0,0)" -draw "circle 170,318 170,458" d:\im\compose_R.png
imconvert d:\im\compose_R.png -fill none -strokewidth 10 -stroke "rgb(255,0,0)" -draw "circle 170,318 170,468" d:\im\compose_R.png
I combined above 3 files

The result was not so flattering as colours mixed were not of equal intensity .
I was hoping of an image in which red colour of level 16 will mix with green and blue of 16 .
Actually , i will need a gradient for that .
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: mixing images

Post by snibgo »

manit wrote:I tried blend & dissolve but image intensity decreases if I want to mix two images equally.
A very late response to that particular point: when blending graphic colours, the result often looks better if you convert to linear RGB before blending, then back to sRGB after blending.

Or, of course, do all the work in linear RGB, and convert only the final result to sRGB.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mixing images

Post by fmw42 »

manit wrote:i have a fantastic idea.
Suppose I have two images one contains red colour only while other contains only yellow colour & I want that both images should be combined such that when they overlap at a point then resultant colour appears that is red+yellow=orange.
How can this be done ?
Will I have to take a pixel from each file then combine both colours.I hope there is an easy way ?

Not sure if this is what you want, but try this (unix syntax)

Code: Select all

convert -size 128x128 xc:"rgba(255,0,0,0.5)" \
-page +64+64 -size 128x128 xc:"rgba(255,255,0,0.5)" \
-background none -layers merge +repage -alpha off orange.png
Windows syntax:

Code: Select all

convert.exe -size 128x128 xc:"rgba(255,0,0,0.5)" ^
-page +64+64 -size 128x128 xc:"rgba(255,255,0,0.5)" ^
-background none -layers merge +repage -alpha off orange.png
Post Reply