/// <summary>
        /// Project the list of image data in frontUIData into the embedding space
        /// </summary>
        /// <param name="frontUIData">Front Data Exchange</param>
        /// <returns></returns>
        private List <INumArray <double> > RankOneProjImgList(DataExchange frontUIData)
        {
            INumArray <double> l;
            INumArray <double> r;
            INumArray <double> data;
            INumArray <double> vecData;

            List <INumArray <double> > listImgVec = new List <INumArray <double> >();//list of projected image data

            int             nEl   = frontUIData.ElementCount;
            int             nProj = _leftMatrix.size1;
            ExchangeElement exEl;

            for (int i = 0; i < nEl; i++)
            {
                exEl = frontUIData.GetElement(i);
                data = GetData(exEl);

                vecData = ArrFactory.DoubleArray(nProj);
                for (int j = 0; j < nProj; j++)
                {
                    l          = (INumArray <double>)(_leftMatrix.GetCol(j));
                    r          = (INumArray <double>)(_rightMatrix.GetCol(j));
                    vecData[j] = (((INumArray <double>)(l.Transpose())).Mult(data).Mult(r))[0];
                }
                listImgVec.Add(vecData);
            }
            return(listImgVec);
        }
        /// <summary>
        /// Parse the configuration file
        /// </summary>
        /// <param name="frontUIData">front-backend data exchange</param>
        private void ParseConfig(DataExchange frontUIData)
        {
            string       configureFile = frontUIData.BackEndConfigFile;
            string       configureDir  = System.IO.Path.GetDirectoryName(configureFile);
            StreamReader ConfigReader  = new StreamReader(configureFile);
            string       strLine;

            string[] strArr;

            try
            {
                m_strLeftMatFileName  = _RootedPath(ConfigReader.ReadLine(), configureDir);
                m_strRightMatFileName = _RootedPath(ConfigReader.ReadLine(), configureDir);

                strLine         = ConfigReader.ReadLine();
                strArr          = strLine.Split(new char[] { ' ' });
                m_iReSizeHeight = Convert.ToInt32(strArr[0]);
                m_iReSizeWidth  = Convert.ToInt32(strArr[1]);

                strLine = ConfigReader.ReadLine();
                strArr  = strLine.Split(new char[] { ' ' });

                m_iLocalHeight = Convert.ToInt32(strArr[0]);
                m_iLocalWidth  = Convert.ToInt32(strArr[1]);

                if ((m_iLocalWidth == 0) || (m_iLocalHeight == 0))
                {
                    m_bGlocalTrans = false;
                }
                else
                {
                    m_bGlocalTrans = true;
                }

                ExchangeElement el = frontUIData.GetElement(0);

                if ((m_iReSizeHeight == (el.Height / 2)) && (m_iReSizeWidth == (el.Width / 2)))
                {
                    m_bDownSample = true;
                    m_bResize     = false;
                }
                else
                {
                    if ((m_iReSizeHeight == el.Height) && (m_iReSizeWidth == el.Width))
                    {
                        m_bDownSample = false;
                        m_bResize     = false;
                    }
                    else
                    {
                        m_bDownSample = false;
                        m_bResize     = true;
                    }
                }
            }
            catch
            {
                throw(new Exception("Exception: Configuration File Format Error"));
            }
        }
        /// <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;
        }
Example #4
0
        /// <summary>
        /// Read the status of each of the elements in frontUIData. An element can be
        /// in the mode of frozen, selected, or free
        /// </summary>
        /// <param name="frontUIData">DataExchange data structure</param>
        /// <param name="arrCoord">coordinate of elements</param>
        /// <param name="listFixedImg">list of indices of images with fixed position</param>
        /// <param name="nImgIndex">the selected image, if none, -1</param>
        private void ReadStatus(DataExchange frontUIData, out double[,] arrCoord,
                                out List <int> listFixedImg, out int nImgIndex)
        {
            int nEl  = frontUIData.ElementCount;
            int nDim = frontUIData.Coordinates.GetLength(1);

            ExchangeElement ele = null;

            arrCoord     = new double[nEl, nDim];
            listFixedImg = new List <int>();
            nImgIndex    = -1;

            Random randGen = new Random();
            int    i, j;
            double dCoordVal;

            for (i = 0; i < nEl; i++)
            {
                ele = frontUIData.GetElement(i);
                switch (ele.State)
                {
                case ExchangeElement.ElementState.Selected:
                    nImgIndex = i;
                    break;

                case ExchangeElement.ElementState.FrozenLocation:
                    listFixedImg.Add(i);
                    for (j = 0; j < nDim; j++)
                    {
                        dCoordVal      = frontUIData.Coordinates[i, j];
                        arrCoord[i, j] = dCoordVal + (randGen.NextDouble() / 100);
                    }
                    break;

                default:
                    for (j = 0; j < nDim; j++)
                    {
                        arrCoord[i, j] = frontUIData.Coordinates[i, j];
                    }
                    break;
                }
            }
        }