Page 1 of 1

Despeckle

Posted: 2008-10-22T20:47:41-07:00
by el_supremo
I had assumed that MagickDespeckleImage would remove "pepper" from an image but that doesn't appear to be the case (I'm using IM 6.4.4-5). What does it actually do?
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();
}

Re: Despeckle

Posted: 2008-10-22T21:08:33-07:00
by fmw42
I had assumed that MagickDespeckleImage would remove "pepper" from an image but that doesn't appear to be the case (I'm using IM 6.4.4-5). What does it actually do?
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
Pete,

As I don't use your API, only the command line, I cannot generate your example. Can you post an example of your resulting image? How isolated is the noise?

Have you tried just using -median?

You might also want to look at my scripts, isonoise and statsfilt, and perhaps try to convert them to your API code, if they work well on your image.

Fred

Re: Despeckle

Posted: 2008-10-23T09:10:17-07:00
by el_supremo
Have you tried just using -median?
Thanks, Fred. That works a lot better. I'm also trying out the technique in your isofilter which may be the best option since it has a greater effect on the "pepper" than anything else in the image which is what I was looking for.

Pete