What version of IM? I assume v6. If v7, use "magick" instead of "convert". What platform? I assume Windows.
Many methods are possible, such as this (Windows BAT format, for IM v6.)
Code: Select all
convert ^
flowRoot3688.png -alpha extract ^
( +clone ^
-fill gray(50%%) -colorize 100 ^
+noise Gaussian ^
-channel R -separate +channel ^
-blur 0x1 ^
-auto-level ^
) ^
-evaluate-sequence Mean ^
-threshold 50%% ^
-define connected-components:area-threshold=20 ^
-define connected-components:mean-color=true ^
-connected-components 4 ^
-threshold 50%% ^
-blur 0x0.5 ^
( +clone ^
-fill Black -colorize 100 ^
) ^
+swap ^
-compose CopyOpacity -composite ^
noisyFont.png
I prefer to work in black and white, rather than opaque and transparent, so I extract alpha at the start and copy opacity at the end.
I create a clone of the image, and replace the pixels with Gaussian random, use just the red channel, and blur it, (adjust the blur sigma from 1 if you want) and auto-level.
I take the mean of the text image and the noise, and threshold to 50% to get white characters on black background. However, there will be some small patches of black within the white characters, and small patches of white within the black background. Connected-components, followed by another threshold, removes these.
Now we have entirely white characters on black background. A small blur gives an antialias. (There are "proper" ways of doing this, but they are more complex.) If you don't want the antialias, remove that blur.
Then we create an entirely black image and copy the opacity to it.
My command is rather complex. I suspect there is a simpler method.