/// <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); }
private static ExchangeItem GetPlatformExchangeFromConfig(ExchangeElement configElement) { var item = new ExchangeItem() { Name = configElement.Name, PrefetchCount = configElement.PrefetchCount, Type = configElement.Type, Out = new List <OutMessage>(), In = new List <InMessage>() }; foreach (var outEl in configElement.Out.Cast <OutgoingElement>()) { var outItem = new OutMessage() { Key = outEl.Key, Name = outEl.Name, Persist = outEl.Persist, Timeout = outEl.Timeout }; item.Out.Add(outItem); } foreach (var inElement in configElement.In.Cast <IncomingElement>()) { var inItem = new InMessage() { Key = inElement.Key, Name = inElement.Name, Type = inElement.Type, React = inElement.React }; item.In.Add(inItem); } return(item); }
/// <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")); } }
private static void AddSenders(IAdvancedBus advancedBus, IExchange exchange, ExchangeElement exchangeItem, HashSet <IBusSender> set, ServiceBusSection configSection) { foreach (var outcome in exchangeItem.Out.Cast <OutgoingElement>()) { set.Add( new BusSender(EndpointInfoFactory.Create(advancedBus, exchange, outcome.Name, outcome.Key, outcome.Persist, outcome.Timeout)) { ExchangeType = exchangeItem.Type }); } }
/// <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; }
/// <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; } } }
/// <summary> /// Read the image data from ExchangeElement, subject to the transform, i.e., reSize, downsampling, etc. /// specified by the parameters. /// </summary> /// <param name="exEl">element in DataExchange</param> /// <returns></returns> private INumArray <double> GetData(ExchangeElement exEl) { INumArray <double> data; int nHeight = exEl.Height; int nWidth = exEl.Width; int i, j; int ipx = 0; if (m_bResize) { //if m_bResize=true, resize the data to certain size char[] charArr = new char[exEl.ByteData.GetLength(0)]; for (i = 0; i < exEl.ByteData.GetLength(0); i++) { charArr[i] = Convert.ToChar(exEl.ByteData[i]); } Dpu.ImageProcessing.Image dpuImgData = new Dpu.ImageProcessing.Image(charArr, nWidth, nHeight); Dpu.ImageProcessing.Image rstImgData = new Dpu.ImageProcessing.Image(m_iReSizeWidth, m_iReSizeHeight); Dpu.ImageProcessing.Image.BilinearResample(dpuImgData, rstImgData); data = ArrFactory.DoubleArray(m_iReSizeHeight, m_iReSizeWidth); float[] pixelData = rstImgData.Pixels; ipx = 0; for (i = 0; i < m_iReSizeHeight; i++) { for (j = 0; j < m_iReSizeWidth; j++) { data[i, j] = Convert.ToDouble(pixelData[ipx]); ipx += 1; } } } else { if (m_bDownSample) { data = ArrFactory.DoubleArray(nHeight / 2, nWidth / 2); ipx = 0; Byte[] imData = exEl.ByteData; for (i = 0; i < nHeight; i++) { for (j = 0; j < nWidth; j++) { data[i, j] = Convert.ToDouble(imData[ipx]); ipx += 2; } } } else { data = ArrFactory.DoubleArray(exEl.DoubleDataMatrix); } } if (m_bGlocalTrans) { data = DataTransform.GlocalTransform(data, _localWidth, _localHeight); } return(data); }