Example #1
0
        private void 八邻域函数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Apicturegrayinformation[] ApicturegrayinformationArray;
            ArrayList neighbourhood = new ArrayList();

            //ApicturegrayinformationArray = new Apicturegrayinformation[0];
            //StreamReader rd = File.OpenText("data.txt");
            //string s = rd.ReadLine();
            //string[] ss = s.Split(',');


            //int row = int.Parse(ss[0]); //行数
            //int col = int.Parse(ss[1]);  //每行数据的个数

            //double[,] p1 = new double[row, col]; //数组

            //for (int i = 0; i < row; i++)  //读入数据并赋予数组
            //{
            //    string line = rd.ReadLine();
            //    string[] data = line.Split(',');
            //    for (int j = 0; j < col; j++)
            //    {
            //        Array.Resize(ref ApicturegrayinformationArray, ApicturegrayinformationArray.Length + 1);
            //        ApicturegrayinformationArray[i].currentgrayValue = byte.Parse(data[j]);
            //    }
            //}
            functionFun.racepossibleEdgePointIndexFunc(5120, 5120, 11884921, ref neighbourhood);
        }
        // 跳点不去震动函数:piontsNoVibrationcorrection()
        public void piontsNoVibrationcorrection(OpticMeasureClass opticFlowFunc)
        {
            int PointArraylength;                 //第i张母板点坐标数组长度

            CalculateWidthAndHightOfPointImage(); //计算母板点数组的长和宽

            trian = new Triangulation();          // 创建三角剖分对象

            //call装顶点表函数,装母板顶点表
            trian.GetTrianglerVertexArrayFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, StepValue);

            PointArraylength = trian.TriangleVertexArray.Length;
            packedPiontImageCoorditionArrayFunction(opticFlowFunc, PointArraylength);//装母板点数组

            //销毁trian对象
            trian.Destroy();
            GC.Collect();


            //=============待匹配照片循环 计算==================
            for (int k = 0; k < length; k++)
            {
                CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k];//待匹配照片在结果数组中的索引

                CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k]].PictureLujin);

                CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray);        //创建 匹配照片灰度数组

                CreatArray.creatPictureDlateGreyArray(CurrentPictureBitmap, ref PictureDlateGreyArray);     //创建灰度差值数组

                functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装载 匹配照片灰度数组

                //CreatArray.creatHomologousPointsDisplacementsArray(PointArraylength,ref HomologousPointsDisplacementsArray);//创建位移场数组

                CreatArray.creatPointsResultArray(opticFlowFunc, CurPictureIndex, RefPicturePointArrayHight, RefPicturePointArrayWidth);//创建结果数组

                // 求母板照片和待匹配照片灰度差
                for (int j = 0; j < CurrentPictureGreyArray.Length; j++)
                {
                    PictureDlateGreyArray[j] = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[j].OrigingrayValue;
                }

                //清数组
                Array.Resize(ref CurrentPictureGreyArray, 0);


                //====母板点数组循环计算=========
                for (int j = 0; j < PointArraylength; j++)
                {
                    //装载点坐标数组
                    opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].X;
                    opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].Y;

                    //装八邻域数组
                    functionFun.racepossibleEdgePointIndexFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray[j], ref CurrentPixtNeighbourArray);

                    //soble算子
                    Grad.X = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]];

                    Grad.Y = -2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] + 2 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]];

                    //Prewitt算子
                    //Grad.X = 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[2]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[6]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]];

                    //Grad.Y = -1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[0]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[1]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[3]] +1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[4]] + 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[5]] - 1 * PictureDlateGreyArray[(int)CurrentPixtNeighbourArray[7]];

                    opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].Grad = Grad;
                }

                // 清除数组
                Array.Resize(ref PictureDlateGreyArray, 0);
                CurrentPixtNeighbourArray.Clear();
            }
            // 清除数组
            Array.Resize(ref ReferencePictureGreyArray, 0);
        }