Despeckle

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Despeckle

Post 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();
}
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Despeckle

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Despeckle

Post 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
Post Reply