Ejemplo n.º 1
0
        /// <summary>
        /// Get the filter response images from exEl
        /// </summary>
        /// <param name="exEl"></param>
        /// <returns></returns>
        private Image GetData(ExchangeElement exEl, LBPFilter lbpFilter)
        {
            int nHeight = exEl.Height;
            int nWidth  = exEl.Width;

            int i;

            char[] charArr = new char[exEl.ByteData.GetLength(0)];
            for (i = 0; i < exEl.ByteData.GetLength(0); i++)
            {
                charArr[i] = Convert.ToChar(exEl.ByteData[i]);
            }

            Image dpuImgData = new Image(charArr, nWidth, nHeight);
            Image rstImgData = null;

            if ((_imgWidth != nWidth) || (_imgHeight != nHeight))
            {
                rstImgData = new Dpu.ImageProcessing.Image(_imgWidth, _imgHeight);
                Image.BilinearResample(dpuImgData, rstImgData);
            }
            else
            {
                rstImgData = dpuImgData;
            }

            dpuImgData = new Image(_imgWidth, _imgHeight);
            lbpFilter.FilterImage(rstImgData, dpuImgData);

            return(dpuImgData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the LBP distance
        /// </summary>
        /// <param name="frontUIData"></param>
        public void LBPDistance(DataExchange frontUIData)
        {
            ParseConfig(frontUIData);

            List <Image>    listFilteredImage = new List <Image>();
            int             nEl = frontUIData.ElementCount;
            ExchangeElement exEl = null;
            Image           filteredImage = null;
            LBPFilter       lbpFilter = new LBPFilter(1, 8, true, true);
            int             i, j;

            for (i = 0; i < nEl; i++)
            {
                exEl          = frontUIData.GetElement(i);
                filteredImage = GetData(exEl, lbpFilter);
                listFilteredImage.Add(filteredImage);
            }

            SparseFilterExample  example;
            LBPIntegralHistogrom lbpHist1 = new LBPIntegralHistogrom();
            LBPIntegralHistogrom lbpHist2 = new LBPIntegralHistogrom();

            StrongClassifier  strongClassifier   = LoadClassifier(_classifierFileName);
            RectangularFilter rectangularFilters = LoadFilterSet(_rectangularFileName);

            List <int> listRectangularIndices = GetFilterIndex(strongClassifier);

            float[]  score    = new float[2];
            double[] expScore = new double[2];

            double[,] distanceMatrix = new double[nEl, nEl];

            for (i = 0; i < nEl; i++)
            {
                lbpHist1.Create(listFilteredImage[i], lbpFilter.m_nFilterRange + 1);
                for (j = 0; j < i; j++)
                {
                    lbpHist2.Create(listFilteredImage[j], lbpFilter.m_nFilterRange + 1);
                    example = CreateFilterResponses(lbpHist1, lbpHist2,
                                                    rectangularFilters, listRectangularIndices);
                    score[0] = score[1] = 0;
                    score    = strongClassifier.Vote(example, score, _stage);

                    expScore[0]          = Math.Exp(Convert.ToDouble(score[0]));
                    expScore[1]          = Math.Exp(Convert.ToDouble(score[1]));
                    distanceMatrix[i, j] = expScore[0] / (expScore[0] + expScore[1]) + 0.05;
                    distanceMatrix[j, i] = distanceMatrix[i, j];
                }
            }
            frontUIData.DistanceMatrix = distanceMatrix;
        }