public void Initialize(FastBitmap img) { _r = new Random(); img.LockBits(); _height = img.Height; _width = img.Width; int capacity = _width * _height; _pixels = new Pixel[capacity]; int n = 0; for (int j = 0; j < _height; j++) { for (int i = 0 ; i < _width; i++) { List<byte> samples = new List<byte>(); samples.Add(img[i,j]); byte[] randomPixels = GetRandomGreyPixels(img, i, j); samples.AddRange(randomPixels); _pixels[n] = new Pixel(samples.ToArray()); n++; } } img.UnlockBits(); }
public byte[] GetMask(FastBitmap img) { byte[] mask = new byte[_height * _width]; int n = 0; for (int j = 0; j < _height; j++) { for (int i = 0; i < _width; i++) { byte pixel_data = img[i,j]; if (Compare(pixel_data, _pixels[n]) == 1) { mask[n] = BackgroundByte; UpdateModel(pixel_data, i,j); } else { mask[n] = pixel_data; } n++; } } return mask; }
private byte[] GetRandomGreyPixels(FastBitmap img, int x, int y) { byte[] result = new byte[NumberOfSamples - 1]; for (int i = 0; i < NumberOfSamples - 1; i++ ) { GetCoordinate(ref x, ref y); result[i] = img[x, y]; } return result; }