12
$\begingroup$

The question is simple:

How can I take an image of a perfect stamp (load an image file) such as

enter image description here

and make it look old, worn, and faded, with missing arbitrary small bits, like the following stamp

enter image description here

Any suggestions?

$\endgroup$
  • $\begingroup$ @Kuba For me it does not matter if it is a stamp or a photo. All I want is to load an image file (.bmp, .png, .jpg, etc) and remove arbitrary small bits from it, thus making it look old and worn. $\endgroup$ – Vaggelis_Z Nov 10 '17 at 15:23
  • $\begingroup$ @Kuba Please see my edit! $\endgroup$ – Vaggelis_Z Nov 10 '17 at 15:48
  • $\begingroup$ Thanks and sorry for being picky :) $\endgroup$ – Kuba Nov 10 '17 at 16:34
  • $\begingroup$ @AccidentalFourierTransform Done! Thank you! $\endgroup$ – Vaggelis_Z Nov 11 '17 at 16:52
28
$\begingroup$

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]]

enter image description here

Then binarize that noise, using MorphologicalBinarize:

binary = MorphologicalBinarize[noise, {.6, .7}]

enter image description here

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]]

enter image description here

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}]

enter image description here

$\endgroup$
14
$\begingroup$

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"]

alpha x a resized random image

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"]

SaltPepper holes in the alpha mask

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"]

Resize a gaussian noise addition to make it look like regions and not just pixels are missing.

Of course you can play with the noise type and the starting image size to get what matches what you want best.

$\endgroup$
  • $\begingroup$ When I try the first method with another image I get the following error message: "ColorCombine::ccbinput: should be a list of images with the same image dimensions." $\endgroup$ – Vaggelis_Z Nov 10 '17 at 16:39
  • $\begingroup$ I also get the same error message when I try the exact same image of the example. $\endgroup$ – Vaggelis_Z Nov 10 '17 at 16:41
  • $\begingroup$ Hmm. Weird. What does ImageDimensions /@ (ColorSeparate[im]*{1, 1, 1, ImageResize[RandomImage[1, {100, 100}], {200, 200}]}) say? $\endgroup$ – kjosborne Nov 10 '17 at 16:42
  • $\begingroup$ I cannot reproduce neither of the three methods. I tried in v9 and v11 with no luck. In all three of them the ColorCombine module complains about the dimensions. $\endgroup$ – Vaggelis_Z Nov 10 '17 at 16:55
  • $\begingroup$ It sounds like you're on a version before the regular arithmetic functions were extended to images. That's fairly recent. $\endgroup$ – kjosborne Nov 10 '17 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.