The principle and realization of image filtering

Source: Internet
Author: User
Tags sort

1. Basic Principles

The image information is often disturbed by various noise sources in the process of acquisition, and these noises often appear as isolated pixels in the image, which can be understood as the spatial correlation of pixel grayscale, that is, the pixel gray level of noise point differs significantly from the grayscale of neighboring pixels . Usually, the general pre-image processing of the image spikes still with the subsequent unwanted entrainment of the pixel points, such interference or isolated pixels, such as not filtered, will be the future image region segmentation, analysis and judgement impact.

The noise-contaminated image can be processed by linear filtering, but many linear filters have low continuity, while the denoising also makes the edges blurred, and median filtering can be used to remove the noise and protect the edge of the image in some cases, he is a non-linear method of de-noising.

The principle of median filtering is to replace the value of a point in a digital image with the median value of an area of that point, as defined by the median value:

A group of numbers X1, X2, X3 ... Xn if the order is as follows:

X i 1≤x i 2≤x i 3≤ ... ≤x i N

Y=med{x1, X2, X3 ... Xn}=xi ((1+n)/2) n is an odd number

Xi (N/2) +xi ((1+n)/2) n is even

Y is called X1, X2, X3 ... The median value of Xn, if there is a sequence (10,20,30,40,50,60,70), the median value is 40.

The field of a particular length or shape of a point is called a window, in one dimension, the median filter is a sliding window of an odd pixel, and the value of the center of the window is replaced by the median value of each pixel within the window. Set the input to {XI,I∈I2}, the output of the filter is:

Yi=med{xi}=med{xi-u ... Xu ... Xi+u}

If you generalize to two-dimensional, you can define the output as:

Yi=med{xij}=med{x (I+s), (J+s) (r,s) ∈a, (i,j) ∈i2}

For the median filter of the two-dimensional filter, a 3x3 or 5x5 window is generally used for filtering.

2. Realize

Procedure Tform1.button2click (Sender:tobject);

Var

P1,p2,p3,p4:pbytearray;

RVALUEARRAY:ARRAY[0..10] of Integer;

I,j:integer;

Begin

Self. doublebuffered:=true;//with double buffering mode

Changedbmp:=tbitmap. Create;

Testbmp:=tbitmap. Create;

Changedbmp. Assign (Image1. picture);

Testbmp. Assign (Image1. picture);

For J:=1 to Changedbmp. Height-2 do

Begin

P1:=testbmp.    SCANLINE[J]; P2:=testbmp. SCANLINE[J-1];

P3:=changedbmp. SCANLINE[J]; P4:=changedbmp. SCANLINE[J-1];

For I:=1 to Changedbmp. Width-2 do

Begin

rvaluearray[0]:=p2[3* (i-1) +2];

RVALUEARRAY[1]:=P2[3*I+2];

rvaluearray[2]:=p2[3* (i+1) +2];

rvaluearray[3]:=p3[3* (i-1) +2];

RVALUEARRAY[4]:=P3[3*I+2];

rvaluearray[5]:=p3[3* (i+1) +2];

rvaluearray[6]:=p4[3* (i-1) +2];

RVALUEARRAY[7]:=P4[3*I+2];

rvaluearray[8]:=p4[3* (i+1) +2];

Sort (Rvaluearray);

P1[3*I+2]:=RVALUEARRAY[4];

rvaluearray[0]:=p2[3* (i-1) +1];

RVALUEARRAY[1]:=P2[3*I+1];

rvaluearray[2]:=p2[3* (i+1) +1];

rvaluearray[3]:=p3[3* (i-1) +1];

RVALUEARRAY[4]:=P3[3*I+1];

rvaluearray[5]:=p3[3* (i+1) +1];

rvaluearray[6]:=p4[3* (i-1) +1];

RVALUEARRAY[7]:=P4[3*I+1];

rvaluearray[8]:=p4[3* (i+1) +1];

Sort (Rvaluearray);

P1[3*I+1]:=RVALUEARRAY[4];

rvaluearray[0]:=p2[3* (i-1)];

Rvaluearray[1]:=p2[3*i];

rvaluearray[2]:=p2[3* (i+1)];

rvaluearray[3]:=p3[3* (i-1)];

Rvaluearray[4]:=p3[3*i];

rvaluearray[5]:=p3[3* (i+1)];

rvaluearray[6]:=p4[3* (i-1)];

Rvaluearray[7]:=p4[3*i];

rvaluearray[8]:=p4[3* (i+1)];

Sort (Rvaluearray);

P1[3*I]:=RVALUEARRAY[4];

End

End

Changedbmp.assign (testbmp);

Paintbox2.canvas.copymode:=srccopy; PaintBox2.Canvas.Draw (0,0,changedbmp);

End

3. Effect

Perhaps the image after the binary processing is not very obvious, but the color image filtering after the obvious feeling of the image is much clearer, the main reason is the filter after some noise elimination.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.