Increasing atop opacity/intensity

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
credomane
Posts: 5
Joined: 2017-05-08T07:59:34-07:00
Authentication code: 1151

Increasing atop opacity/intensity

Post by credomane »

Originally I created this finished image in GIMP by simply change the overlay mode to color and setting the opacity to 75%.
Image

This file needs regenerated occasionally when the source concrete file changes. After doing this manually I figured I could automate it using ImageMagick
So far the best result I've gotten is
Image
As you can see the overlay is very transparent. I've tried to change the atop filter but it doesn't seem to have any options that I could find. I'm no closer to automating the image I made with GIMP than what I show here. It doesn't need to be 100% exact but getting closer is the goal.

Command used

Code: Select all

#!/bin/bash
size=`convert concrete.png -format "%wx%h" info:`
convert concrete.png \( overlay.png -crop "$size" \) -compose atop -composite ./result/concrete.png
Anyone have ideas?

convert -version
Version: ImageMagick 6.9.5-7 Q16 x86_64 2016-12-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP
Delegates (built-in): autotrace bzlib cairo fftw fontconfig fpx freetype gslib jbig jng jp2 jpeg lcms lzma pangocairo png ps rsvg tiff webp x xml zlib
Source images:
Image
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Increasing atop opacity/intensity

Post by snibgo »

I can't see that your "-crop "$size"" has any effect. Try "-channel A -evaluate Multiply 0.75 +channel" in the same location.
snibgo's IM pages: im.snibgo.com
credomane
Posts: 5
Joined: 2017-05-08T07:59:34-07:00
Authentication code: 1151

Re: Increasing atop opacity/intensity

Post by credomane »

I had "-crop "$size"" so as to crop the 2048x2048 overlay to the dimensions of the source image. As you said is doesn't seem to actually do anything. Well crap.

The "-channel A -evaluate Multiply 0.75 +channel" gets me very very close! Now I have something to play with. Thanks so much!
credomane
Posts: 5
Joined: 2017-05-08T07:59:34-07:00
Authentication code: 1151

Re: Increasing atop opacity/intensity

Post by credomane »

Is there a place that explains "-channel A -evaluate Multiply 0.75 +channel"? Or can you explain it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Increasing atop opacity/intensity

Post by snibgo »

"-channel A {operation} +channel" means the operation will be performed on only the A channel, which is Alpha, aka opacity. So this multiplies opacity by 0.75. So fully opaque becomes 75% opaque. Fully transparent (opacity=0) stays fully transparent. See http://www.imagemagick.org/script/comma ... hp#channel etc.

The "-crop" as no effect because it crops the "source" to the same size as the "destination". But the output of "-composite" is already limited to the size of the destination.
snibgo's IM pages: im.snibgo.com
credomane
Posts: 5
Joined: 2017-05-08T07:59:34-07:00
Authentication code: 1151

Re: Increasing atop opacity/intensity

Post by credomane »

I think perhaps I'm going about using imagemagick the wrong way to accomplish what I want.

The more I play with atop and/or the more I increase the opacity of the overlay the more it overrides the source image causing details to be lost. Which is exactly what atop is meant to do but now I realize that it isn't what I'm trying to do. Got excited when I found atop and never considered I was walking the wrong path. Oops.

What I'm really needing to do is colorize the source image. I can do

Code: Select all

convert ./testing/concrete.png -fill "rgb(255,0,0)" -colorize 25,25,25,0 -level "0%,100%,0.8" ./testing/result/red.png
This gives me nice images shifted towards red but I only want to shift the parts where my overlay image and the source image are both non-transparent. That make sense?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Increasing atop opacity/intensity

Post by snibgo »

credomane wrote:... but now I realize that it isn't what I'm trying to do.
Figuring out what we want is often the hardest part of the task!

There are plenty of alternatives to "atop", such as "colorize". See http://www.imagemagick.org/Usage/compose/#colorize

Code: Select all

convert zwuvgCg.png ( +clone -alpha extract +write mpr:ALP +delete ) ( 2QjTGat.png  +write x.png ) -compose colorize -composite mpr:ALP -alpha off -compose CopyOpacity -composite r.png
You can play around with operations to 2QjTGat.png (eg -colorize and -level), saving the intermediate result to x.png for testing.
snibgo's IM pages: im.snibgo.com
credomane
Posts: 5
Joined: 2017-05-08T07:59:34-07:00
Authentication code: 1151

Re: Increasing atop opacity/intensity

Post by credomane »

After a ton more playing around I get what I wanted and then some!
I converted the red stripes to black. Probably not needed considering I convert it to an alpha map.

Code: Select all

    convert zwuvgCg.png \
    \( +clone -fill "rgb(255,0,0)" -colorize $C,$C,$C,0 -level "0%,100%,0.8" \) \
    \( 2QjTGat.png -alpha extract -flop \) \
    -compose SrcIn -composite ./output.png
It is beautiful! I can modify the coloring however I want and apply it to the original image using a mask of my choice for pretty effects.
Image

Thanks for all your help! This snippet of code was the key for me to figure everything out!

Code: Select all

( +clone -alpha extract +write mpr:ALP +delete )
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Increasing atop opacity/intensity

Post by fmw42 »

Have you tried

Code: Select all

convert zwuvgCg.png \( 2QjTGat.png -channel a -evaluate multiply 0.75 +channel \) -compose colorize -composite result.pn
Post Reply