/// <summary> /// 任意范围拉伸 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e) { int[][] pixel = new int[bands][]; double[] max = new double[bands]; double[] min = new double[bands]; double[] stretch = new double[bands]; for (int i = 0; i < bands; i++) { perHistogram ph = new perHistogram(); ph.histogram2(BandsDataD, ColumnCounts * LineCounts, i, out pixel[i]); max[i] = ph.max; min[i] = ph.min; stretch[i] = ph.stretch; } ChooseRange CR = new ChooseRange(); CR.bands = bands; CR.pixel = pixel; CR.max = max; CR.min = min; CR.stretch = stretch; //if (bands == 1) //{ // CR.g1 = CR.pictureBox1.CreateGraphics(); // CR.g1.TranslateTransform(30, CR.pictureBox1.Height * 14 / 15); // CR.DrawRGB(0); // CR.g2 = CR.pictureBox1.CreateGraphics(); // CR.g2.TranslateTransform(30, CR.pictureBox1.Height * 14 / 15); // CR.g2.DrawLine(System.Drawing.Pens.Gray, CR.pt2.X, 0, CR.pt2.X, -1 * (int)(CR.pictureBox1.Height / 1.2)); // CR.g2.DrawLine(System.Drawing.Pens.Gray, CR.pt3.X, 0, CR.pt3.X, -1 * (int)(CR.pictureBox1.Height / 1.2)); //} CR.ShowDialog(); if (CR.WinState == true) { double a = CR.a; double b = CR.b; CR.WinState = false; BandpixelInitialize bpi = new BandpixelInitialize();//画图数组初始化 bpi.Initialization(out bandstemp, showdata, ColumnCounts, LineCounts, bands); imagestretch imgstrch = new imagestretch(ColumnCounts, LineCounts, bands); imgstrch.GlobalLinear(BandsDataD, bandstemp, a, b, CR.rabuttonState); pictureBox1.Refresh(); map = new Bitmap(pictureBox1.Width, pictureBox1.Height); ImageShow ims = new ImageShow(); ims.showimage(bandstemp, ColumnCounts, LineCounts, bands, map); pictureBox1.Image = map; //CR.ShowDialog(); } isValue = false; }
/// <summary> /// 均衡化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e) { imagestretch imst = new imagestretch(ColumnCounts, LineCounts, bands); imst.Equalization(BandsDataD); StretchTemp = imst.getresult(); this.bandstemp = imst.TwoPercentStretch(StretchTemp); pictureBox1.Refresh(); map = new Bitmap(pictureBox1.Width, pictureBox1.Height); ImageShow ims = new ImageShow(); ims.showimage(bandstemp, ColumnCounts, LineCounts, bands, map); pictureBox1.Image = map; isValue = false; stretchtype = "Equalization"; }
/// <summary> /// 2%拉伸 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e) { BandpixelInitialize bpi = new BandpixelInitialize();//画图数组初始化 bpi.Initialization(out bandstemp, showdata, ColumnCounts, LineCounts, bands); imagestretch imgstrch = new imagestretch(ColumnCounts, LineCounts, bands); bandstemp = imgstrch.TwoPercentStretch(BandsDataD); pictureBox1.Refresh(); map = new Bitmap(pictureBox1.Width, pictureBox1.Height); ImageShow ims = new ImageShow(); ims.showimage(bandstemp, ColumnCounts, LineCounts, bands, map); pictureBox1.Image = map; isValue = false; }
/// <summary> /// 传递数据至image stastics窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { /// </summary> /// 根据文件名选择数据 /// </summary> if (listBox1.Text == "") { MessageBox.Show("请选择数据!"); return; } Imagestatistics imagsta = new Imagestatistics(); imagsta.FileName = listBox1.SelectedItem.ToString(); GetDataByFilename gdb = new GetDataByFilename(); int DataNumber = gdb.getnumber(Form1.boduan, imagsta.FileName); /// </summary> /// imagsta实例窗体数据初始化和赋值 /// </summary> imagsta.LineCounts = Form1.boduan[DataNumber].LineCounts; imagsta.ColumnCounts = Form1.boduan[DataNumber].ColumnCounts; imagsta.bands = Form1.boduan[DataNumber].bands; //imagsta.DataType = Form1.boduan[DataNumber].DataType; imagsta.Interleave = Form1.boduan[DataNumber].Interleave; imagsta.BandsData = new int[imagsta.bands, imagsta.ColumnCounts *imagsta.LineCounts]; imagsta.BandsDataD = new double[imagsta.bands, imagsta.ColumnCounts *imagsta.LineCounts]; imagsta.showdata = new int[imagsta.bands, imagsta.ColumnCounts *imagsta.LineCounts]; for (int i = 0; i < imagsta.bands; i++) { for (int j = 0; j < imagsta.ColumnCounts * imagsta.LineCounts; j++) { imagsta.BandsData[i, j] = Form1.boduan[DataNumber].BandsData[i, j]; imagsta.BandsDataD[i, j] = Form1.boduan[DataNumber].BandsDataD[i, j]; } } /// </summary> /// 生成0-255范围像素数据,用于联合直方图和共生矩阵 /// </summary> imagestretch ims = new imagestretch(imagsta.ColumnCounts, imagsta.LineCounts, imagsta.bands); ims.LinearShow(imagsta.showdata, imagsta.BandsDataD); imagsta.Show(); this.Close(); }
/// <summary> /// 直方图匹配(窗口间) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e) { if (Form1.abl.Wins.Count == 1) { MessageBox.Show("窗口不足,不能实现直方图匹配!"); } else { int WinN1, WinN2; HistogramMatch hm = new HistogramMatch(); WinN1 = Convert.ToInt32(this.windowname.Substring(windowname.Length - 1)); for (int i = 0; i < Form1.abl.Wins.Count; i++) { hm.listBox1.Items.Add(Form1.abl.Wins[i].windowname); } hm.listBox1.Items.Remove(this.windowname); hm.ShowDialog(); if (hm.Winnumber2 != -9999) { WinN2 = hm.Winnumber2; /// <summary> /// 直方图匹配采用0-255值域显示数据方便步骤 /// <summary> BandpixelInitialize bpi = new BandpixelInitialize(); bpi.Initialization(out bandstemp, showdata, ColumnCounts, LineCounts, bands); imagestretch imst = new imagestretch(ColumnCounts, LineCounts, bands); imst.HistogramMatch(this.BandsDataD, Form1.abl.Wins[WinN2].BandsDataD, Form1.abl.Wins[WinN2].bands); StretchTemp = imst.getresult(); imst.LinearShow(bandstemp, StretchTemp); /// <summary> /// 显示图像 /// <summary> pictureBox1.Refresh(); map = new Bitmap(pictureBox1.Width, pictureBox1.Height); ImageShow ims = new ImageShow(); ims.showimage(bandstemp, ColumnCounts, LineCounts, bands, map); pictureBox1.Image = map; } } isValue = false; stretchtype = "HistogramMatch"; }
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("请输入波段!"); } } } }