Page 1 of 1

Overlaying Noise

Posted: 2015-08-26T02:16:51-07:00
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.

Re: Overlaying Noise

Posted: 2015-08-26T06:44:04-07:00
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:

Re: Overlaying Noise

Posted: 2015-08-26T09:16:06-07:00
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

Re: Overlaying Noise

Posted: 2015-08-26T23:23:54-07:00
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.