Overlaying Noise

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
AwooOOoo
Posts: 2
Joined: 2015-08-26T01:43:50-07:00
Authentication code: 1151

Overlaying Noise

Post by AwooOOoo »

Hi,
I'm trying to create create an image with noise and do it with one combined command, but am having issues.

The image is simply text (i.e. ABCD) and I want to overlay black and white noise to obscure the letters

First creating the text on its own image...

Code: Select all

convert -size 100x100 xc:none  -pointsize 35 -gravity center -draw "text 0,0 'ABCD' " test.png
Next create the black and white noise...

Code: Select all

convert -size 100x100 xc: +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite test2.png
If I want to draw the letters on the noise...

Code: Select all

convert -size 100x100 xc: +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite -pointsize 35 -gravity center -draw "text 0,0 'ABCD' " test3.png
...but this isn't what I want as the noise is under the letters, not over them...

If I reverse the commands however the noise completely covers the letters (as there is no transparency) so I do not see them at all using the following command

Code: Select all

convert -size 100x100 xc:none  -pointsize 35 -gravity center -draw "text 0,0 'ABCD' " xc: +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite test4.png
I tried using -transparent white, but this didn't help. I believe of the xc canvas creation for the noise is swamping the previously defined text. I imagine I need to use parenthesis to separate the layers while they are created and then somehow glue them back together...but I'm not sure how to do it properly.

Can someone please tell me how to correct this, or a better way of accomplishing my goal?

Ammendment: Running 6.9.1 Q16 (64 bit) via DOS command line

Paul.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Overlaying Noise

Post by 246246 »

Probably better approach exists, but following seems to work with 6.9.2-0 Q16 x86 on Windows.
(And also checked with 6.9.0-0 Q16 x86_64 on Mac after converted to proper syntax.)

Code: Select all

convert xc:none[100x100!] ^
 +noise random -channel G -threshold 25% -negate -channel RG -separate +channel ^
 -compose CopyOpacity -composite +write mpr:1 +delete ^
 xc:none[100x100!] -pointsize 35 -gravity center -draw "text 0,0 'ABCD'" ^
 mpr:1 -compose Over -composite test.png
Edit:
After looking a bit, it does not need to be so complex: following is enough (in Unix syntax)

Code: Select all

convert \( xc:none[100x100\!] +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite \) \( xc:none[100x100\!] -pointsize 35 -gravity center -draw "text 0,0 'ABCD'" \) -compose DstOver -composite show:
or

Code: Select all

convert xc:none[100x100\!] \( -clone 0 +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite \) \( -clone 0 -pointsize 35 -gravity center -draw "text 0,0 'ABCD'" \) -delete 0 -compose DstOver -composite show:
Edit 2:
if you want only letter part (like Fred's answer below), replace DstOver to DstIn.

Code: Select all

convert xc:none[100x100\!] \( -clone 0 +noise random -channel G -threshold 25% -negate -channel RG -separate +channel -compose CopyOpacity -composite \) \( -clone 0 -pointsize 35 -gravity center -draw "text 0,0 'ABCD'" \) -delete 0 -compose DstIn -composite show:
Last edited by 246246 on 2015-08-26T17:43:08-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: Overlaying Noise

Post by fmw42 »

If you use gaussian noise, it will add to the base image. Random noise replaces the base image. See -attenuate X +noise gaussian

compare these three results:

Code: Select all

convert -size 500x200 xc:none  -font verdana -pointsize 100 -gravity center -draw "text 0,0 'ABCD'" result1.png 

Code: Select all

convert -size 500x200 xc:none  -font verdana -pointsize 100 -gravity center -draw "text 0,0 'ABCD'" -attenuate 5 +noise gaussian result2.png

Code: Select all

convert -size 500x200 xc:none  -font verdana -pointsize 100 -gravity center -draw "text 0,0 'ABCD'" -attenuate 5 +noise gaussian -colorspace gray result3.png
AwooOOoo
Posts: 2
Joined: 2015-08-26T01:43:50-07:00
Authentication code: 1151

Re: Overlaying Noise

Post by AwooOOoo »

Thank you,
This is just what I was after! As it turns out, I have use for both noise on just the letters and the letters plus the background so this is good and I understand the syntax of grouping operations better now.

Sincerely, Paul.
Post Reply