compose and colorize images on blank canvas

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?".
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

compose and colorize images on blank canvas

Post by higoka »

I need to compose some images into a transparent blank canvas. Some images need to have a red color overlay with -composite multiply!
The problem is that when i use a transparent canvas and compose, the images which should have a color overlay just disappear or get transparent.

What exactly i want to do:
1. Create a empty transparent canvas. 8-bit
2. Place each image on top of the canvas with x and y offsets.
3. Put a red color overlay (multiply) over img/b_4_0.png and img/c_4_1.png.
4. Somehow make that the light of the flame (img/g_4_1.png) is transparent. (remove the black around it)

Here are the images: https://ufile.io/61jror4f

This is the command i use

Code: Select all

convert -size 300x300 canvas:transparent -depth 8 \
  \( img/a_4_0.png -geometry +122+137 \) -composite \
  \( img/b_4_0.png -geometry +132+115 -compose multiply -fill red -colorize 100% \) -composite \
  \( img/c_4_1.png -geometry +142+81 -compose multiply -fill red -colorize 100% \) -composite \
  \( img/d_4_0.png -geometry +133+116 -compose plus \) -composite \
  \( img/e_4_1.png -geometry +143+82 -compose plus \) -composite \
  \( img/f_4_1.png -geometry +147+54 \) -composite \
  \( img/g_4_1.png -geometry +125+36 -compose plus \) -composite \
  img/result.png
ResultImage

If i use for example a red background for the canvas and remove the red color after the image is composed it kind of works.
The only problem with this is that there is a red circle around the light of the flame. (img/g_4_1.png)

Here the other command

Code: Select all

convert -size 300x300 canvas:red -depth 8 \
  \( img/a_4_0.png -geometry +122+137 \) -composite \
  \( img/b_4_0.png -geometry +132+115 -compose multiply \) -composite \
  \( img/c_4_1.png -geometry +142+81 -compose multiply \) -composite \
  \( img/d_4_0.png -geometry +133+116 -compose plus \) -composite \
  \( img/e_4_1.png -geometry +143+82 -compose plus \) -composite \
  \( img/f_4_1.png -geometry +147+54 \) -composite \
  \( img/g_4_1.png -geometry +125+36 -compose plus \) -composite \
  -transparent red img/result.png
ResultImage

I think what i try to do is clear enough. If not just ask.
And hope somebody could help me. Im desperate :/
Last edited by higoka on 2019-04-22T23:18:42-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

Please zip (or rar) all your files, then upload the zip container so that your images keep their proper names that correspond to those in your command line.

Your command sequence does not make sense to me. You are not supposed to put anything between -compose x and -composite and the -compose X should be outside the parenthesis. Also -fill X -colorize 100 will make the whole image completely red.

See https://imagemagick.org/Usage/layers/#convert for compose composite syntax for a sequence of images.

You only need the parenthesis to add red to your image and the percent should not be 100 or the image will be totally red.

So until I have access to the images with correct names, I cannot really test your code.

This

Code: Select all

convert -size 300x300 canvas:red -depth 8 \
  \( img/a_4_0.png -geometry +122+137 \) -composite \
  \( img/b_4_0.png -geometry +132+115 -compose multiply \) -composite \
  \( img/c_4_1.png -geometry +142+81 -compose multiply \) -composite \
  \( img/d_4_0.png -geometry +133+116 -compose plus \) -composite \
  \( img/e_4_1.png -geometry +143+82 -compose plus \) -composite \
  \( img/f_4_1.png -geometry +147+54 \) -composite \
  \( img/g_4_1.png -geometry +125+36 -compose plus \) -composite \
  -transparent red img/result.png
Should be more like

Code: Select all

convert -size 300x300 canvas:red -depth 8 \
img/a_4_0.png -geometry +122+137 -compose over -composite \
img/b_4_0.png -geometry +132+115 -compose multiply -composite \
img/c_4_1.png -geometry +142+81 -compose multiply -composite \
img/d_4_0.png -geometry +133+116 -compose plus -composite \
img/e_4_1.png -geometry +143+82 -compose plus -composite \
img/f_4_1.png -geometry +147+54  -compose over -composite \
img/g_4_1.png -geometry +125+36 -compose plus -composite \
-transparent red img/result.png
If you do not reset the -compose method, it will be assumed to be whatever preceded it.
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

I'm new to imagemagick, sorry for the confusion with the paranthese.
Anyway here are the zipped images: https://ufile.io/61jror4f

Also i think it should be colorize 100 because i want the full color. Then it should "blend" together using compose multiply.
Correct me if i'm wrong.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

If you do a compose multiply properly, then yes. But I do not think that was what you were doing in your first set of commands. At least it is not a proper command.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

Try this and let me know if that is what you want? If not, let me know how and where the result is not what you want.

Code: Select all

convert -size 300x300 canvas:transparent -depth 8 \
img/a_4_0.png -geometry +122+137 -compose over -composite \
\( img/b_4_0.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
\( img/c_4_1.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
img/d_4_0.png -geometry +133+116 -compose plus -composite \
img/e_4_1.png -geometry +143+82 -compose plus -composite \
img/f_4_1.png -geometry +147+54 -compose over -composite \
img/g_4_1.png -geometry +125+36 -compose plus -composite \
img/result.png
Image

You have to make a clone to turn it red, then compose multiply that and then -compose over -composite the result with the previous image.

As I mentioned before, when changing compose methods, the default is not -compose over, but whatever you used previously. So you need to reset the compose method to over rather than just using -composite.
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

Yes, the colorizing part is done. The only problem now is the black around the flame as you can see.
The image which causes this problem is img/g_4_1.png

I think it has something to do with the alpha channel or opacity.
Last edited by higoka on 2019-04-23T00:00:52-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

What is it that you want to show there. If you do not like the "glare" remove it from the g-4-1 image. Just make that image totally black. If you do not want the black at all make that whole image transparent or remove it from the command line.

Sorry, I do not know what you want to change.
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

I want the opposite, like keeping the yellow glow but removing the black around it.
See the small glow around the flame
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

That is hard to do from the g_4_1.png image you provided. You should probably create a new one.

Code: Select all

convert -size 300x300 canvas:transparent -depth 8 \
img/a_4_0.png -geometry +122+137 -compose over -composite \
\( img/b_4_0.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
\( img/c_4_1.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
img/d_4_0.png -geometry +133+116 -compose plus -composite \
img/e_4_1.png -geometry +143+82 -compose plus -composite \
img/f_4_1.png -geometry +147+54 -compose over -composite \
\( img/g_4_1.png -fuzz 15% -transparent black -channel alpha -blur 0x2 -level 50x100% +channel \) -geometry +125+36 -compose plus -composite \
img/result2.png
Image


Code: Select all

convert -size 300x300 canvas:transparent -depth 8 \
img/a_4_0.png -geometry +122+137 -compose over -composite \
\( img/b_4_0.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
\( img/c_4_1.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
img/d_4_0.png -geometry +133+116 -compose plus -composite \
img/e_4_1.png -geometry +143+82 -compose plus -composite \
img/f_4_1.png -geometry +147+54 -compose over -composite \
\( img/g_4_1.png -fuzz 15% -transparent black -channel alpha -blur 0x2 -level 50x100% +channel -fill yellow -colorize 30% \) -geometry +125+36 -compose plus -composite \
img/result3.png
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compose and colorize images on blank canvas

Post by fmw42 »

Try this

Code: Select all

convert -size 300x300 canvas:transparent -depth 8 \
img/a_4_0.png -geometry +122+137 -compose over -composite \
\( img/b_4_0.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
\( img/c_4_1.png \( +clone -fill red -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
img/d_4_0.png -geometry +133+116 -compose plus -composite \
img/e_4_1.png -geometry +143+82 -compose plus -composite \
img/f_4_1.png -geometry +147+54 -compose over -composite \
\( \( img/g_4_1.png -fill yellow -colorize 100% \) \
\( img/g_4_1.png -fuzz 7% -transparent black -channel alpha -blur 0x9 -level 50x100% +channel \) \
-compose over -compose copy_opacity -composite \) -geometry +125+36 -compose dst_over -composite \
img/result4.png
Image

Change the yellow color as desired.
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

Ive noticed something strange. When i use a background color for the canvas the glow of the flame is displayed correct, without the black pixels around it.
Image

But if i use a transparent background for the canvas the black pixels around the glow still are there.
Image

Here is the convert command

Code: Select all

convert -size 300x300 canvas:transparent -depth 8 -colorspace srgb \
  img/a_4_0.png -geometry +122+137 -compose over -composite \
  \( img/b_4_0.png \( +clone -fill '#B357FF' -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
  \( img/c_4_1.png \( +clone -fill '#B357FF' -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
  img/d_4_0.png -geometry +133+116 -compose plus -composite \
  img/e_4_1.png -geometry +143+82 -compose plus -composite \
  img/f_4_1.png -geometry +147+54 -compose over -composite \
  img/g_4_1.png -geometry +125+36 -compose plus -composite \
  img/result.png
Could it be because the glow (img/g_4_1.png) is PaletteAlpha and the composed image is TrueColorAlpha?
But i rather think it has something to do with the transparent pixel and -compose plus.

I created a gist with the output of identify -verbose if someone could use some information about the images.
https://gist.github.com/higoka/c27813b5 ... 9008ac9d2a
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: compose and colorize images on blank canvas

Post by snibgo »

@higoka: What version of IM are you using? v6 and v7 behave differently when you have transparency. In v7, we often need "-channel RGB" to restrict operations to the colour channels.

If you use v7, I suggest you use "magick", not "convert".
snibgo's IM pages: im.snibgo.com
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

I use v7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: compose and colorize images on blank canvas

Post by snibgo »

I encourage you to use "magick".

I also encourage you to break your problem into simpler processes, and discover the effect of restricting operations to just the colour channels.
snibgo's IM pages: im.snibgo.com
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: compose and colorize images on blank canvas

Post by higoka »

I tried using -channel rgb then the glow just gets transparent. The other images are displayed correct. It has something to do with the alpha.
And what do you mean by "magick"?
Post Reply