public void Gabor(System.Drawing.Bitmap srcImage, GaborParam gaborParam) { Byte[] rgbBytes = LockBits(srcImage, System.Drawing.Imaging.ImageLockMode.ReadWrite); Int32 singleWidth = RealWidth / 3; Int32 length = singleWidth * Height; Byte[] tempb = new Byte[length]; for (int i = 0; i < Height; i++) { for (int j = 0; j < singleWidth; j++) { tempb[i * singleWidth + j] = rgbBytes[i * Width + j * 3]; } } Byte[] resub; base.gabor(ref tempb, singleWidth, Height, gaborParam, out resub); for (int i = 0; i < Height; i++) { for (int j = 0; j < singleWidth; j++) { rgbBytes[i * Width + j * 3] = resub[i * singleWidth + j]; rgbBytes[i * Width + j * 3 + 1] = resub[i * singleWidth + j]; rgbBytes[i * Width + j * 3 + 2] = resub[i * singleWidth + j]; } } UnlockBits(rgbBytes); }
private void BtnGabor_Click(object sender, EventArgs e) { var srcImage = (Bitmap)this.PicShow.Image; GaborParam parma = new GaborParam { Gamma = 0.5, Theta = 0.5, Lambda = 0.5, Sigma = 0.5, Psi = 0.5 }; ((IFrequency)valueImage).Gabor(srcImage, parma); this.PicShow.Refresh(); }
/// <summary> /// 盖博滤波 /// </summary> /// <param name="data">二维数据</param> /// <param name="width">数据宽度</param> /// <param name="height">数据高度</param> /// <param name="gaborParam">盖博参数</param> /// <param name="result">返回的结果</param> protected void gabor(ref Byte[] data, Int32 width, Int32 height, GaborParam gaborParam, out Byte[] result) { result = new Byte[data.Length]; Double temp; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Int32 index = j * width + i; temp = data[index] * valueMath.Gabor(i, j, gaborParam).Real; temp = temp > 255 ? 255 : temp < 0 ? 0 : temp; result[index] = (Byte)temp; } } }