1
Reply

Linear best fit

siphu07

siphu07

Nov 17 2004 10:26 AM
1.9k
public class LinearBestFitAdjust : ImageFilter { public LinearBestFitAdjust(int width, int height) : base(width, height) {} public LinearBestFitAdjust(int width, int height, int[][] Mask) : base(width, height, Mask) {} public override void Apply(Bitmap img) { float[] ra = new float[w]; float[] rb = new float[w]; float[] ca = new float[h]; float[] cb = new float[h]; float sx, sy, sxy, sxx; int n; float p; // for rows : for(int l = 0; l < w; l++) { n=0; sx = 0; sy = 0; sxy = 0; sxx = 0; for(int c = 0; c < h; c++) { if (mask[l][c] == 1) { sx += c; sxx += c * c; p = img.GetPixel(l,c).R; sy += p; sxy += p*c; n++; } } ra[l] = (n*sxy - sx*sy)/(n*sxx - sx*sx); rb[l] = sy/n - ra[l] * sx/n; } //for columns for(int c = 0; c < h; c++) { n = 0; sx = 0; sy = 0; sxy = 0; sxx = 0; for(int l = 0; l < w; l++) { if (mask[l][c] == 1) { sx += l; sxx += l * l; p = ra[l] * c + rb[l]; // c ou l ? sy += p; sxy += p*l; n++; } } ca[c] = (n*sxy - sx*sy)/(n*sxx - sx*sx); cb[c] = sy/n - ca[c] * sx/n; } // apply on img : -- Douteux int g; for(int l = 0; l < w; l++) for(int c = 0; c < h; c++) { g = img.GetPixel(l,c).R; g = g - (int)(ca[c] * l + cb[c])+128; //g = (int)(ra[l] * c + rb[l]); if (g < 0) g = 0; if (g > 255) g = 255; img.SetPixel(l,c,Color.FromArgb(g, g, g)); //img.SetPixel(l,c,Color.FromArgb(12,112,121)); } } } Somebody can tell me what does this LinearBestFitAdjust do?? This is one part of a image processing program give me some where that introduce about this algorithm?? Another question when i mark a class is [serializable] and use a BinaryFormater to save this object but it 's always arise an error, that the system.windows.form class does mark [serializable]????

Answers (1)