Beispiel #1
0
        private void g_b_showcolor_Click(object sender, EventArgs e)
        {
            //显示图像
            g_GetBands();//读取具体波段
            //显示图像
            var bitmap = new Bitmap(gcols, grows);

            for (int i = 0; i < grows; i++)
            {
                for (int j = 0; j < gcols; j++)
                {
                    if (g_rgb)
                    {
                        int r = gvalues[g_selectband[0], i, j];
                        int g = gvalues[g_selectband[1], i, j];
                        int b = gvalues[g_selectband[2], i, j];
                        bitmap.SetPixel(i, j, Color.FromArgb(r, g, b));
                    }
                    else
                    {
                        int r = gvalues[g_selectband[0], i, j];
                        bitmap.SetPixel(i, j, Color.FromArgb(r, r, r));
                    }
                }
            }

            img imgform = new img(bitmap);

            imgform.Show();
        }
Beispiel #2
0
        private void showimg_Click(object sender, EventArgs e)
        {
            GetBands();
            if (selectBands.Length == 0)
            {
                MessageBox.Show("请输入波段!");
                return;
            }
            var bitmap = new Bitmap(cols, rows);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    if (isrgb)
                    {
                        int r = data[selectBands[0], i, j];
                        int g = data[selectBands[1], i, j];
                        int b = data[selectBands[2], i, j];
                        bitmap.SetPixel(j, i, Color.FromArgb(r, g, b));
                    }
                    else
                    {
                        int r = data[selectBands[0], i, j];
                        bitmap.SetPixel(j, i, Color.FromArgb(r, r, r));
                    }
                }
            }

            img imgform = new img(bitmap);

            imgform.Show();
        }
Beispiel #3
0
        private void showKvalue(int Bnum)
        {//显示K均值分类结果
            String str = "";

            for (int i = 0; i < g_N; i++)
            {
                str += "第" + (i + 1) + "个类中心:";
                for (int j = 0; j < Bnum; j++)
                {
                    str += g_tzvalue[i, j].ToString() + " ";
                }
                str += "\r\n";
            }
            textBox1.Text = str;

            //显示图像
            var gbitmap = new Bitmap(gcols, grows);

            for (int i = 0; i < grows; i++)
            {
                for (int j = 0; j < gcols; j++)
                {
                    int r = typecolor[g_Kvalues[i, j], 0];
                    int g = typecolor[g_Kvalues[i, j], 1];
                    int b = typecolor[g_Kvalues[i, j], 2];
                    gbitmap.SetPixel(j, i, Color.FromArgb(r, g, b));
                }
            }
            img gimgform = new img(gbitmap);

            gimgform.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double H, S;
            Bitmap bitmap = new Bitmap(cols, rows);
            var    b1     = sband1.SelectedIndex;
            var    b2     = sband2.SelectedIndex;
            var    b3     = sband3.SelectedIndex;

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    double r = (data[b1, i, j]);
                    double g = (data[b2, i, j]);
                    double b = (data[b3, i, j]);

                    double num  = 0.5 * ((r - g) + (r - b));
                    double den1 = Math.Sqrt((r - g) * (r - g) + (r - b) * (g - b));
                    if (den1 == 0)
                    {
                        H = 0;
                    }
                    else
                    {
                        double theta = Math.Acos(num / den1);
                        if (b > g)
                        {
                            H = (2 * Math.PI - theta) / (2 * Math.PI);
                        }
                        else
                        {
                            H = theta / (2 * Math.PI);
                        }
                    }
                    double min = (b > g) ? g : b;
                    min = (min > r) ? r : min;
                    double den2 = r + g + b;
                    if (den2 == 0)
                    {
                        S = 0;
                    }
                    else
                    {
                        S = 1 - 3 * min / den2;
                    }
                    double intensity = (r + g + b) / 3;

                    Color tmp = Color.FromArgb((int)(H * 255), (int)(S * 255), (int)(intensity));
                    bitmap.SetPixel(j, i, tmp);
                }
            }

            img m = new img(bitmap);

            m.Show();
        }
Beispiel #5
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if (draw == false)
            {
                return;
            }

            //画出坐标系
            Graphics g      = e.Graphics;
            Pen      curPen = new Pen(Brushes.Black, 1);

            g.DrawLine(curPen, 50, 240, 320, 240);
            g.DrawLine(curPen, 50, 240, 50, 30);
            g.DrawLine(curPen, 100, 240, 100, 242);
            g.DrawLine(curPen, 150, 240, 150, 242);
            g.DrawLine(curPen, 200, 240, 200, 242);
            g.DrawLine(curPen, 250, 240, 250, 242);
            g.DrawLine(curPen, 300, 240, 300, 242);
            g.DrawString("0", new Font("New Timer", 8), Brushes.Black, new PointF(46, 242));
            g.DrawString("50", new Font("New Timer", 8), Brushes.Black, new PointF(92, 242));
            g.DrawString("100", new Font("New Timer", 8), Brushes.Black, new PointF(139, 242));
            g.DrawString("150", new Font("New Timer", 8), Brushes.Black, new PointF(189, 242));
            g.DrawString("200", new Font("New Timer", 8), Brushes.Black, new PointF(239, 242));
            g.DrawString("250", new Font("New Timer", 8), Brushes.Black, new PointF(289, 242));
            g.DrawLine(curPen, 48, 40, 50, 40);
            g.DrawString("0", new Font("New Timer", 8), Brushes.Black, new PointF(34, 234));
            g.DrawString(maxPixel.ToString(), new Font("New Timer", 8), Brushes.Black, new PointF(18, 34));

            double temp = 0;

            for (int i = 0; i < 256; i++)
            {
                temp = 200.0 * countPixel[i] / maxPixel;
                g.DrawLine(curPen, 50 + i, 240, 50 + i, 240 - (int)temp);
            }

            curPen.Dispose();

            var bitmap1 = new Bitmap(cols, rows);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    int r  = results1[i, j];
                    int gg = results1[i, j];
                    int b  = results1[i, j];
                    bitmap1.SetPixel(j, i, Color.FromArgb(r, gg, b));
                }
            }

            img imgform = new img(bitmap1);

            imgform.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string b     = sbands.Text.ToString();
            int    index = b[b.Length - 1] - 49;

            Bitmap bitmap = new Bitmap(cols, rows); //初始化bitmap

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    int rgbNumber = calculateRange(i, j, index);
                    bitmap.SetPixel(j, i, Color.FromArgb(rgbNumber, rgbNumber, rgbNumber));
                }
            }
            img imgform = new img(bitmap);

            imgform.Show();
        }
        private void 打开jpg图像ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            values = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title  = "打开文件";
            openFileDialog1.Filter = "JPG文件|*.jpg|PNG文件|*.png|BMP文件|*.bmp";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = openFileDialog1.FileName;
                bitmap = (Bitmap)Image.FromFile(path);
                img f = new img(bitmap);
                f.Show();
                string[] name = path.Split('\\');
                string   file = name[name.Length - 1];

                rows               = bitmap.Height;
                cols               = bitmap.Width;
                bands              = 3;
                values             = new int[3, rows, cols];
                byte [,,] tempdata = new byte[3, rows, cols];
                for (int b = 0; b < bands; b++)
                {
                    for (int i = 0; i < rows; i++)
                    {
                        for (int j = 0; j < cols; j++)
                        {
                            Color color = bitmap.GetPixel(j, i);
                            values[0, i, j]   = color.R;
                            values[1, i, j]   = color.G;
                            values[2, i, j]   = color.B;
                            tempdata[0, i, j] = color.R;
                            tempdata[1, i, j] = color.G;
                            tempdata[2, i, j] = color.B;
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string b      = combo3.Text.ToString();
            int    index  = b[b.Length - 1] - 49;
            string c      = combo4.Text.ToString();
            int    index1 = c[c.Length - 1] - 49;

            int[] pre             = new int[256]; // 原来的直方图
            int[] cur             = new int[256]; //规定化的直方图
            int[] predistribution = new int[256]; //离散的概率的分布函数
            int[] curdistribution = new int[256]; //规范化函数的分布函数
            int[,] Min = new int[256, 256];       //插的最小值
            int[]  result = new int[256];         //映射后的结果
            double temp1 = 0, temp2 = 0;

            //统计直方图
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    pre[values[index, i, j]]++;
                }
            }
            //规规定化的函数
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    cur[values1[index1, i, j]]++;
                }
            }
            //计算拉伸后的离散的概率分布函数
            for (int i = 0; i < 256; i++)
            {
                temp1 += (double)pre[i] / (double)(rows * cols);         //概率
                predistribution[i] = (int)(255 * temp1 + 0.5);           //拉伸到0~255上

                temp2 += (double)cur[i] / (double)((0 + 255) * 255 / 2); //概率
                curdistribution[i] = (int)(255 * temp2 + 0.5);           //拉伸到0~255上
            }
            //计算差值,确定关系
            for (int i = 0; i < 256; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    Min[i, j] = System.Math.Abs(predistribution[i] - curdistribution[j]);
                }
            }
            //差值最小的地方建立映射关系
            for (int i = 0; i < 256; i++)
            {
                int min = Min[i, 0];
                int m   = 0;
                for (int j = 1; j < 256; j++)
                {
                    if (Min[i, j] < min)
                    {
                        min = Min[i, j];
                        m   = j;
                    }
                }
                result[i] = m;
            }
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    values[index, i, j] = result[values[index, i, j]];
                }
            }
            //输出图像
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    results1[i, j] = values[index, i, j];
                }
            }
            var bitmap1 = new Bitmap(cols, rows);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    int r = results1[i, j];
                    int g = results1[i, j];
                    int k = results1[i, j];
                    bitmap1.SetPixel(j, i, Color.FromArgb(r, g, k));
                }
            }

            img imgform = new img(bitmap1);

            imgform.Show();
            //统计规定化后的直方图
            resultZFT = new int[256];
            for (int i = 0; i < 256; i++)
            {
                resultZFT[i] = 0;
            }
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    resultZFT[results1[i, j]]++;
                }
            }
            //绘制直方图
            draw = true;
            panel1.Refresh();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double[, ,] newdata = new double[3, rows, cols];

            if (radioButtonNDVI.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]) / ((double)data[3, i, j] + (double)data[2, i, j]);
                        newdata[1, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]) / ((double)data[3, i, j] + (double)data[2, i, j]);
                        newdata[2, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]) / ((double)data[3, i, j] + (double)data[2, i, j]);
                    }
                }
            }
            else if (radioButtonRVI.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        if (data[3, i, j] != 0)
                        {
                            newdata[0, i, j] = ((double)data[3, i, j] / (double)data[2, i, j]);
                            newdata[1, i, j] = ((double)data[3, i, j] / (double)data[2, i, j]);
                            newdata[2, i, j] = ((double)data[3, i, j] / (double)data[2, i, j]);
                        }
                        else
                        {
                            newdata[0, i, j] = 0;
                            newdata[1, i, j] = 0;
                            newdata[2, i, j] = 0;
                        }
                    }
                }
            }
            else if (radioButtonDVI.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]);
                        newdata[1, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]);
                        newdata[2, i, j] = ((double)data[3, i, j] - (double)data[2, i, j]);
                    }
                }
            }
            else if (radioButtonNDWI.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = ((double)data[1, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[1, i, j]);
                        newdata[1, i, j] = ((double)data[1, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[1, i, j]);
                        newdata[2, i, j] = ((double)data[1, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[1, i, j]);
                    }
                }
            }
            else if (radioButtonNDBI.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = ((double)data[4, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[4, i, j]);
                        newdata[1, i, j] = ((double)data[4, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[4, i, j]);
                        newdata[2, i, j] = ((double)data[4, i, j] - (double)data[3, i, j]) / ((double)data[3, i, j] + (double)data[4, i, j]);
                    }
                }
            }
            img form = new img(newdata, rows, cols);

            form.Show();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            ROI roi = new ROI(path);
            int n   = 8;
            int i   = 0;

            int [][] samples = new int[8][];
            samples[0] = new int[291];
            samples[1] = new int[76];
            samples[2] = new int[547];
            samples[3] = new int[221];
            samples[4] = new int[67];
            samples[5] = new int[30];
            samples[6] = new int[562];
            samples[7] = new int[460];
            double[] means = new double[8];
            double[] var2s = new double[8];

            double[,,] newdata = new double[3, rows, cols];

            for (int p = 1; p < 9; p++)
            {
                int t = 0;
                for (int m = 0; m < rows; m++)
                {
                    for (int k = 0; k < cols; k++)
                    {
                        if (roi.type[m, k] == p)
                        {
                            samples[p - 1][t++] = roi.data[m, k];
                        }
                    }
                }
            }
            for (i = 0; i < n; i++)
            {
                means[i] = roi.cal_mean(samples[i], roi.kinds[i]);
                var2s[i] = roi.cal_var2(samples[i], roi.kinds[i], means[i]);
            }

            int [,] color = new int[9, 3];
            color[0, 0]   = 0;
            color[0, 1]   = 0;
            color[0, 2]   = 255;

            color[1, 0] = 0;
            color[1, 1] = 255;
            color[1, 2] = 255;

            color[2, 0] = 0;
            color[2, 1] = 255;
            color[2, 2] = 0;

            color[3, 0] = 0;
            color[3, 1] = 139;
            color[3, 2] = 139;

            color[4, 0] = 255;
            color[4, 1] = 0;
            color[4, 2] = 0;

            color[5, 0] = 255;
            color[5, 1] = 255;
            color[5, 2] = 255;

            color[6, 0] = 176;
            color[6, 1] = 48;
            color[6, 2] = 96;

            color[7, 0] = 0;
            color[7, 1] = 139;
            color[7, 1] = 0;



            for (int m = 0; m < rows; m++)
            {
                for (int k = 0; k < cols; k++)
                {
                    double max_score = 0;
                    int    max_lable = 0;
                    for (i = 0; i < n; i++)
                    {
                        double the_houyan = roi.houyan(means[i], var2s[i], data[0, m, k]);
                        the_houyan = the_houyan * (1.0 / n) / (1.0 / 256);

                        if (the_houyan > max_score)
                        {
                            max_score = the_houyan;
                            max_lable = i;
                        }
                    }
                    data[0, m, k] = color[max_lable, 0];
                    data[1, m, k] = color[max_lable, 1];
                    data[2, m, k] = color[max_lable, 2];

                    newdata[0, m, k] = color[max_lable, 0];
                    newdata[1, m, k] = color[max_lable, 1];
                    newdata[2, m, k] = color[max_lable, 2];
                }
            }
            img form = new img(newdata, rows, cols);

            form.Show();
        }
        private void kT变换ToolStripMenuItem_Click(object sender, EventArgs e)
        {//K-T变换-葛婧琳
            //img(double[, ,] data, int rows, int cols)
            if (bands != 7)
            {
                MessageBox.Show("错误!");
                return;
            }
            double[, ,] KTvalue = new double[4, rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    KTvalue[0, i, j] = 0.2909 * values[0, i, j] + 0.2493 * values[1, i, j] + 0.4806 * values[2, i, j] + 0.5568 * values[3, i, j] + 0.4438 * values[4, i, j] + 0.1706 * values[6, i, j] + 10.3695;
                    KTvalue[1, i, j] = (-0.2728) * values[0, i, j] - 0.2174 * values[1, i, j] - 0.5508 * values[2, i, j] + 0.7221 * values[3, i, j] + 0.0733 * values[4, i, j] - 0.1648 * values[6, i, j] - 0.7310;
                    KTvalue[2, i, j] = 0.1446 * values[0, i, j] + 0.1761 * values[1, i, j] + 0.3322 * values[2, i, j] + 0.3396 * values[3, i, j] - 0.6210 * values[4, i, j] - 0.4186 * values[6, i, j] - 3.3828;
                    KTvalue[3, i, j] = 0.8461 * values[0, i, j] - 0.0731 * values[1, i, j] - 0.4640 * values[2, i, j] - 0.0032 * values[3, i, j] - 0.0492 * values[4, i, j] + 0.0119 * values[6, i, j] + 0.7879;
                }
            }

            double[, ,] Brightness = new double[3, rows, cols]; //亮度
            double[, ,] Greenness  = new double[3, rows, cols]; //绿度
            double[, ,] Wetness    = new double[3, rows, cols]; //湿度
            double[, ,] Hazeness   = new double[3, rows, cols]; //霾

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    //亮度
                    Brightness[0, i, j] = KTvalue[0, i, j];
                    Brightness[1, i, j] = KTvalue[0, i, j];
                    Brightness[2, i, j] = KTvalue[0, i, j];
                    //绿度
                    Greenness[0, i, j] = KTvalue[1, i, j];
                    Greenness[1, i, j] = KTvalue[1, i, j];
                    Greenness[2, i, j] = KTvalue[1, i, j];
                    //湿度
                    Wetness[0, i, j] = KTvalue[2, i, j];
                    Wetness[1, i, j] = KTvalue[2, i, j];
                    Wetness[2, i, j] = KTvalue[2, i, j];
                    //霾
                    Hazeness[0, i, j] = KTvalue[3, i, j];
                    Hazeness[1, i, j] = KTvalue[3, i, j];
                    Hazeness[2, i, j] = KTvalue[3, i, j];
                }
            }

            KT_Bright kt_B = new KT_Bright(Brightness, rows, cols);

            kt_B.Show();
            KT_Green kt_G = new KT_Green(Greenness, rows, cols);

            kt_G.Show();
            KT_Wet kt_W = new KT_Wet(Wetness, rows, cols);

            kt_W.Show();
            KT_haze kt_H = new KT_haze(Hazeness, rows, cols);

            kt_H.Show();
            img kt = new img(KTvalue, rows, cols);

            kt.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int index = comboBox1.SelectedIndex;
            int size  = Convert.ToInt32(textBox1.Text);//窗口大小
            int off   = size / 2;

            if (index == -1)
            {
                MessageBox.Show("请输入波段!");
                return;
            }

            double[, ,] newdata = new double[3, rows, cols];

            if (radioButtonMean.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        List <double> res = new List <double>();
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                res.Add(data[index, i + a, j + b]);
                            }
                        }
                        double r = res.Sum() / res.Count;
                        newdata[0, i, j] = r;
                        newdata[1, i, j] = r;
                        newdata[2, i, j] = r;
                    }
                }
            }
            else if (radioButtonMax.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        List <double> res = new List <double>();
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                res.Add(data[index, i + a, j + b]);
                            }
                        }
                        double r = res.Max();
                        newdata[0, i, j] = r;
                        newdata[1, i, j] = r;
                        newdata[2, i, j] = r;
                    }
                }
            }
            else if (radioButtonMin.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        List <double> res = new List <double>();
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                res.Add(data[index, i + a, j + b]);
                            }
                        }
                        double r = res.Min();
                        newdata[0, i, j] = r;
                        newdata[1, i, j] = r;
                        newdata[2, i, j] = r;
                    }
                }
            }
            else if (radioButtonMedian.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        List <double> res = new List <double>();
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                res.Add(data[index, i + a, j + b]);
                            }
                        }
                        double r = res[res.Count / 2];
                        newdata[0, i, j] = r;
                        newdata[1, i, j] = r;
                        newdata[2, i, j] = r;
                    }
                }
            }
            else if (radioButtonTIDU.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        List <double> res = new List <double>();
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                if (a == 0 && b == 0)
                                {
                                    continue;
                                }
                                if (data[index, i, j] == data[index, i + a, j + b])
                                {
                                    continue;
                                }
                                res.Add(1.0 / Math.Abs(((double)data[index, i, j] - (double)data[index, i + a, j + b])));
                            }
                        }

                        double c = 2 * res.Sum();
                        double r = 0;
                        int    x = 0;
                        for (int a = -off; a <= off; a++)
                        {
                            if (i + a < 0 || i + a >= rows)
                            {
                                continue;
                            }
                            for (int b = -off; b <= off; b++)
                            {
                                if (j + b < 0 || j + b >= cols)
                                {
                                    continue;
                                }
                                if (a == 0 && b == 0)
                                {
                                    continue;
                                }
                                if (data[index, i, j] == data[index, i + a, j + b])
                                {
                                    continue;
                                }
                                r += (double)data[index, i + a, j + b] * res[x] / c;
                                x++;
                            }
                        }
                        r += (double)data[index, i, j] * 0.5;

                        newdata[0, i, j] = r;
                        newdata[1, i, j] = r;
                        newdata[2, i, j] = r;
                    }
                }
            }

            img form = new img(newdata, rows, cols);

            form.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int index1 = comboBox1.SelectedIndex;
            int index2 = comboBox2.SelectedIndex;

            if (index1 == -1 || index2 == -1)
            {
                MessageBox.Show("请输入波段!");
                return;
            }

            double[, ,] newdata = new double[3, rows, cols];

            //大于
            if (radioButtonDayu.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        if (data[index1, i, j] > data[index2, i, j])
                        {
                            newdata[0, i, j] = 255;
                            newdata[1, i, j] = 255;
                            newdata[2, i, j] = 255;
                        }
                        else
                        {
                            newdata[0, i, j] = 0;
                            newdata[1, i, j] = 0;
                            newdata[2, i, j] = 0;
                        }
                    }
                }
            }
            //小于
            else if (radioButtonXiaoyu.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        if (data[index1, i, j] < data[index2, i, j])
                        {
                            newdata[0, i, j] = 255;
                            newdata[1, i, j] = 255;
                            newdata[2, i, j] = 255;
                        }
                        else
                        {
                            newdata[0, i, j] = 0;
                            newdata[1, i, j] = 0;
                            newdata[2, i, j] = 0;
                        }
                    }
                }
            }
            //等于
            else if (radioButtonDengyu.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        if (data[index1, i, j] == data[index2, i, j])
                        {
                            newdata[0, i, j] = 255;
                            newdata[1, i, j] = 255;
                            newdata[2, i, j] = 255;
                        }
                        else
                        {
                            newdata[0, i, j] = 0;
                            newdata[1, i, j] = 0;
                            newdata[2, i, j] = 0;
                        }
                    }
                }
            }

            img form = new img(newdata, rows, cols);

            form.Show();
        }
Beispiel #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            int index1 = comboBox1.SelectedIndex;
            int index2 = comboBox2.SelectedIndex;

            if (index1 == -1 || index2 == -1)
            {
                MessageBox.Show("请输入波段!");
                return;
            }

            double[, ,] newdata = new double[3, rows, cols];

            //加法
            if (radioButton1.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = (data[index1, i, j] + data[index2, i, j]) / 2;
                        newdata[1, i, j] = (data[index1, i, j] + data[index2, i, j]) / 2;
                        newdata[2, i, j] = (data[index1, i, j] + data[index2, i, j]) / 2;
                    }
                }
            }
            //减法
            else if (radioButton2.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = (data[index1, i, j] - data[index2, i, j]);
                        newdata[1, i, j] = (data[index1, i, j] - data[index2, i, j]);
                        newdata[2, i, j] = (data[index1, i, j] - data[index2, i, j]);
                    }
                }
            }
            //乘法
            else if (radioButton3.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        newdata[0, i, j] = (data[index1, i, j] * data[index2, i, j]);
                        newdata[1, i, j] = (data[index1, i, j] * data[index2, i, j]);
                        newdata[2, i, j] = (data[index1, i, j] * data[index2, i, j]);
                    }
                }
            }
            //除法
            else if (radioButton4.Checked)
            {
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < cols; j++)
                    {
                        if (data[index2, i, j] != 0)
                        {
                            newdata[0, i, j] = ((double)data[index1, i, j] / (double)data[index2, i, j]);
                            newdata[1, i, j] = ((double)data[index1, i, j] / (double)data[index2, i, j]);
                            newdata[2, i, j] = ((double)data[index1, i, j] / (double)data[index2, i, j]);
                        }
                        else
                        {
                            newdata[0, i, j] = 0;
                            newdata[1, i, j] = 0;
                            newdata[2, i, j] = 0;
                        }
                    }
                }
            }
            img form = new img(newdata, rows, cols);

            form.Show();
        }