private void setPixelData(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { System.Array pbArr = (System.Array)pbIn.get_PixelData(p); for (int r = 0; r < pbIn.Height; r++) { for (int c = 0; c < pbIn.Width; c++) { HashSet <float> hash = new HashSet <float>(); for (int rb = 0; rb < rws; rb++) { int nrb = r + rb; for (int cb = 0; cb < clms; cb++) { int ncb = c + cb; object objVl = pbInBig.GetVal(p, ncb, nrb); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); hash.Add(vl); } } } pbArr.SetValue(hash.Count, c, r); } } pbIn.set_PixelData(p, pbArr); }
private void setPixelData(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { System.Array pbArr = (System.Array)pbIn.get_PixelData(p); for (int r = 0; r < pbIn.Height; r++) { for (int c = 0; c < pbIn.Width; c++) { int tCnt = 0; Dictionary <float, int> vlDic = new Dictionary <float, int>(); for (int rb = 0; rb < rws; rb++) { int nrb = r + rb; for (int cb = 0; cb < clms; cb++) { int ncb = c + cb; object objVl = pbInBig.GetVal(p, ncb, nrb); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); int vlCnt = 1; //Console.WriteLine("From Thread " + p.ToString() + "; " + vl.ToString()); if (vlDic.TryGetValue(vl, out vlCnt)) { vlDic[vl] = vlCnt + 1; } else { vlDic.Add(vl, 1); } tCnt += 1; } } } int rSum = 0; int halfCnt = tCnt / 2; List <float> keyLst = vlDic.Keys.ToList(); keyLst.Sort(); foreach (float f in keyLst) { int vlCnt = vlDic[f]; rSum = rSum + vlCnt; if (rSum > halfCnt) { pbArr.SetValue(f, c, r); break; } } //pbArr.SetValue(ent, c, r); } } pbIn.set_PixelData(p, pbArr); }
private void setPixelData(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { System.Array pbArr = (System.Array)pbIn.get_PixelData(p); for (int r = 0; r < pbIn.Height; r++) { for (int c = 0; c < pbIn.Width; c++) { Dictionary <float, int> vlDic = new Dictionary <float, int>(); for (int rb = 0; rb < rws; rb++) { int nrb = r + rb; for (int cb = 0; cb < clms; cb++) { int ncb = c + cb; object objVl = pbInBig.GetVal(p, ncb, nrb); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); int vlCnt = 1; //Console.WriteLine("From Thread " + p.ToString() + "; " + vl.ToString()); if (vlDic.TryGetValue(vl, out vlCnt)) { vlDic[vl] = vlCnt + 1; } else { vlDic.Add(vl, 1); } } } } int maxCnt = 0; float maxVl = 0; foreach (KeyValuePair <float, int> kvp in vlDic) { int kVl = kvp.Value; //Console.WriteLine("kVl = " + kVl.ToString()); if (kVl > maxCnt) { maxVl = kvp.Key; maxCnt = kVl; } } pbArr.SetValue(maxVl, c, r); } } pbIn.set_PixelData(p, pbArr); }
private void setPixelData(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { System.Array pbArr = (System.Array)pbIn.get_PixelData(p); for (int r = 0; r < pbIn.Height; r++) { for (int c = 0; c < pbIn.Width; c++) { float tCnt = 0; Dictionary <float, int> vlDic = new Dictionary <float, int>(); for (int rb = 0; rb < rws; rb++) { int nrb = r + rb; for (int cb = 0; cb < clms; cb++) { int ncb = c + cb; object objVl = pbInBig.GetVal(p, ncb, nrb); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); int vlCnt = 1; //Console.WriteLine("From Thread " + p.ToString() + "; " + vl.ToString()); if (vlDic.TryGetValue(vl, out vlCnt)) { vlDic[vl] = vlCnt + 1; } else { vlDic.Add(vl, 1); } tCnt += 1; } } } float prob = 0; float ent = 0; foreach (int vlCnt in vlDic.Values) { prob = vlCnt / tCnt; ent = ent + (prob * System.Convert.ToSingle(Math.Log(prob))); } pbArr.SetValue(ent * -1, c, r); } } pbIn.set_PixelData(p, pbArr); }
private void setPixelDataFolding(int p, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { System.Array pbArr = (System.Array)pbIn.get_PixelData(p); HashSet <float>[][] wrDic1 = new HashSet <float> [pbIn.Width][]; //create first dictionary and set first values for (int w = 0; w < pbIn.Width; w++) { wrDic1[w] = new HashSet <float> [rws]; for (int r = 0; r < rws; r++) { wrDic1[w][r] = new HashSet <float>(); HashSet <float> fDic = wrDic1[w][r]; for (int c = 0; c < clms; c++) { object objVl = pbInBig.GetVal(p, c, r); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); fDic.Add(vl); } } } setValues(pbArr, wrDic1[w], w, 0); } //create next dictionary and set the rest of the values int clmsM = clms - 1; int rwsM = rws - 1; HashSet <float>[][] wrDic2 = new HashSet <float> [pbIn.Width][]; //wrDic2[0][0] = wrDic1[0][rwsM]; for (int r = 1; r < pbIn.Height; r++) { for (int c = 0; c < pbIn.Width; c++) { HashSet <float> clmsDic; wrDic2[c] = new HashSet <float> [rws]; for (int rb = 1; rb < rws; rb++) { wrDic2[c][rb - 1] = new HashSet <float>(wrDic1[c][rb]); } int nrb = r + rwsM; if (c > 0)// copy previous dictionary on same row and remove/add values { wrDic2[c][rwsM] = new HashSet <float>(wrDic2[c - 1][rwsM]); clmsDic = wrDic2[c][rwsM]; int ncb = c + clmsM; object objVln = pbInBig.GetVal(p, ncb, nrb); object objVlo = pbInBig.GetVal(p, c - 1, nrb); if (objVlo != null)//remove old value { float vlo = System.Convert.ToSingle(objVlo); clmsDic.Remove(vlo); } if (objVln != null)//add new value { float vln = System.Convert.ToSingle(objVln); clmsDic.Add(vln); } } else //first column, need to get all numbers of new row { wrDic2[c][rwsM] = new HashSet <float>(); HashSet <float> fDic = wrDic2[c][rwsM]; for (int c2 = 0; c2 < clms; c2++) { object objVl = pbInBig.GetVal(p, c2, nrb); if (objVl != null) { float vl = System.Convert.ToSingle(objVl); fDic.Add(vl); } } } setValues(pbArr, wrDic2[c], c, r); } } pbIn.set_PixelData(p, pbArr); wrDic1 = wrDic2; }
public override void updatePixelRectangle(ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbIn, ESRI.ArcGIS.DataSourcesRaster.IPixelBlock3 pbInBig) { int rs = pbInBig.Height; int cs = pbInBig.Width; int hc = clms - 1; int hr = rws - 1; int scs = pbIn.Width; int srs = pbIn.Height; Queue <float[]>[] windowQueue = new Queue <float[]> [pbIn.Planes]; for (int b = 0; b < pbIn.Planes; b++) { System.Array upArr = (System.Array)pbIn.get_PixelData(b);; Queue <float[]> queB = new Queue <float[]>(); windowQueue[b] = queB; for (int r = 0; r < rws; r++) { int nr = r - hr; float[] sumNewBigArr = new float[scs]; float sumVl = 0; for (int c = 0; c < clms; c++) { object objBvl = pbInBig.GetVal(b, c, r); float bVl = 0; if (objBvl != null) { bVl = (float)objBvl; } sumVl += bVl; } sumNewBigArr[0] = sumVl; for (int c = clms; c < cs; c++) { int nc = c - hc; int pc = c - clms; object bVlobj = pbInBig.GetVal(b, c, r); object pVlobj = pbInBig.GetVal(b, pc, r); float bVl = 0; float pVl = 0; if (bVlobj != null) { bVl = (float)bVlobj; } if (pVlobj != null) { pVl = (float)pVlobj; } sumVl += bVl - pVl; try { sumNewBigArr[nc] = sumVl; } catch (Exception e) { Console.WriteLine(e.ToString()); System.Windows.Forms.MessageBox.Show(e.ToString()); } } queB.Enqueue(sumNewBigArr); } updateFirstRow(queB, ref upArr, ref pbIn); for (int r = rws; r < rs; r++) { int pr = r - rws; int nr = r - hr; float[] sumNewBigArr = new float[scs]; float sumVl = 0; //first 3 values for (int c = 0; c < clms; c++) { object bVlobj = pbInBig.GetVal(b, c, r); float bVl = 0; if (bVlobj != null) { bVl = (float)bVlobj; } sumVl += bVl; } sumNewBigArr[0] = sumVl; float oldSumVl = queB.Peek()[0]; float pSmallArrValue = (float)upArr.GetValue(0, pr);//pSmallArrValues[0]; float nSmallArrValue = pSmallArrValue + sumVl - oldSumVl; upArr.SetValue(nSmallArrValue, 0, nr); //pSmallArrValues[0] = nSmallArrValue; for (int c = clms; c < cs; c++) { int nc = c - hc; int pc = c - clms; object bVlobj = pbInBig.GetVal(b, c, r); object pVlobj = pbInBig.GetVal(b, pc, r); float bVl = 0; float pVl = 0; if (bVlobj != null) { bVl = (float)bVlobj; } if (pVlobj != null) { pVl = (float)pVlobj; } sumVl += bVl - pVl; sumNewBigArr[nc] = sumVl; oldSumVl = queB.Peek()[nc]; pSmallArrValue = (float)upArr.GetValue(nc, pr);;// pSmallArrValues[nc]; nSmallArrValue = pSmallArrValue + sumVl - oldSumVl; try { upArr.SetValue(nSmallArrValue, nc, nr); //pSmallArrValues[nc] = nSmallArrValue; } catch (Exception e) { Console.WriteLine("Error in setting pSmallArrValues"); Console.WriteLine(e.ToString()); System.Windows.Forms.MessageBox.Show(e.ToString()); } } queB.Enqueue(sumNewBigArr); queB.Dequeue(); } pbIn.set_PixelData(b, upArr); } }