The code below creates a white 800x600 image, peppers it with random black spots and then despeckles it, saving before and after images. The before image has pure black spots on a pure white background. The despeckle operation changes all black spots (0) to slightly lighter ones (16) and also adds a light gray border around them and around the entire image.
If this is what's supposed to happen, which operation should I be using to remove the "pepper" from the image?
Thanks
Pete
Code: Select all
#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(LPTSTR lpCmdLine)
{
MagickWand *mw = NULL;
unsigned char image[800*600],*ip;
int i,j,k;
MagickWandGenesis();
mw = NewMagickWand();
ip = image;
for(i=0;i<600;i++) {
for(j=0;j<800;j++) {
*ip++ = 255;
}
}
srand(time(0));
for(i=0;i<500;i++) {
// plonk some random black pixels in the image
j = rand()%600;
k = rand()%800;
image[k*j] = 0;
}
MagickConstituteImage(mw,800,600,"I",CharPixel,image);
MagickWriteImage(mw,"pepper.png");
MagickDespeckleImage(mw);
MagickWriteImage(mw,"pepper_despeckle.png");
DestroyMagickWand(mw);
MagickWandTerminus();
}