How to remove noise in the image?

Hi,

  I want  to reduce noise in the image. I tried by using  some of image smoothing techniques like median,gaussian. when I apply these filters noise is reducing But  quality of the image is going. How can I reduce noise, without loosing quality.

inampudi1Asked:
Who is Participating?
 
BdLmConnect With a Mentor Commented:
will you use a pascal solution ? code is not error free, we must debug first ...

{***********************************
 *  copy the image data to a Array of integer
 *
 ***********************************}
 
procedure ScanRasterValues (aBmp : TBitmap; xstart, ystart, xsteps, ysteps : Integer; var RvalueArray, GValueArray, BValueArray : TImageFilter);
var   ByteLine  : Pbytearray;
      i, j      : integer;
begin
 
 
 
   for j := ystart to ystart + ysteps  do
         begin
 
         ByteLine := aBmp.ScanLine[j];
 
         for  i:= xstart to xstart + xsteps  do
 
                begin
 
                   BvalueArray [i-xstart, j-ystart] := ByteLine[3*i];
                   GvalueArray [i-xstart, j-ystart] := ByteLine[3*i +1];
                   RvalueArray [i-xstart, j-ystart] := ByteLine[3*i +2];
 
 
                end;
 
         end;
 
end;
 
 
 
function FilterResult (aFilter, bFilter : TImageFilter) : word;
var  i,j   :  Integer;
     n,m     :  Integer;
 
begin
     n := length( aFilter );
     m:= n;
 
 
     for i := 1 to n do
       for j := 1 to m do
          result := aFilter[i][j] * bfilter[i,j];
end;
 
{******************************************************************************
 *      Input:
 *          bmp1, bm2 : TBitMap
 *          ImageFilter  : Image Filter array , size   FilterSize x  FilterSize
 *          assume filter size is always even !!  1,3,5, ...
 *
 *    OutPut:
 *
 *
 *
 *******************************************************************************}
 
procedure ReduceNoise_AnyFilter (bmp1, bmp2 : TBitMap; aImageFilter : TImageFilter );
 
var  P1                 :    pbytearray;  //  from Image 1
     FilterSize         :    Integer;     //  3,5,7
     FilterSize2        :    Integer;     //  2,3,4
     i,j,jj             :    Integer;
     RvalueArray        :    TImageFilter;    // Red Color Values
     GvalueArray        :    TImageFilter;    // Green Color Values
     BvalueArray        :    TImageFilter;    // Blue Color Values
 
begin
     //  the filter size
     FilterSize := length(aImageFilter);
 
     FilterSize2 := round((FilterSize-1)/2 +1);
 
      //  adjust dyn. arrays
 
     setlength ( RvalueArray, Filtersize, Filtersize );
 
     setlength ( GvalueArray, Filtersize, Filtersize );
 
     setlength ( BvalueArray, Filtersize, Filtersize );
 
 
     //  Loop through all Pixels
     for j := FilterSize2 to bmp1.Height - (FilterSize2 +1) do
         begin
 
             p1 := bmp1.ScanLine[j];
 
 
             for i := FilterSize2 to bmp1.Width - (FilterSize2+1)  do
 
               begin
 
                ScanRasterValues (bmp2, i-FilterSize2, j-FilterSize2, FilterSize, FilterSize,RvalueArray, GValueArray, BValueArray );
 
 
 
                p1[3 * i ]     :=  FilterResult ( aImageFilter,BvalueArray ) ;     //  Bvalue
                p1[3 * i + 1 ] :=  FilterResult ( aImageFilter,GvalueArray ) ;     //  Gvalue
                p1[3 * i + 2 ] :=  FilterResult ( aImageFilter,RvalueArray ) ;     //  Rvalue
 
 
               end; // i := ...
 
 
 
 
         end;  //  j:= ..
end;

Open in new window

0
 
dbruntonCommented:
Expect to lose quality when you alter an image.

Try using your filters with very mild settings and see what they do.  The milder the better.  The more aggressive or high the settings are the more you will lose in an image.  If it's in a particular error you may be able to cut the affected area out and apply the filters there and then paste the result back.

One other possible trick is to apply the filter and then sharpen straight away.  This may or may not work and depends on your image.
0
 
inampudi1Author Commented:
Hi dbrunton,

 Thank u for reply. I will try for sharpening after smothing.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
HypoCommented:
Hi, I'm not sure if this algorithm would produce any good results, but I think it could at least do some difference to just aplying a gauss filter, and I would give it a try myself:

1: Extract all the borders in the image by using vertical- and horizontal- derivative filters, store the results in a temporary image map.

2: Apply a gaussian filter to the original image, but for each pixel, you create a new gaussian filter that is more or less sharpen, depending on the corresponding value in your temporary image map.

The theory behind it is that you recognize the resolution of an image by the sharpness of the edges in the image; e.g. if you blur an edge, then you would feel that that the image looses quality, but if you blur an area with no edges, then it wouldn't affect your experience of the image as much. So what you do is that you extract all the edges of the image, and then, the more a pixel is not considered to be part of an edge, the more you blur it, and vice versa.

I haven't tested it myself yet, but I think that with some tweaking, this algorithm would result in the filters smothening areas in the image (removing noise), but not smoothing the edges of the image (not loose as much quality).

regards
Hypo
0
 
BdLmCommented:
can you post sample images for testing ?
0
 
inampudi1Author Commented:
Hi,

   Please see the test image.


leena.bmp
0
 
dbruntonCommented:
Median filter works OK in Irfanview and PaintShop Pro.  But can't be aggressive.

So if this programming you are going to have to be very mild with the filter there.
0
 
inampudi1Author Commented:
Hi dbrunton,

   I am working on VC++, I used median filter but after sharpening image also quality is missing. Please see the software in the link,

http://www.neatimage.com/download.html

  Quality is coming very fine. He is using luminance and crominance channel. please tell me how to to get like this quality.
0
 
BdLmCommented:
uses the test image with an 5x5 median filter only 1 time execution

lenoise-image-meadian-file.bmp
0
 
HypoCommented:
I had to try out the idea of removing noise using information about the edges in an image, and I think it looks ok... the algorithm works as I described above; and this is the results I got after some parameter tweaking...

regards
Hypo
RemoveNoiseFilter.PNG
0
 
dbruntonCommented:
Try sharpening your Normal Gaussian blur.  Might give slightly better.



And try a 3 x 3 median filter instead of the 5 x 5.
0
 
inampudi1Author Commented:
Hi,

Please can u give me c++ or delphi code for MEDIAN filter.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.