The question is simple:
How can I take an image of a perfect stamp (load an image file) such as
and make it look old, worn, and faded, with missing arbitrary small bits, like the following stamp
Any suggestions?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThe question is simple:
How can I take an image of a perfect stamp (load an image file) such as
and make it look old, worn, and faded, with missing arbitrary small bits, like the following stamp
Any suggestions?
You could try something like this:
with your image,
img = Import["https://i.stack.imgur.com/hf1aj.png"]
create some random noise and smooth it, to make the "dirt grains" smoother:
noise = ImageAdjust[
GaussianFilter[RandomImage[{0, 1}, ImageDimensions[img]], 2]]
Then binarize that noise, using MorphologicalBinarize:
binary = MorphologicalBinarize[noise, {.6, .7}]
This produces fewer, larger "grains" than simply using Binarize.
Now subtract that image from the alpha channel in your image:
SetAlphaChannel[img, ImageSubtract[AlphaChannel[img], binary]]
You can play around with the filter size and the binarization thresholds to get different "graininess":
rnd = RandomImage[{0, 1}, ImageDimensions[img]];
Manipulate[
SetAlphaChannel[img,
ImageSubtract[AlphaChannel[img],
MorphologicalBinarize[
ImageAdjust[GaussianFilter[rnd, s]], {t1, t2}]]],
{{s, 2}, 0, 10}, {{t1, .6}, 0, 1}, {{t2, .7}, 0, 1}]
Given that your image already has an alpha channel, I would try to reduce the opaque mask on the "stamp" that already exists by multiplying the alpha channel by some selected noise.
Here are a few examples:
im = Import["https://i.stack.imgur.com/hf1aj.png"];
Create flatly random noise in a size half that of the image, then scale. This rescaling reduces pixelation and helps to remove sections rather than just one-off pixels:
ColorCombine[ColorSeparate[im]*{1, 1, 1, ImageResize[RandomImage[1, {100, 100}], {200, 200}]}, "RGB"]
This one is going to use isolated pixels, but has good contrast since it's using SaltPepper noise:
ColorCombine[ColorSeparate[im]*{1, 1, 1, ImageEffect[ConstantImage[White, {200, 200}], {"SaltPepperNoise", 1/3}]}, "RGB"]
I think my favorite is a resize of GaussianNoise:
ColorCombine[ColorSeparate[im]*{1, 1, 1, ImageResize[ImageEffect[ ConstantImage[White, {100, 100}], {"GaussianNoise", 2/3}], Scaled[2]]}, "RGB"]
Of course you can play with the noise type and the starting image size to get what matches what you want best.
ImageDimensions /@ (ColorSeparate[im]*{1, 1, 1, ImageResize[RandomImage[1, {100, 100}], {200, 200}]})
say?
$\endgroup$
Nov 10, 2017 at 16:42
ColorCombine
module complains about the dimensions.
$\endgroup$
Nov 10, 2017 at 16:55