I would assume you want to apply a convolution filter.
To start with you probably want to use a Bitmap Rather than an image, i.e. new Bitmap(Path).
The trivial method would be to loop over each pixel, and then loop over each value in the filter and multiply/accumulate with the corresponding pixel values. Using GetPixel to get the pixel values. Note that you need to handle the borders of the image somehow, for example by skipping them. GetPixel is notoriously slow, but I would recommend using it to ensure you have the code nailed down before optimizing.
Something like this (Untested):
var bmp = new Bitmap(@"test.bmp");
var filter = new float[3, 3];
var result = new Bitmap(bmp.Width - 2, bmp.Height - 2);
for(int y = 1; y < bmp.Height-1; y++)
{
for (int x = 1; x < bmp.Width - 1; x++)
{
float r = 0;
r += bmp.GetPixel(x-1, y-1).R * filter[0, 0];
r += bmp.GetPixel(x , y-1).R * filter[1, 0];
r += bmp.GetPixel(x+1, y-1).R * filter[2, 0];
r += bmp.GetPixel(x-1, y ).R * filter[0, 1];
r += bmp.GetPixel(x , y ).R * filter[1, 1];
r += bmp.GetPixel(x+1, y ).R * filter[2, 1];
r += bmp.GetPixel(x-1, y+1).R * filter[0, 2];
r += bmp.GetPixel(x , y+1).R * filter[1, 2];
r += bmp.GetPixel(x+1, y+1).R * filter[2, 2];
// Repeat for G & B channels
result.SetPixel(x-1, y-1, Color.FromArgb((int)r, 0, 0));
}
}
A more comprehensive guide can be found here.
index = ( x * width + y ) * colorsize. I hope I've not made a mistake, it's a long time I coded such thing... ButBitmaphas the methodGetPixel(). What do you call "3x3 of the image" ?Bitmapand the method.GetPixel(), how can I get those 3x3 for my process??Image.Save, you are saving the file representation of the image to your memory stream. This is not going to be a byte array representing pixel data, but the.jpgfile contents, including the headers and the results of the JPEG compression algorithm. Unless you are intimately familiar with how JPEG compression works, the contents of the byte array will be unusable for image processing.