Google Answers Logo
View Question
 
Q: C language or matlab code for filtering in digital image processing ( Answered,   0 Comments )
Question  
Subject: C language or matlab code for filtering in digital image processing
Category: Computers > Algorithms
Asked by: deepac-ga
List Price: $10.00
Posted: 21 Nov 2002 11:27 PST
Expires: 21 Dec 2002 11:27 PST
Question ID: 112068
A Matlab or C language code for loading an image, then adding any type
of noise to it, then seperate the noise once by using the median
filter and once by using the neighbourhood averaging filter.
Answer  
Subject: Re: C language or matlab code for filtering in digital image processing
Answered By: maniac-ga on 21 Nov 2002 16:23 PST
 
Hello Deepac,

There are a number of image processing tools with source code
available on line. Perhaps the most comprehensive is ImageMagick
described at
  http://www.imagemagick.org/

Some of its features includes:
 o It is supported on a variety of operating systems (Unix, Windows,
MacOS, VMS, OS2)
 o It has command line utilities to perform many operations (including
the ones you have described)
 o It has function libraries that can be called from C, C++, Perl,
Python, and Java
 o Source code is freely available
 o Has extensive documentation and mailing lists to provide help using
the functions and applications.

For example, a sample C++ application is shown at
  http://www.imagemagick.org/www/Magick++/Image.html
which reads a TIFF image, adds noise, and writes the TIFF image
[basically, the first and second steps you describe above]
and does this in five lines of code (look about 1/4 of the way down
the page).

The function for median filter is described on the same page - search
for medianFilter.

I can't tell for sure which neighborhood algorithm you want to use.
The choices are:
 o Floyd/Steinberg error diffusion - search for quantize Dither
 o Gaussian Blur - search for gaussianBlur
The command line utilities described at
  http://www.imagemagick.org/www/ImageMagick.html#details-noise
also describes a method where a noisy pixel is replaced by one of its
neighbors, but I can't seem to find the function interface for that
particular operation. It may be "enhanceImage" or "reduceNoiseImage",
but I can't be sure. Be sure to ask in a clarification request if one
of these does not meet your needs.

Some suggestions on further searches, use phrases such as
  source code image filtering neighborhood averaging
The third link was a site at
  http://www.cs.cmu.edu/~cil/v-source.html
titled "Computer Vision Source Code" which has direct links to a
number of resources - ImageMagick was one of them.

  --Maniac

Request for Answer Clarification by deepac-ga on 21 Nov 2002 17:58 PST
Hi! Maniac,
  thanx for showing ur concern in my problem. the C program sent by u
for loading image and adding noise is perfect. But unfortunately, i'm
not being able to get a source code for using median filter as well as
neighbourhood averaging filter to filter back the added noise. Could u
pls take the pains of finding out the code for the above two
operations(in C or matlab).I'll really appreciate it. As far as ur
query regarding the type of neighbourhood averaging filter is
concerned, u pls let me have a code of any type. Actually it doesn't
make a big difference for me. my project uses this problem as a small
part of the entire process. So what matters for me is the source code
in c or matlab for median filtering and any type of neighbourhood
averagin filtering to filter the noise from original image.
  hoping for a quick n positive reply
--deepac

Request for Answer Clarification by deepac-ga on 22 Nov 2002 21:37 PST
Hi! Maniac, 
       This is the second time I'm asking for clarification of my
answer.i'm
not being able to get a source code for using median filter as well as
neighbourhood averaging filter to filter back the added noise.Could u
pls take the pains of finding out the code for the above two
operations(in C or matlab).I'll really appreciate it. As far as ur
query regarding the type of neighbourhood averaging filter is
concerned, u pls let me have a code of any type.what matters for me is
the source code in c or matlab for median filtering and any type of
neighbourhood averaging filtering to filter the noise from original
image.
  hoping for a quick n positive reply 
--deepac

Clarification of Answer by maniac-ga on 23 Nov 2002 19:00 PST
Hello Deepac,

At the ImageMagick site
  http://www.imagemagick.org/www/archives.html
there is a list of sites that have the source code and binaries for
the applications and libraries. For example, choosing
  ftp://ftp.yggdrasil.com/mirrors/site/ftp.simplesystems.org/pub/ImageMagick/
or
  ftp://ftp.simplesystems.org/pub/ImageMagick/
from the list on the first page gives you a list of files.

Downloading the source should take between 10 and 15 minutes on a 56 K
modem line (one of the first few files listed). The references below
are for version 5.4.9-1. All are c source files.

Searching the files downloaded for the phrase "neighbor" and "median",
you can determine that the algorithms are implemented in the following
files / line numbers.

Neighborhood averaging
  magick/effect.c:142 (comments - BlurImage - gaussian)
  magick/effect.c:331 (BlurImage function)
  magick/effect.c:1493 (comments - ReduceNoiseImage)
  magick/effect.c:1575 (ReduceNoiseImage function)

Median Averaging
  magick/effect.c:975 (comments)
  magick/effect.c:1207 (MedianFilterImage function)
there are some supporting routines in this area as well

I looked at the description for Floyd/Steinberg further and it does
not appear to be what you need. If you want to look more at it, it is
hard to trace, but it appears that DitherImage is what implements it.
Good luck on your work.
  --Maniac

Request for Answer Clarification by deepac-ga on 01 Dec 2002 12:19 PST
Hi! maniac,
   this is in continuation to ur earlier search results for the matlab
or C code for my problem. I'm sorry to trouble u once more but acually
those search sites r not giving me a ready made matlab code(or a C
program) which i could directly compile n run to see the results. If u
remember, u sent me a c code in the very first reply  which was for
loading an image and adding noise to it. That is the kind of results
i'm looking for my problem. A straight forward C or matlab code which
could load an image , add noise(of any type) to it,ilter that noise by
once using median filter n oonce using neighbourhood averaging filter.
i know i'm troubling u too much but pls help me out as i've nowhere
else to go. I'm supposed to give this problem by tuesday..pls try to
search for the above code rather than the links where i could download
some such things which will not serve my pupose.
  hope to have a positive n prompt reply.
--deepac

Clarification of Answer by maniac-ga on 01 Dec 2002 20:15 PST
Hello Deepac,

Assuming you downloaded ImageMagick source as described previously and
are have a directory with the source. [steps for a Unix system]

At the top directory, generate and install ImageMagick
  ./configure
  make
  (as root)
  make install
[If you don't have root access, check the documentation to change the
default install location and adjust your commands as approprite;
installation could be skipped if it is already installed on your
system.]
  make check
(check the installation and generate the rwfile program used later)

In the tests directory, create a file named my.cpp with the following
contents:

#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;

int main (int argc, char **argv) {

  Image image;
  image.read("logo.gif");
  image.addNoise(GaussianNoise);
  image.write("logo-noise.gif");
  image.medianFilter(1.0); // filter w/ radius one
  image.write("logo-median.gif");
  image.read("logo-noise.gif");
  image.reduceNoise();
  image.write("logo-nonoise.gif");
  return 0;
}

Then
  ./rwfile LOGO: logo.gif
(to generate the input file)
  c++ -o my my.cpp `/usr/local/bin/Magic++-config  --cxxflags
--cppflags --ldflags --libs`
(to generate the my application; all on one line, note the direction
of the ` used to get the output of Magic++-config used as command line
parameters)

  ./my
(read logo.gif and generate the output files)

Review the files logo.gif, logo-noise.gif, logo-median.gif (median
filter), and logo-nonoise.gif (after noise removal - neighborhood
replacement) with an image viewing program to see the effects. The
gaussian noise added was a little subtle - you may want to repeat that
step more than one time to get the image "noisy".

Good luck.
  --Maniac
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy