private void bttnOK_Click(object sender, EventArgs e) { colPalette = loadColorPalette(Application.StartupPath + "\\" + cmbColorPalettes.SelectedItem + ".cp"); NIRed = cmbInfraRed.SelectedIndex; Red = cmbRed.SelectedIndex; this.Cursor = Cursors.WaitCursor; panel1.Controls.Add(iw); iw.Dock = DockStyle.Fill; iw.Show(); GeoMultiBandMethods ndvi = new GeoMultiBandMethods(); string filesNamesNIR = GiwerDataFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(imgDat.FileName) + @"\" + NIRed + ".gwr"; string filesNamesRed = GiwerDataFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(imgDat.FileName) + @"\" + Red + ".gwr"; if (NIRed != -1 & Red != -1) { GeoImageData gima = new GeoImageData(); gima.FileName = GiwerDataFolder + "\\" + System.IO.Path.GetFileNameWithoutExtension(imgDat.FileName) + ".gwh"; GeoImageTools gmt = new GeoImageTools(gima); byte[] bnir = gmt.readGwrFile(filesNamesNIR); byte[] bred = gmt.readGwrFile(filesNamesRed); currentBand = ndvi.NDVI(bnir, bred); iw.DrawImage(gima, currentBand, colPalette); //iw.InitImage(gmt.convertOneBandBytesto8bitBitmap(currentBand,imgDat.Ncols,imgDat.Nrows,colPalette)); bttnHisto.Visible = true; bttnSaveAsImage.Visible = true; bttnSaveToGiwerFormat.Visible = true; } else { MessageBox.Show("Missing band! Two bands need to be selected"); } this.Cursor = Cursors.Default; }
//compute correlation matrix for the given bands (lst4PCA contains bands' name) public double[,] computeCorrelationMatrix(List <int> lst4PCA) { double[,] corr = new double[lst4PCA.Count, lst4PCA.Count]; for (int k = 0; k < lst4PCA.Count; k++) { corr[k, k] = 1; } for (int j = 0; j < lst4PCA.Count; j++) { string fnA = GiwerDataFolder + @"\" + System.IO.Path.GetFileNameWithoutExtension(gida.FileName) + @"\" + lst4PCA[j] + ".gwr"; byte[] curBandA = gito.readGwrFile(fnA); double averageA = imageAverage(curBandA); double scatterA = imageScatter(curBandA, averageA); double[] standA = imageStandardization(curBandA, averageA, scatterA); double[] standB = new double[standA.Length]; for (int i = j + 1; i < lst4PCA.Count; i++) { string fnB = GiwerDataFolder + @"\" + System.IO.Path.GetFileNameWithoutExtension(gida.FileName) + @"\" + lst4PCA[i] + ".gwr"; byte[] curBandB = gito.readGwrFile(fnB); double averageB = imageAverage(curBandB); double scatterB = imageScatter(curBandB, averageB); standB = imageStandardization(curBandB, averageB, scatterB); corr[j, i] = computeCorrelation(standA, standB); corr[i, j] = corr[j, i]; //corr[i, lst4PCA.Count - j-1] = corr[i, j]; } } return(corr); }
void AligningBands() // band aligning for all bands: Band0 - Band1, Band0 - Band2, Band0 - Band3, ... { shifts.Clear(); pbar.Minimum = 0; pbar.Maximum = lstFiles.Items.Count - 1; pbar.Step = 1; pbar.Value = 0; pbar.Visible = true; cropMargin = 100 * (int)(gimda.Nrows / 300); offset = (int)(cropMargin / 15); GeoImageTools gtools = new GeoImageTools(gimda); List <float> listOfDiffs; List <string> listOfInds; Point startp1 = new Point(gimda.Ncols / 2 - cropMargin / 2, gimda.Nrows / 2 - cropMargin / 2); string fname1 = currentFolder + "\\" + lstFiles.Items[0].ToString().Split('_')[1] + ".gwr"; byte[] fileToCombine1 = ClipImage(gtools.readGwrFile(fname1), startp1, new Size(cropMargin, cropMargin), gimda.Ncols, gimda.Nrows); Point startp2 = startp1; shifts.Add("0;0"); textBox1.Text = ""; for (int i = 1; i < lstFiles.Items.Count; i++) // computes differences between bands one after the other { pbar.PerformStep(); Application.DoEvents(); string fname2 = currentFolder + "\\" + lstFiles.Items[i].ToString().Split('_')[1] + ".gwr"; byte[] fileToCombine2 = gtools.readGwrFile(fname2); DifferenceOfShifts(fileToCombine1, fileToCombine2, startp2, out listOfDiffs, out listOfInds); float min; string minindex; getMin(listOfDiffs, listOfInds, out min, out minindex); shifts.Add(minindex); listOfDiffs.Clear(); listOfInds.Clear(); if (i > 1) { textBox1.AppendText(Environment.NewLine); } textBox1.AppendText("B0-B" + i + " -> shift: " + minindex); //textBox1.AppendText(Environment.NewLine + "difference: " + min.ToString("#.###")); textBox1.Visible = true; } pbar.Visible = false; string minmax = getShiftsMinMax(); recoverBands(minmax); MessageBox.Show("Align process completed"); }
private void lstFiles_SelectedIndexChanged(object sender, EventArgs e) { if (lstFiles.SelectedItem != null) { GeoImageTools gtools = new GeoImageTools(); string fn = currentFolder + @"\" + lstFiles.SelectedItem.ToString().Split('_')[1] + ".gwr"; byte[] by = gtools.readGwrFile(fn); imw.DrawImage(gimda, by, loadColorPalette(Application.StartupPath + "\\" + "default.cp")); panel1.Visible = true; } else { panel1.Visible = false; } }
void recoverBands(string minmax) // minmax = minx; miny; maxx; maxy; minindex; maxindex { GeoImageTools gt = new GeoImageTools(gimda); GeoImageData gdOut = new GeoImageData(); gdOut = gimda; int widorig = gimda.Ncols; int hgtorig = gimda.Nrows; byte[] byin = new byte[widorig * hgtorig]; int maxindex = Convert.ToInt16(minmax.Split(';')[5]); int minindex = Convert.ToInt16(minmax.Split(';')[4]); int a = Math.Abs(Convert.ToInt16(shifts[minindex].Split(';')[0])); // get minx value from the shifts list int b = Math.Abs(Convert.ToInt16(shifts[maxindex].Split(';')[0])); // get maxx value from the shifts list int newwid = widorig - (a + b); int c = Math.Abs(Convert.ToInt16(shifts[minindex].Split(';')[1])); // get miny value from the shifts list int d = Math.Abs(Convert.ToInt16(shifts[maxindex].Split(';')[1])); // get maxy value from the shifts list int newhgt = hgtorig - (c + d); gdOut.Ncols = newwid; gdOut.Nrows = newhgt; gdOut.Nbits = 8; Size commonSize = new Size(newwid, newhgt); string fn = Path.GetDirectoryName(gimda.FileName) + "\\" + Path.GetFileNameWithoutExtension(gimda.FileName) + "_aligned.gwh"; GeoImageTools gtsave = new GeoImageTools(gdOut); gtsave.saveHeader2Giwer(fn); gdOut.FileName = fn; gtsave.saveHeader2Giwer(fn); for (int i = 0; i < lstFiles.Items.Count; i++) { int px = Math.Abs(Convert.ToInt16(shifts[i].Split(';')[0])); int py = Math.Abs(Convert.ToInt16(shifts[i].Split(';')[1])); //int px = Convert.ToInt16(shifts[maxindex].Split(';')[0]) - Convert.ToInt16(shifts[i].Split(';')[0]); //int py = Convert.ToInt16(shifts[maxindex].Split(';')[1]) - Convert.ToInt16(shifts[i].Split(';')[1]); Point startp = new Point(px, py); string fname = currentFolder + "\\" + lstFiles.Items[i].ToString().Split('_')[1] + ".gwr"; byin = gtsave.readGwrFile(fname); byte[] byOut = ClipImage(byin, startp, commonSize, widorig, hgtorig); string dirname = Path.GetDirectoryName(gdOut.FileName) + "\\" + Path.GetFileNameWithoutExtension(gdOut.FileName); gt.saveGivenBand2GiwerFormat(dirname, byOut, i, ""); } }