0
votes

I am very beginner in C# and I have an absurd method which is described below.

If I want to create a 3x3 window and find average value of these 9 pixels I follow that way:

IM[i - 1, j - 1]
IM[i - 1, j]
IM[i - 1, j + 1]
IM[i, j - 1]
IM[i, j + 1]
IM[i - 1, j - 1]
IM[i - 1, j]
IM[i - 1, j + 1]
IM[i, j]

If I want to create a 5x5 window and put it on each pixel to find average of these 25 pixel I follow that way:

IM[i - 2, j - 2]
IM[i - 1, j - 2]
IM[i, j - 2]
IM[i + 1, j - 2]
IM[i + 2, j - 2]
IM[i - 2, j - 1]
IM[i - 1, j - 1]
IM[i, j - 1]
IM[i + 1, j - 1]
IM[i + 2, j - 1]
IM[i - 2, j]
IM[i - 1, j]
IM[i, j]
IM[i + 1, j]
IM[i + 2, j]
IM[i - 2, j + 1]
IM[i - 1, j + 1]
IM[i, j + 1]
IM[i + 1, j + 1]
IM[i + 2, j + 1]
IM[i - 2, j + 2]
IM[i - 1, j + 2]
IM[i, j + 2]
IM[i + 1, j + 2]
IM[i + 2, j + 2]

If I want to create 7x7 or more window, it is too hard to write position of each pixel in the 7x7 window.

I want to create the dynamic window whose size is defined by user. How can I do that? Is there any way to do that?

1
If you really want to do image processing you do not work with windows but with Bitmaps. If you actually want to do calculations you should use Arrays. - Of course you can create both in (more or less) any size dynamically. You also should learn about the for loop.. - TaW

1 Answers

0
votes

You can extend this (by replacing 3 with the number you're interested in) for a box of any size.

for(int x=-3; x <= 3; x++)
{
    for (int y=-3; y <= 3; y++)
    {
        IM[i+ x, j + y] //theres your reference, if you're going to get the average you can add it to a sum or whatever
    }
}