Esempio n. 1
0
 /// <summary>
 /// 对点集进行排序
 /// </summary>
 /// <param name="workPointHist">工作样本点集</param>
 /// <param name="distingPointHist">对比样本点集</param>
 /// <param name="rect">搜索区域</param>
 /// <param name="whtPoint">输出根据区分度排好序的白点</param>
 /// <param name="blcPoint">输出根据区分度排好序的黑点</param>
 /// <returns></returns>
 private static void PointSort(short[][][] workPointHist, short[][][] distingPointHist, Rectangle rect, ref ArrayList whtPoint, ref ArrayList blcPoint)
 {
     for (int h = rect.Top + IntellPointConfig.SearchSize; h < rect.Bottom - IntellPointConfig.SearchSize; h++)
     {
         for (int w = rect.Left + IntellPointConfig.SearchSize; w < rect.Right - IntellPointConfig.SearchSize; w++)
         {
             PointDisc whtPointDisc = new PointDisc();
             PointDisc blcPointDisc = new PointDisc();
             GetDiscrimination(workPointHist[h][w], distingPointHist[h][w], ref whtPointDisc, ref blcPointDisc);
             whtPointDisc.x = blcPointDisc.x = (short)w;
             whtPointDisc.y = blcPointDisc.y = (short)h;
             whtPoint.Add(whtPointDisc);
             blcPoint.Add(blcPointDisc);
         }
     }
     RandomArrayList(ref whtPoint);
     RandomArrayList(ref blcPoint);
     whtPoint.Sort();
     blcPoint.Sort();
 }
Esempio n. 2
0
        /// <summary>
        /// 两个点之间可区分度的关键函数(算法性能主要改动这个函数)
        /// 本算法为类叶贝斯分类
        /// </summary>
        /// <param name="workhist">工作点的灰度分布情况</param>
        /// <param name="distinghist">区分点的灰度分布情况</param>
        /// <returns></returns>
        private static void GetDiscrimination(short[] workhist, short[] distinghist, ref PointDisc whtPointDisc, ref PointDisc blcPointDisc)
        {
            int whtDisc = 0; int blcDisc = 0;
            //统计
            int workCount = 0, distCount = 0;
            for (int i = 0; i < 256; i++ )
            {
                workCount += workhist[i];
                distCount += distinghist[i];
            }
            if (workCount <=0 || distCount <=0)
            {
                whtDisc = 0;
                blcDisc = 0;
                return;
            }

            short whtThr = 0;
            short blcThr = 255;
            GetThr(workhist, workCount, ref whtThr, ref blcThr);

            //计算distPoint的误判数
            int whtErrCount = 0;
            for (int i = whtThr; i >= 0; i-- )
            {
                whtErrCount += distinghist[i];
            }
            int blcErrCount = 0;
            for (int i = blcThr; i < 256; i++ )
            {
                blcErrCount += distinghist[i];
            }

            //计算distPoint和workPoint的灰度差异
            short up = 0; short down = 0;
            GetUpAndDown(distinghist, distCount, ref up, ref down);
            short whtGrayDiff = (short)(whtThr - up);
            short blcGrayDiff = (short)(down - blcThr);

            //distPoint的误判个数
            whtDisc = (int)((double)30000 * (whtErrCount) / (double)distCount);
            blcDisc = (int)((double)30000 * (blcErrCount) / (double)distCount);

            if (IntellPointSel.IntellPointConfig.ClassMode ==  ConfigClassMode.GrayDiff)
            {
                whtDisc = whtDisc * 256 + whtGrayDiff;
                blcDisc = blcDisc * 256 + blcGrayDiff;
            }

            whtPointDisc.g = whtThr;
            blcPointDisc.g = blcThr;
            whtPointDisc.disc = whtDisc;
            blcPointDisc.disc = blcDisc;
        }