예제 #1
0
        public List <PixInfor> getNoiseInfor(WriteableBitmap b, float driftPercent)//得到符合标准,也就是超过阀值的噪点的数量
        //阀值是一个浮点数,实际是rgb偏移的允许比例
        //bm是单一色块,driftPercent是阀值
        {
            List <PixInfor> pl   = new List <PixInfor>();
            Color           AveC = this.getAverageColor(b);

            var components = b.PixelBuffer.ToArray();

            for (int i = 0; i < b.PixelHeight; i++)
            {
                for (int j = 0; j < b.PixelWidth; j++)
                {
                    var   index = i * b.PixelWidth * 4 + (j * 4);
                    Color c     = new Color();
                    c.B = components[index];
                    c.G = components[index + 1];
                    c.R = components[index + 2];
                    if (IsNoise(c, AveC, driftPercent))//偏离平均值过大被认为是噪点
                    {
                        PixInfor pi = new PixInfor();
                        pi.colorValue = c;
                        pi.XPosition  = j;
                        pi.YPosition  = i;
                        pl.Add(pi);
                    }
                }
            }

            return(pl);
        }
예제 #2
0
        public List <PixInfor> getEqualPix(WriteableBitmap SourceBitmap, WriteableBitmap TargetBitmap)
        {
            if (SourceBitmap.PixelHeight != TargetBitmap.PixelHeight)
            {
                return(null);
            }

            if (SourceBitmap.PixelWidth != TargetBitmap.PixelWidth)
            {
                return(null);
            }
            List <PixInfor> pl = new List <PixInfor>();

            for (int i = 0; i < SourceBitmap.PixelHeight; i++)
            {
                for (int j = 0; j < SourceBitmap.PixelWidth; j++)
                {
                    if (IsEpualPix(SourceBitmap, TargetBitmap, j, i))
                    {
                        PixInfor pi = new PixInfor();
                        pi.colorValue = GetPixel(SourceBitmap, j, i);
                        pi.XPosition  = i % SourceBitmap.PixelWidth;
                        pi.YPosition  = i / SourceBitmap.PixelWidth;
                        pi.PhotoH     = SourceBitmap.PixelHeight;
                        pi.PhotoW     = SourceBitmap.PixelWidth;
                        pl.Add(pi);
                    }
                }
            }
            SourceBitmap = null;
            TargetBitmap = null;
            return(pl);
        }
예제 #3
0
 public bool IsSame(PixInfor a, PixInfor b, int ph, int bh)
 {
     if ((Math.Abs(a.XPosition - b.XPosition) < ph) && (Math.Abs(a.YPosition - b.YPosition) < ph))
     {
         if ((Math.Abs(a.colorValue.R - b.colorValue.R) < bh) && (Math.Abs(a.colorValue.G - b.colorValue.G) < bh) && (Math.Abs(a.colorValue.B - b.colorValue.B) < bh))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
        public bool IsBadPix(WriteableBitmap b, PixInfor p, int minStep, int maxStep, double h)//默认min是1,max是4,h是阀值
        {
            WriteableBitmap minB = getImageArea(b, p.XPosition - minStep, p.YPosition - minStep, minStep * 2 + 1, minStep * 2 + 1);
            WriteableBitmap maxB = getImageArea(b, p.XPosition - maxStep, p.YPosition - maxStep, maxStep * 2 + 1, maxStep * 2 + 1);
            double          minL = getAverageColorL(minB);
            double          maxL = getAverageColorL(maxB);

            if (Math.Abs(minL - maxL) >= h)
            {
                return(true);
            }
            return(false);
        }
예제 #5
0
        bool IsEpualPix(WriteableBitmap b, PixInfor pi)//判断一个图像和特定的PixInfor是否一致
        {
            List <int> il = getStepIndex(b.PixelWidth, b.PixelHeight, pi.XPosition, pi.YPosition);

            foreach (int i in il)
            {
                if (IsEpualPix(b, pi))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #6
0
        public bool IsSameBright(PixInfor pi, WriteableBitmap b, int h)//判断在某个阀值下该点的亮度是否和图片对应位置的点的亮度一致
        {
            byte[] components = new byte[4];
            components = BitConverter.GetBytes(b.PixelBuffer.ToArray()[pi.XPosition + pi.YPosition * b.PixelWidth]);
            Color c = new Color();

            c.B = components[0];
            c.G = components[1];
            c.R = components[2];
            if ((Math.Abs(pi.colorValue.R - c.R) < h) && (Math.Abs(pi.colorValue.G - c.G) < h) && (Math.Abs(pi.colorValue.B - c.B) < h))
            {
                return(true);
            }
            return(false);
        }
예제 #7
0
        bool IsEpualPix(WriteableBitmap photo, int X, int Y, PixInfor pi) //判断一个像素整型是否和特定的PixInfor一致
        {                                                                 //RGB任何的分量小于阀值都算是相等
            Color c = GetPixel(photo, X, Y);

            if (Math.Abs(c.R - pi.colorValue.R) < h)
            {
                return(true);
            }
            if (Math.Abs(c.G - pi.colorValue.G) < h)
            {
                return(true);
            }
            if (Math.Abs(c.B - pi.colorValue.B) < h)
            {
                return(true);
            }
            return(false);
        }
예제 #8
0
        public List <PixInfor> getGBExceptionPix(WriteableBitmap b, double h)//依据国标获得异常点
        {
            List <double> dl = getImageLList(b);
            double        d  = 0;

            foreach (double x in dl)
            {
                d = d + x;
            }
            d = d / dl.Count;
            List <PixInfor> pl = new List <PixInfor>();

            for (int i = 0; i < dl.Count; i++)
            {
                if (Math.Abs(dl[i] - d) >= h)
                {
                    PixInfor p = new PixInfor();
                    p.YPosition  = i / b.PixelWidth;
                    p.XPosition  = i % b.PixelWidth;
                    p.colorValue = GetPixel(b, p.XPosition, p.YPosition);
                }
            }
            return(pl);
        }