Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dim myBitmap1 As Bitmap = PictureBox1.Image
Dim myBitmap2 As New Bitmap(myBitmap1.Width, myBitmap1.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
For ii = 1 To PictureBox1.Width - 2
For jj = 1 To PictureBox1.Height - 2
Dim Win = 0
Dim Mean = 0
For X = ii - 1 To (ii + 1)
For Y = jj - 1 To (jj + 1)
Win = Win + (System.Drawing.ColorTranslator.ToWin32(myBitmap1.GetPixel(X, Y)))
Next Y
Next X
Mean = (Win \ 11)
Dim r = Mean Mod 256
Dim g = ((Mean And &HFF00FF00) / 256&)
Dim b = ((Mean And &HFF0000) / 65536)
myBitmap2.SetPixel(ii, jj, Color.FromArgb(r, g, b))
PictureBox2.Image = myBitmap2
Next jj
Next ii
TextBox1.Visible = True
TextBox1.Text = "Mean Filter"

What I have tried:

I don't know where is the problem?? i need a help ??????????
Posted
Updated 14-Apr-16 3:00am

Hi,

What is it about the image result that is "not good"?

If it is blurry, this could be normal for a mean filter, you could use a median filter instead.
If some colours seem odd, it could be the type of noise in the image and how you split and recombine.

Cheers,

Jon
 
Share this answer
 
Comments
Huda .M 13-Apr-16 13:00pm    
thanks for answer,,sorry my English is not good,,
the result image is not blur,,i know that is result of mean filter ,,but the image is destroyed or not understand..i con't attachment image here .
I suspect the problem lies with averaging the RGB value when you should be averaging the components individually.

For instance, take two colours, a full on Green (00FF00) and a darker green (008D00). The average you are looking for is something like (00C900) with the green component half way in between the two cells. But your algorithm might give (00C680) which is the numerical average and includes a bit of green and a lot of blue (I think) as the division overflows shift half a shade of green into a lot of blue. The mixing of colours becomes worse as you average over more cells.

Also divide by 9 not 11?

Jon
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900