Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            threshold = (byte)numericUpDown1.Value;
            long i, j, pos;

            tempImageB = new byte[pImage.MBData];
            for (i = 0; i < pImage.MHeight; i++)
            {
                for (j = 0; j < pImage.MWidth; j++)
                {
                    pos             = i * pImage.MBWidth + j;
                    tempImageB[pos] = pImage.ImageB[pos];
                    if (pImage.ImageB[pos] >= threshold)
                    {
                        pImage.ImageB[pos] = 255;
                    }
                    else if (pImage.ImageB[pos] < threshold)
                    {
                        pImage.ImageB[pos] = 0;
                    }
                }
            }
            pImage.putBitMapData();
            mainFF.Refresh();
            try
            {
                mainFF.HistForm.Refresh();
                mainFF.GTFrom.Refresh();
            }
            catch { }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            long   i, j, pos;
            double cosA, sinA;

            sumA = sumA + (double)numericUpDown1.Value;
            double x0 = (long)(pImage.MWidth - 1) / 2;
            double y0 = (long)(pImage.MHeight - 1) / 2;
            double Pi = Math.PI;

            cosA           = Math.Cos(sumA * Pi / 180);
            sinA           = Math.Sin(sumA * Pi / 180);
            tspBar.Maximum = (int)(pImage.MBData);
            tspBar.Minimum = 0;
            for (i = 0; i < pImage.MHeight; i++)
            {
                for (j = 0; j < pImage.MWidth; j++)
                {
                    pos          = i * pImage.MBWidth + j;
                    tspBar.Value = (int)pos;
                    if (radioButton1.Checked == true)
                    {
                        pImage.ImageB[pos] = nearestEle(cosA, sinA, i, j, x0, y0);
                    }
                    if (radioButton2.Checked == true)
                    {
                        pImage.ImageB[pos] = bilinearInterpolation(cosA, sinA, i, j, x0, y0);
                    }
                }
            }
            pImage.putBitMapData();
            tspBar.Value = 0;
            mainFF.Refresh();
        }
Beispiel #3
0
 private void pictureRGB_Paint(object sender, PaintEventArgs e)
 {
     pImage.getXView = pictureRGB.Width;
     pImage.getYView = pictureRGB.Height;
     for (i = 0; i < pImage.MHeight; i++)
     {
         for (j = 0; j < pImage.MWidth; j++)
         {
             pos = i * pImage.MCWidth + 3 * j;
             pImage.ImageC[pos]     = tempImageC[pos];
             pImage.ImageC[pos + 1] = tempImageC[pos + 1];
             pImage.ImageC[pos + 2] = tempImageC[pos + 2];
         }
     }
     pImage.ImageC = tempImageC;
     pImage.putBitMapData();
     e.Graphics.Clear(Color.White);
     pImage.zoomImage(e.Graphics);
 }
Beispiel #4
0
        public void buttonApply_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < pImage.MBWidth * pImage.MHeight; i++)
            {
                pImage.ImageB[i] = grayByte[i];
            }
            pImage.putBitMapData();

            onMainRefresh(this, new EventArgs());        //发送事件

            afterHistPanel.Refresh();

            preHistPanel.Refresh();

            transFormPanel.Refresh();
        }
Beispiel #5
0
        private void Convolution_Click(object sender, EventArgs e)
        {
            int  order = Convert.ToInt32(numericUpDown1.Value);
            int  denominator = getDenominator();
            long pos, conPos;
            int  i, j;
            int  a, b;

            tempImageB = new byte[pImage.MBData];
            //备份原始数据
            for (i = 0; i < pImage.MHeight; i++)
            {
                for (j = 0; j < pImage.MWidth; j++)
                {
                    pos             = i * pImage.MBWidth + j;
                    tempImageB[pos] = pImage.ImageB[pos];
                }
            }

            //卷积处理,不考虑边界问题
            int    conSum = 0;
            byte   conResult;
            double tempResult = 0;

            byte[,] tempArr;
            mainFF.TspBar.Maximum = (int)(pImage.MWidth * pImage.MHeight);
            mainFF.TspBar.Minimum = 0;
            List <double> conSumList = new List <double>();

            for (i = order / 2; i < pImage.MHeight - order / 2; i++)
            {
                for (j = order / 2; j < pImage.MWidth - order / 2; j++)
                {
                    pos = i * pImage.MBWidth + j;
                    mainFF.TspBar.Value = (int)pos;
                    switch (order)
                    {
                    case 1:
                    {
                        conSum = int.Parse(mTextBox[40].Text) * tempImageB[pos];
                        break;
                    }

                    case 3:
                    {
                        conSum  = 0;
                        tempArr = new byte[3, 3];
                        for (a = 0; a < 3; a++)
                        {
                            for (b = 0; b < 3; b++)
                            {
                                pos           = (i + a - 1) * pImage.MBWidth + j + b - 1;
                                conPos        = (a + 3) * 9 + b + 3;
                                tempArr[a, b] = tempImageB[pos];
                                conSum        = conSum + tempArr[a, b] * int.Parse(mTextBox[conPos].Text);
                            }
                        }
                        break;
                    }

                    case 5:
                    {
                        conSum  = 0;
                        tempArr = new byte[5, 5];
                        for (a = 0; a < 5; a++)
                        {
                            for (b = 0; b < 5; b++)
                            {
                                pos           = (i + a - 2) * pImage.MBWidth + j + b - 2;
                                conPos        = (a + 2) * 9 + b + 2;
                                tempArr[a, b] = tempImageB[pos];
                                conSum        = conSum + tempArr[a, b] * int.Parse(mTextBox[conPos].Text);
                            }
                        }
                        break;
                    }

                    case 7:
                    {
                        conSum  = 0;
                        tempArr = new byte[7, 7];
                        for (a = 0; a < 7; a++)
                        {
                            for (b = 0; b < 7; b++)
                            {
                                pos           = (i + a - 3) * pImage.MBWidth + j + b - 3;
                                conPos        = (a + 1) * 9 + b + 1;
                                tempArr[a, b] = tempImageB[pos];
                                conSum        = conSum + tempArr[a, b] * int.Parse(mTextBox[conPos].Text);
                            }
                        }
                        break;
                    }

                    case 9:
                    {
                        conSum  = 0;
                        tempArr = new byte[9, 9];
                        for (a = 0; a < 9; a++)
                        {
                            for (b = 0; b < 9; b++)
                            {
                                pos           = (i + a - 4) * pImage.MBWidth + j + b - 4;
                                conPos        = a * 9 + b;
                                tempArr[a, b] = tempImageB[pos];
                                conSum        = conSum + tempArr[a, b] * int.Parse(mTextBox[conPos].Text);
                            }
                        }
                        break;
                    }

                    default:
                        break;
                    }
                    conSumList.Add((double)conSum);
                    try { tempResult = conSum / (int.Parse(textBox1.Text)); }
                    catch { }
                    //灰度超限处理方式1:
                    if (checkBox1.Checked == false)
                    {
                        if (tempResult < 0)
                        {
                            tempResult = 0;
                        }
                        else if (tempResult > 255)
                        {
                            tempResult = 255;
                        }
                        conResult          = (byte)tempResult;
                        pos                = i * pImage.MBWidth + j;
                        pImage.ImageB[pos] = conResult;
                    }
                }
            }
            //灰度超限处理方式2,线性插值:
            double Gmin = double.MaxValue, Gmax = 0;
            int    tempIndex = 0;
            byte   g         = 0;

            if (checkBox1.Checked == true)
            {
                for (i = 0; i < conSumList.Count; i++)
                {
                    if (Gmin > conSumList[i])
                    {
                        Gmin = conSumList[i];
                    }
                    if (Gmax < conSumList[i])
                    {
                        Gmax = conSumList[i];
                    }
                }
                for (i = order / 2; i < pImage.MHeight - order / 2; i++)
                {
                    for (j = order / 2; j < pImage.MWidth - order / 2; j++)
                    {
                        pos = (i + order / 2) * pImage.MBWidth + j + order / 2;
                        g   = (byte)(((conSumList[tempIndex] - Gmin) / (Gmax - Gmin)) * 255);
                        pImage.ImageB[pos] = g;
                        tempIndex++;
                    }
                }
            }
            mainFF.TspBar.Value = 0;
            pImage.putBitMapData();
            mainFF.Refresh();
            try
            {
                mainFF.GTFrom.Refresh();
                mainFF.HistForm.Refresh();
            }
            catch (System.Exception ex) { }
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            long i, j, pos;

            tempImageB = new byte[pImage.MBData];
            for (i = 0; i < pImage.MHeight; i++)
            {
                for (j = 0; j < pImage.MWidth; j++)
                {
                    pos             = i * pImage.MBWidth + j;
                    tempImageB[pos] = pImage.ImageB[pos];
                }
            }
            double        tempGra  = 0;
            byte          Gra      = 0;
            List <double> tempList = new List <double>();

            for (i = 0; i < pImage.MHeight - 1; i++)
            {
                for (j = 0; j < pImage.MWidth - 1; j++)
                {
                    pos = i * pImage.MBWidth + j;
                    //不同的梯度
                    //i表示X轴方向,j表示Y轴方向
                    if (radioButton1.Checked == true)
                    {
                        tempGra = Math.Abs(tempImageB[pos + pImage.MBWidth] - tempImageB[pos]) + Math.Abs(tempImageB[pos + 1] - tempImageB[pos]);
                    }
                    if (radioButton2.Checked == true)
                    {
                        tempGra = Math.Max(Math.Abs(tempImageB[pos + pImage.MBWidth] - tempImageB[pos]), Math.Abs(tempImageB[pos + 1] - tempImageB[pos]));
                    }
                    if (radioButton3.Checked == true)
                    {
                        tempGra = Math.Sqrt(Math.Pow(tempImageB[pos + pImage.MBWidth] - tempImageB[pos], 2) +
                                            Math.Pow(tempImageB[pos + 1] - tempImageB[pos], 2));
                    }
                    if (radioButton4.Checked == true)
                    {
                        tempGra = Math.Abs(tempImageB[pos + pImage.MBWidth + 1] - tempImageB[pos]) +
                                  Math.Abs(tempImageB[pos + 1] - tempImageB[pos + pImage.MBWidth]);
                    }
                    if (radioButton5.Checked == true)
                    {
                        tempGra = Math.Max(Math.Abs(tempImageB[pos + pImage.MBWidth + 1] - tempImageB[pos]),
                                           Math.Abs(tempImageB[pos + 1] - tempImageB[pos + pImage.MBWidth]));
                    }
                    if (radioButton6.Checked == true)
                    {
                        tempGra = Math.Sqrt(Math.Pow(tempImageB[pos + pImage.MBWidth + 1] - tempImageB[pos], 2) +
                                            Math.Pow(tempImageB[pos + 1] - tempImageB[pos + pImage.MBWidth], 2));
                    }
                    tempList.Add(tempGra);
                    //超限处理方式1:
                    if (checkBox1.Checked == false)
                    {
                        if (tempGra > 255)
                        {
                            tempGra = 255;
                        }
                        if (tempGra < 0)
                        {
                            tempGra = 0;
                        }
                        Gra = (byte)tempGra;
                        pImage.ImageB[pos] = Gra;
                    }
                }
            }
            //超限处理方法2:灰度超限线性约束
            double minGra = double.MaxValue, maxGra = 0;
            int    a, index = 0;

            if (checkBox1.Checked == true)
            {
                for (a = 0; a < tempList.Count; a++)
                {
                    if (minGra > tempList[a])
                    {
                        minGra = tempList[a];
                    }
                    if (maxGra < tempList[a])
                    {
                        maxGra = tempList[a];
                    }
                }
                for (i = 0; i < pImage.MHeight - 1; i++)
                {
                    for (j = 0; j < pImage.MWidth - 1; j++)
                    {
                        pos = i * pImage.MBWidth + j;
                        pImage.ImageB[pos] = (byte)(((tempList[index] - minGra) / (maxGra - minGra)) * 255);
                        index++;
                    }
                }
            }
            pImage.putBitMapData();
            mainFF.Refresh();
        }