/// <summary> /// HSI转换 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") { /// <summary> ///从list数据流中按文件名索引数据。 /// <summary> string pathmark1 = Path.GetFileName(textBox1.Text); string pathmark2 = Path.GetFileName(textBox2.Text); string pathmark3 = Path.GetFileName(textBox3.Text); GetDataByFilename gdb = new GetDataByFilename(); int iR = gdb.getnumber(Form1.boduan, pathmark1); int iG = gdb.getnumber(Form1.boduan, pathmark2); int iB = gdb.getnumber(Form1.boduan, pathmark3); /// <summary> /// 按波段名索引波段号 /// <summary> GetBandByname gbn = new GetBandByname(); int Rband = gbn.getnumber(Form1.boduan[iR].Bandsname, this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf(pathmark1) - 1) , Form1.boduan[iR].bands); int Gband = gbn.getnumber(Form1.boduan[iG].Bandsname, this.textBox2.Text.Substring(0, this.textBox2.Text.IndexOf(pathmark2) - 1) , Form1.boduan[iG].bands); int Bband = gbn.getnumber(Form1.boduan[iB].Bandsname, this.textBox3.Text.Substring(0, this.textBox3.Text.IndexOf(pathmark3) - 1) , Form1.boduan[iB].bands); if (Form1.boduan[iR].ColumnCounts == Form1.boduan[iG].ColumnCounts && Form1.boduan[iR].ColumnCounts == Form1.boduan[iB].ColumnCounts && Form1.boduan[iR].LineCounts == Form1.boduan[iG].LineCounts && Form1.boduan[iR].LineCounts == Form1.boduan[iB].LineCounts) { read rd = new read(); /// <summary> /// RGBtoHSI /// <summary> RGBToHSI rth = new RGBToHSI(iR, iG, iB, Rband, Gband, Bband, rd); rd = rth.GetResult(); rd.Bandsname = new string[3]; rd.Bandsname[0] = "Hue" + "(" + Form1.boduan[iR].Bandsname[Rband] + ":" + pathmark1 + ")"; rd.Bandsname[1] = "Sat" + "(" + Form1.boduan[iG].Bandsname[Gband] + ":" + pathmark2 + ")"; rd.Bandsname[2] = "Iit" + "(" + Form1.boduan[iB].Bandsname[Bband] + ":" + pathmark3 + ")"; if (textBox4.Text == "") { rd.FileName = "HSI"; } else { rd.FileName = textBox4.Text; } /// <summary> ///静态窗口available打开,将结果加入静态数据流泛型中 /// <summary> Form1.abl.readmore.Add(rd); Form1.abl.PATH = rd.FileName; Form1.boduan.Add(rd); Form1.abl.Form_Load(sender, e); Form1.abl.Show(); this.Close(); } else { MessageBox.Show("波段规格不匹配!"); } } else { MessageBox.Show("无有效数据!"); } }
private void simpleButton1_Click(object sender, EventArgs e) { /// <summary> /// No Display 时创建imageview新实例 /// <summary> if (comboBox1.Text == "No Display") { /// <summary> /// comboBox操作,类似envi /// <summary> //windowsnum++; comboBox1.Items.Add("Display #" + 1); comboBox1.SelectedItem = "Display #" + 1; comboBox1.Items.Remove("No Display"); /// <summary> /// 定义新窗体 /// <summary> imageview imv = new imageview("Display #" + 1); imv.Text = "Display #" + 1; /// <summary> /// 选择灰度(单波段)显示 /// <summary> if (radioButton1.Checked) { if (textBox1.Text != "") { /// <summary> ///索引数据流,得到数据 /// <summary> string pathmark = Path.GetFileName(textBox1.Text); GetDataByFilename gdb = new GetDataByFilename(); int i = gdb.getnumber(readmore, pathmark); GetBandByname gbn = new GetBandByname(); int single = gbn.getnumber(readmore[i].Bandsname, this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf(pathmark) - 1) , readmore[i].bands); /// <summary> /// imv实例中各项数据初始化 /// <summary> imv.ColumnCounts = readmore[i].ColumnCounts; imv.LineCounts = readmore[i].LineCounts; imv.bands = 1; imv.showdata = new int[imv.bands, imv.ColumnCounts *imv.LineCounts]; imv.BandsDataD = new double[imv.bands, imv.ColumnCounts *imv.LineCounts]; imv.bandstemp = new int[imv.bands, imv.ColumnCounts *imv.LineCounts]; /// <summary> ///原数据存储 /// <summary> for (int j = 0; j < readmore[i].ColumnCounts * readmore[i].LineCounts; j++) { imv.BandsDataD[0, j] = readmore[i].BandsDataD[single, j]; } imv.pictureBox1.Height = imv.LineCounts; imv.pictureBox1.Width = imv.ColumnCounts; ///窗口状态初始化 imv.handleBopen(); /// <summary> ///通过LinearShow方法,将原数据拉伸至0-255用于显示 /// <summary> imagestretch images = new imagestretch(imv.ColumnCounts, imv.LineCounts, imv.bands); //images.LinearShow(imv.showdata, imv.BandsDataD); imv.showdata = images.TwoPercentStretch(imv.BandsDataD); /// <summary> ///窗口命名 /// <summary> imv.Text = textBox1.Text; /// <summary> ///显示图像 /// <summary> ImageShow ims = new ImageShow(); imv.pictureBox1.Refresh(); Bitmap map = new Bitmap(imv.pictureBox1.Width, imv.pictureBox1.Height); ims.showimage(imv.showdata, imv.ColumnCounts, imv.LineCounts, imv.bands, map); imv.pictureBox1.Image = map; imv.Show(); imv.Visible = true; } else { MessageBox.Show("请选择波段!"); } } else if (radioButton2.Checked) { if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "") { /// <summary> ///从list数据流中按文件名索引数据。 /// <summary> string pathmark2 = Path.GetFileName(textBox2.Text); string pathmark3 = Path.GetFileName(textBox3.Text); string pathmark4 = Path.GetFileName(textBox4.Text); GetDataByFilename gdb = new GetDataByFilename(); int i2 = gdb.getnumber(readmore, pathmark2); int i3 = gdb.getnumber(readmore, pathmark3); int i4 = gdb.getnumber(readmore, pathmark4); /// <summary> /// 按波段名索引波段号 /// <summary> GetBandByname gbn = new GetBandByname(); int Rband = gbn.getnumber(readmore[i2].Bandsname, this.textBox2.Text.Substring(0, this.textBox2.Text.IndexOf(pathmark2) - 1) , readmore[i2].bands); int Gband = gbn.getnumber(readmore[i3].Bandsname, this.textBox3.Text.Substring(0, this.textBox3.Text.IndexOf(pathmark3) - 1) , readmore[i3].bands); int Bband = gbn.getnumber(readmore[i4].Bandsname, this.textBox4.Text.Substring(0, this.textBox4.Text.IndexOf(pathmark4) - 1) , readmore[i4].bands); if (Form1.boduan[i2].ColumnCounts == Form1.boduan[i3].ColumnCounts && Form1.boduan[i2].ColumnCounts == Form1.boduan[i4].ColumnCounts && Form1.boduan[i2].LineCounts == Form1.boduan[i3].LineCounts && Form1.boduan[i2].LineCounts == Form1.boduan[i4].LineCounts) { /// <summary> /// imv实例中各项数据初始化 /// <summary> imv.LineCounts = readmore[i2].LineCounts; imv.ColumnCounts = readmore[i3].ColumnCounts; imv.bands = 3; imv.showdata = new int[imv.bands, imv.LineCounts *imv.ColumnCounts]; imv.BandsDataD = new double[imv.bands, imv.ColumnCounts *imv.LineCounts]; /// <summary> ///任意图像任意波段合成(数据传递) /// <summary> for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++) { imv.BandsDataD[0, j] = readmore[i2].BandsDataD[Rband, j]; } for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++) { imv.BandsDataD[1, j] = readmore[i3].BandsDataD[Gband, j]; } for (int j = 0; j < imv.ColumnCounts * imv.LineCounts; j++) { imv.BandsDataD[2, j] = readmore[i4].BandsDataD[Bband, j]; } imv.pictureBox1.Height = imv.LineCounts; imv.pictureBox1.Width = imv.ColumnCounts; ///窗口状态初始化 imv.handleBopen(); /// <summary> ///通过LinearShow方法,将原数据拉伸至0-255用于显示 /// <summary> imagestretch images = new imagestretch(imv.ColumnCounts, imv.LineCounts, imv.bands); images.LinearShow(imv.showdata, imv.BandsDataD); //imv.showdata = images.TwoPercentStretch(imv.BandsDataD); /// <summary> ///窗口命名 /// <summary> imv.Text = textBox2.Text + "&" + textBox3.Text + "&" + textBox4.Text; /// <summary> ///显示图像 /// <summary> imv.pictureBox1.Refresh(); ImageShow ims = new ImageShow(); Bitmap map = new Bitmap(imv.pictureBox1.Width, imv.pictureBox1.Height); ims.showimage(imv.showdata, imv.ColumnCounts, imv.LineCounts, imv.bands, map); imv.pictureBox1.Image = map; imv.Show(); imv.Visible = true; } else { MessageBox.Show("波段规格不匹配!"); } } else { MessageBox.Show("请输入波段!"); } } /// <summary> /// imv实例加入Wins泛型中 /// <summary> Wins.Add(imv); } /// <summary> ///对已存在的imageview窗体进行数据传递和操作 /// <summary> else { /// <summary> /// 搜索窗口 /// <summary> GetWinByName gwn = new GetWinByName(); int WinNbr = gwn.GetWinN(Wins, comboBox1.Text); if (radioButton1.Checked) { if (textBox1.Text != "") { string pathmark = Path.GetFileName(textBox1.Text); /// <summary> ///索引数据流,得到数据 /// <summary> GetDataByFilename gdb = new GetDataByFilename(); int i = gdb.getnumber(readmore, pathmark); GetBandByname gbn = new GetBandByname(); int single = gbn.getnumber(readmore[i].Bandsname, this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf(pathmark) - 1) , readmore[i].bands); /// <summary> /// imv实例中各项数据初始化 /// <summary> Wins[WinNbr].ColumnCounts = readmore[i].ColumnCounts; Wins[WinNbr].LineCounts = readmore[i].LineCounts; Wins[WinNbr].bands = 1; Wins[WinNbr].showdata = new int[Wins[WinNbr].bands, Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts]; Wins[WinNbr].BandsDataD = new double[Wins[WinNbr].bands, Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts]; /// <summary> ///原数据存储 /// <summary> for (int j = 0; j < readmore[i].ColumnCounts * readmore[i].LineCounts; j++) { Wins[WinNbr].BandsDataD[0, j] = readmore[i].BandsDataD[single, j]; } Wins[WinNbr].pictureBox1.Height = Wins[WinNbr].LineCounts; Wins[WinNbr].pictureBox1.Width = Wins[WinNbr].ColumnCounts; ///窗口状态初始化 Wins[WinNbr].handleBopen(); /// <summary> ///通过LinearShow方法,将原数据拉伸至0-255用于显示 /// <summary> imagestretch images = new imagestretch(Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands); //images.LinearShow(Wins[WinNbr].showdata, Wins[WinNbr].BandsDataD); Wins[WinNbr].showdata = images.TwoPercentStretch(Wins[WinNbr].BandsDataD); /// <summary> /// 图像拉伸数据初始化和赋值 /// <summary> BandpixelInitialize bpi = new BandpixelInitialize(); bpi.Initialization(out Wins[WinNbr].bandstemp, Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts , Wins[WinNbr].LineCounts, Wins[WinNbr].bands); /// <summary> ///窗口命名 /// <summary> Wins[WinNbr].Text = textBox1.Text; /// <summary> ///显示图像 /// <summary> ImageShow ims = new ImageShow(); //ims.showimage(bandints,ColumnCounts,LineCounts) Wins[WinNbr].pictureBox1.Refresh(); Bitmap map = new Bitmap(Wins[WinNbr].pictureBox1.Width, Wins[WinNbr].pictureBox1.Height); ims.showimage(Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands, map); Wins[WinNbr].pictureBox1.Image = map; Wins[WinNbr].Show(); Wins[WinNbr].Visible = true; } else { MessageBox.Show("请输入波段!"); } } else if (radioButton2.Checked) { if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "") { /// <summary> ///从list数据流中按文件名索引数据。 /// <summary> string pathmark2 = Path.GetFileName(textBox2.Text); string pathmark3 = Path.GetFileName(textBox3.Text); string pathmark4 = Path.GetFileName(textBox4.Text); GetDataByFilename gdb = new GetDataByFilename(); int i2 = gdb.getnumber(readmore, pathmark2); int i3 = gdb.getnumber(readmore, pathmark3); int i4 = gdb.getnumber(readmore, pathmark4); /// <summary> /// 按波段名索引波段号 /// <summary> GetBandByname gbn = new GetBandByname(); int Rband = gbn.getnumber(readmore[i2].Bandsname, this.textBox2.Text.Substring(0, this.textBox2.Text.IndexOf(pathmark2) - 1) , readmore[i2].bands); int Gband = gbn.getnumber(readmore[i3].Bandsname, this.textBox3.Text.Substring(0, this.textBox3.Text.IndexOf(pathmark3) - 1) , readmore[i3].bands); int Bband = gbn.getnumber(readmore[i4].Bandsname, this.textBox4.Text.Substring(0, this.textBox4.Text.IndexOf(pathmark4) - 1) , readmore[i4].bands); if (Form1.boduan[i2].ColumnCounts == Form1.boduan[i3].ColumnCounts && Form1.boduan[i2].ColumnCounts == Form1.boduan[i4].ColumnCounts && Form1.boduan[i2].LineCounts == Form1.boduan[i3].LineCounts && Form1.boduan[i2].LineCounts == Form1.boduan[i4].LineCounts) { /// <summary> /// imv实例中各项数据初始化 /// <summary> Wins[WinNbr].LineCounts = readmore[i2].LineCounts; Wins[WinNbr].ColumnCounts = readmore[i3].ColumnCounts; Wins[WinNbr].bands = 3; Wins[WinNbr].showdata = new int[3, Wins[WinNbr].LineCounts * Wins[WinNbr].ColumnCounts]; Wins[WinNbr].BandsDataD = new double[3, Wins[WinNbr].LineCounts * Wins[WinNbr].ColumnCounts]; /// <summary> ///任意图像任意波段合成(数据传递) /// <summary> for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++) { Wins[WinNbr].BandsDataD[0, j] = readmore[i2].BandsDataD[Rband, j]; } for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++) { Wins[WinNbr].BandsDataD[1, j] = readmore[i3].BandsDataD[Gband, j]; } for (int j = 0; j < Wins[WinNbr].ColumnCounts * Wins[WinNbr].LineCounts; j++) { Wins[WinNbr].BandsDataD[2, j] = readmore[i4].BandsDataD[Bband, j]; } Wins[WinNbr].pictureBox1.Height = Wins[WinNbr].LineCounts; Wins[WinNbr].pictureBox1.Width = Wins[WinNbr].ColumnCounts; ///窗口状态初始化 Wins[WinNbr].handleBopen(); /// <summary> ///通过LinearShow方法,将原数据拉伸至0-255用于显示 /// <summary> imagestretch images = new imagestretch(Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands); //images.LinearShow(Wins[WinNbr].showdata, Wins[WinNbr].BandsDataD); Wins[WinNbr].showdata = images.TwoPercentStretch(Wins[WinNbr].BandsDataD); /// <summary> /// 图像拉伸数据初始化和赋值 /// <summary> BandpixelInitialize bpi = new BandpixelInitialize(); bpi.Initialization(out Wins[WinNbr].bandstemp, Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts , Wins[WinNbr].LineCounts, Wins[WinNbr].bands); /// <summary> ///窗口命名 /// <summary> Wins[WinNbr].Text = textBox2.Text + "&" + textBox3.Text + "&" + textBox4.Text; /// <summary> ///显示图像 /// <summary> Wins[WinNbr].pictureBox1.Refresh(); ImageShow ims = new ImageShow(); Bitmap map = new Bitmap(Wins[WinNbr].pictureBox1.Width, Wins[WinNbr].pictureBox1.Height); ims.showimage(Wins[WinNbr].showdata, Wins[WinNbr].ColumnCounts, Wins[WinNbr].LineCounts, Wins[WinNbr].bands, map); Wins[WinNbr].pictureBox1.Image = map; Wins[WinNbr].Show(); Wins[WinNbr].Visible = true; } else { MessageBox.Show("波段规格不匹配!"); } } else { MessageBox.Show("请输入波段!"); } } } }
/// <summary> /// 四则运算 /// </summary> /// <returns>返回结果</returns> private double[] EvaluateExpression() { try { string myExp = expression + "="; //表达式。。 Stack <char> optr = new Stack <char>(myExp.Length); //存放操作符栈。。 Stack <double[]> opnd = new Stack <double[]>(myExp.Length); //存放操作数组栈。。 optr.Push('='); int index = 0; //字符索引。。 char c = myExp.ToCharArray()[index++]; //读取每一个字符。。 double[] num1, num2; while ((c != '=') || (optr.Peek() != '=')) { if (c == '"') { string band_File = ""; while (true) { if ((c = myExp.ToCharArray()[index++]) == '"') { if (band_File.IndexOf(":") == -1) { //double[] temp = opnd.Pop(); //int Length = temp.GetLength(0); //opnd.Push(temp); //double math = Convert.ToDouble(band_File); //temp = new double[Length]; //for (int i = 0; i < temp.GetLength(0); i++) // temp[i] = math; //opnd.Push(temp); //c = myExp.ToCharArray()[index++]; //break; } else { //索引数据 string FileName = Path.GetFileName(band_File); GetDataByFilename gdbf = new GetDataByFilename(); int i = gdbf.getnumber(Form1.boduan, FileName); string bandname = band_File.Substring(0, band_File.IndexOf(FileName) - 1); GetBandByname gbbn = new GetBandByname(); int j = gbbn.getnumber(Form1.boduan[i].Bandsname, bandname, Form1.boduan[i].bands); //初始化数据并赋值 double[] temp = new double[Form1.boduan[i].ColumnCounts * Form1.boduan[i].LineCounts]; for (int k = 0; k < Form1.boduan[i].ColumnCounts * Form1.boduan[i].LineCounts; k++) { temp[k] = Form1.boduan[i].BandsDataD[j, k]; } ColumnCounts = Form1.boduan[i].ColumnCounts; LineCounts = Form1.boduan[i].LineCounts; //将数据压入栈中 opnd.Push(temp); c = myExp.ToCharArray()[index++]; break; } } band_File += c; } } else if (c != '+' && c != '-' && c != '*' && c != '/' && c != '(' && c != ')' && c != '=') { string band_File = ""; band_File += c; while (true) { if (index + 1 == myExp.Length) { break; } c = myExp.ToCharArray()[index++]; if (!judge(c)) { break; } band_File += c; } double[] temp = opnd.Pop(); int Length = temp.GetLength(0); opnd.Push(temp); double math = Convert.ToDouble(band_File); temp = new double[Length]; for (int i = 0; i < temp.GetLength(0); i++) { temp[i] = math; } opnd.Push(temp); c = myExp.ToCharArray()[index++]; } else { bool isJump = false; switch (Precede(optr.Peek(), c)) { case '<': optr.Push(c); if ((index + 1) == myExp.Length) { isExpressionRight = false; isJump = true; break; } c = myExp.ToCharArray()[index++]; break; case '=': optr.Pop(); //if ((index + 1) == myExp.Length) //{ // isExpressionRight = false; // isJump = true; // break; //} c = myExp.ToCharArray()[index++]; break; case '>': num2 = opnd.Pop(); num1 = opnd.Pop(); opnd.Push(Operate(num1, optr.Pop(), num2)); if (!ishandled) { isJump = true; } break; default: break; } if (isJump) { break; } } } if (!isExpressionRight) { double[] a = new double[100]; } return(opnd.Pop()); } catch (Exception) { double[] a = new double[100]; return(a); } }