Merci pour ta réponse,
j'ai compris cette explication mais quelle est sa relation avec le filtre moyenne!!
voila tout le code du filtre, je n'en ai rien compris.
pouvez vous m'expliquer svp !!
private void moyenneFilter(int filterWidth, int filterHeight)
{
// Create new array
int width = bit.getWidth();
int height = bit.getHeight();
int[] pixNew = new int[width * height];
int[] pixOld = new int[width * height];
bit.getPixels(pixNew, 0, width, 0, 0, width, height);
bit.getPixels(pixOld, 0, width, 0, 0, width, height);
// Apply pixel-by-pixel change
int filterHalfWidth = filterWidth/2;
int filterHalfHeight = filterHeight/2;
int filterArea = filterWidth * filterHeight;
for (int y = filterHalfHeight; y < height-filterHalfHeight; y++)
{
for (int x = filterHalfWidth; x < width-filterHalfWidth; x++)
{
// Accumulate values in neighborhood
int accumR 0, accumG 0, accumB = 0;
for (int dy = -filterHalfHeight; dy <= filterHalfHeight; dy++)
{
for (int dx = -filterHalfWidth; dx <= filterHalfWidth; dx++)
{
int index = (y+dy)*width + (x+dx);
accumR += (pixOld[index] >> 16) & 0xff;
accumG += (pixOld[index] >> 8) & 0xff;
accumB += pixOld[index] & 0xff;
} // dx
} // dy
// Normalize
accumR /= filterArea;
accumG /= filterArea;
accumB /= filterArea;
int index = y*width + x;
pixNew[index] = 0xff000000 | (accumR << 16) | (accumG << 8) | accumB;
} // x
} // y
// Change bitmap to use new array
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
bitmap.setPixels(pixNew, 0, width, 0, 0, width, height);
bit = null;
bit = bitmap;
pixOld = null;
pixNew = null;
}
}