Victor Image Processing Library How-to Tips

Creating Artificial Snow

An object in an image appears to be snow-covered when the bright areas are replaced with a scattering of white pixels.
Convertible with top down
Convertible with top down in the snow
Covered in Snow

We create a very high contrast grayscale version of the image, then generate an error diffusion scatter of white and black pixels by converting it to 1-bit, then back to 8-bit grayscale again. The black and white scatter picture is dropped over the original using a threshold of zero. This sets the black pixels to be transparent.

Artificial Snow - the Source Code

This function works well for both grayscale and color images. Requires Victor Image Processing Library v 4.1x or higher.
int artsnow(imgdes *srcimg, imgdes *resimg)
   imgdes tmp24, tmp8, tmp1;
   int cols, rows, rcode, mode=0;
   cols = CALC_WIDTH(srcimg);
   rows = CALC_HEIGHT(srcimg);
   allocimage(&tmp8, cols, rows, 8);
   allocimage(&tmp1, cols, rows, 1);
   if(srcimg->bmh->biBitCount == 24) {
      allocimage(&tmp24, cols, rows, 24);
   colortogray(srcimg, &tmp8);
   expandcontrast(100, 155, &tmp8, &tmp8);
   convert8bitto1bit(mode, &tmp8, &tmp1);
   convert1bitto8bit(&tmp1, &tmp8);
   if(srcimg->bmh->biBitCount == 24) {
      convertpaltorgb(&tmp8, &tmp24);
      rcode = cover(0, srcimg, &tmp24, resimg);
      rcode = cover(0, srcimg, &tmp8, resimg);

Copyright © 1997 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.

Victor Image Processing Library homepage | Victor Sample Code