C#:LBP特征图像(VS2010窗体+代码)

        private Bitmap xjGetLBP(Bitmap BitmapOld)
        {
            //原始LBP
            int xjWidth = BitmapOld.Width;//宽度
            int xjHeight = BitmapOld.Height;//高度
            Bitmap xjBitmapLBP = new Bitmap(xjWidth, xjHeight);
            for (int width = 0; width < xjWidth; width++)
            {
                for (int height = 0; height < xjHeight; height++)
                {
                    //中心像素
                    Color xjCenterColor = BitmapOld.GetPixel(width, height);
                    byte xjCRed = xjCenterColor.R;
                    byte xjCGreen = xjCenterColor.G;
                    byte xjCBlue = xjCenterColor.B;
                    int xjCenterValue = (xjCRed * 38 + xjCGreen * 75 + xjCBlue * 15) >> 7;

                    //8邻域
                    string xjFieldValue = string.Empty;
                    for (int w = width - 1; w <= width + 1; w++)
                    {
                        for (int h = height - 1; h <= height + 1; h++)
                        {
                            if ((w == width) && (h == height))
                            {
                                continue;
                            }

                            int xjValue = -1;
                            if ((w < 0) || (w >= xjWidth) || (h < 0) || (h >= xjHeight))
                            {
                                xjValue = xjCenterValue;
                            }
                            else
                            {
                                Color xjFieldColor = BitmapOld.GetPixel(w, h);
                                byte xjRed = xjFieldColor.R;
                                byte xjGreen = xjFieldColor.G;
                                byte xjBlue = xjFieldColor.B;
                                xjValue = (xjRed * 38 + xjGreen * 75 + xjBlue * 15) >> 7;
                            }

                            //关键:大小判断,略有改变(小于中心像素值为0,大于等于中心像素值为1)
                            if (xjValue < xjCenterValue)
                            {
                                xjFieldValue += "0";
                            }
                            else
                            {
                                xjFieldValue += "1";
                            }
                        }
                    }

                    //LBP二进制
                    string xjLBPBinary = xjGetLBPBinary(xjFieldValue);
                    //原始LBP值(十进制)
                    int xjLbpValue = Convert.ToInt32(xjLBPBinary, 2);

                    //赋值
                    xjBitmapLBP.SetPixel(width, height, Color.FromArgb(xjLbpValue, xjLbpValue, xjLbpValue));
                }
            }
            return xjBitmapLBP;
        }



        //邻域值转为LBP二进制。全图顺序一致即可。
        private string xjGetLBPBinary(string FieldValue)
        {
            string xjOrderValue = string.Empty;
            xjOrderValue += FieldValue.Substring(0, 3);
            xjOrderValue += FieldValue.Substring(4, 1);
            xjOrderValue += FieldValue.Substring(7, 1);
            xjOrderValue += FieldValue.Substring(6, 1);
            xjOrderValue += FieldValue.Substring(5, 1);
            xjOrderValue += FieldValue.Substring(3, 1);
            return xjOrderValue;
        }

C#:LBP特征图像(VS2010窗体+代码)

VS2010具体窗体+代码见:点击打开链接

相关文章:

  • 2021-10-10
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-04-21
  • 2021-07-01
  • 2022-01-14
  • 2021-07-28
  • 2021-08-17
  • 2021-06-19
相关资源
相似解决方案