//像素去震动函数:pixelWithVibrationcorrection() public void pixelWithVibrationcorrection(OpticMeasureClass opticFlowFunc) { int InReferencePictureIndex = 0;//在母板系照片灰度中的索引 Mt = new CSharpAlgorithm.Algorithm.MatrixOfAlgorithm(); //call读识标记点函数,将母板的标记点识取出来 functionFun.ReadMarkPointsFunc(); //将第i张母板标记点存到PictureOpticflowDataResultArray[ReferencePictureDataArray[i].ReferencePictureIndex].PictureMarkpointsArray opticFlowFunc.PictureOpticflowDataResultArray[opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].ReferencePictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; CreatArray.creatInReferencePicturePixXYArray(RefPictureWidth * RefPictureHight, ref InReferencePicturePixXYArray);//像素经过旋转平移后在母板坐标系下的坐标数组 //=============待匹配照片循环================ for (int k = 0; k < length; k++) { CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k]; //待匹配照片在结果数组中的索引 CreatArray.creatPixelResultArray(opticFlowFunc, CurPictureIndex, RefPictureHight, RefPictureWidth); //创建像素光流结果数组 //装待匹配照片灰度数组 CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureLujin); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); //创建待匹配照片灰度数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装载待匹配照片灰度数组 functionFun.ReadMarkPointsFunc(); //call识标记点函数 //将第K张待匹配照片标记点到光流结果数组中 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; // call 求旋转平移矩阵函数,得到母板照片旋转平移到当前待匹配照片上的旋转平移矩阵函数 functionFun.GetRotationMatrixAndTranslationFunc(ref Mt); //=============待匹配照片像素循环 像素流计算(去震动像素直接相减)================== for (int j = 0; j < CurrentPictureGreyArray.Length; j++) { // 得到旋转平移后的坐标 functionFun.Get2DzuobiaoInReferencePictureFunc(opticFlowFunc, CurrentPictureBitmap, Mt, T, InReferencePictureDataArrayIndex, j, RefPictureWidth * RefPictureHight, ref InReferencePicturePixXYArray); //计算编号 functionFun.CalculateIndexOfInReferencePictureFunc(RefPictureHight, RefPictureWidth, j, InReferencePicturePixXYArray, ref InReferencePictureIndex); //求灰度差 直接相减 Greyvalue = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[InReferencePictureIndex].OrigingrayValue; //将结果存到结果数组中 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPixelArray[j].Greyvalue = Greyvalue; } //清空待匹配照片灰度数组 Array.Resize(ref CurrentPictureGreyArray, 0); } //销毁对象 functionFun = null; //清空母版照片灰度数组 Array.Resize(ref ReferencePictureGreyArray, 0); }
//将母板点坐标(x,y)存到母板点数组中函数: packedPiontImageCoorditionArrayFunction() public void packedPiontImageCoorditionArrayFunction(OpticMeasureClass opticFlowFunc, int PointArraylength) { //判断母板点数组是否建立 if (opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray == null) { opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray = new Vector2[PointArraylength]; } else { Array.Resize(ref opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray, PointArraylength); } //判断母板点索引数组是否建立 if (opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray == null) { opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray = new int[PointArraylength]; } else { Array.Resize(ref opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray, PointArraylength); } //将母板点坐标(x,y)存到母板点数组中 for (int n = 0; n < PointArraylength; n++) { opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[n].X = trian.TriangleVertexArray[n].D2V1.X; opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[n].Y = trian.TriangleVertexArray[n].D2V1.Y; opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray[n] = trian.TriangleVertexArray[n].Index; } }
//像素不去震动函数:pixelNoVibrationcorrection() public void pixelNoVibrationcorrection(OpticMeasureClass opticFlowFunc) { //=============待匹配照片循环================== for (int k = 0; k < length; k++) { CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k];//待匹配照片在结果数组中的索引 CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureLujin); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); // 创建匹配照片的灰度数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); // 装待匹配照片的灰度数组 CreatArray.creatPixelResultArray(opticFlowFunc, CurPictureIndex, RefPictureHight, RefPictureWidth); //像素结果数组创建 //=============照片像素循环 像素流计算(像素直接相减)================== for (int j = 0; j < CurrentPictureGreyArray.Length; j++) { //Greyvalue = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[j].OrigingrayValue; //Greyvalue = CurrentPictureGreyArray[j].OrigingrayValue / ReferencePictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[j].OrigingrayValue/ReferencePictureGreyArray[j].OrigingrayValue; //Greyvalue = CurrentPictureGreyArray[j].OrigingrayValue / ReferencePictureGreyArray[j].OrigingrayValue - CurrentPictureGreyArray[j+1].OrigingrayValue / ReferencePictureGreyArray[j].OrigingrayValue; //将结果存到结果数组中 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPixelArray[j].Greyvalue = Greyvalue; } //清空数组 Array.Resize(ref CurrentPictureGreyArray, 0); } //清数数组 Array.Resize(ref ReferencePictureGreyArray, 0); // 销毁functionFun functionFun = null; }
CreatArray CreatArray = new CreatArray(); //创建数组对象 public void Flow_Diagnostics_Run_Refine(OpticMeasureClass currentOMC) { //------定义局部变量------------------------------- int[] window_shifting = new int[4]; //装载矩形窗的左上角和右下角点的坐标 数组 int size_average = 3; // 卷积核大小,即邻域大小 byte thresholding = 20; //得到阈值 byte dwtSeries = 2; //得到小波分解级数 byte flagFilter = 0; //得到应用何种小波基和何种阈值法(0-5) //------装待匹配照片灰度数组------------------------------------------- for (int i = 0; i < currentOMC.readFileNames.Length - 1; i++) { //模板照片灰度数组 ReferencePictureBitmap = (Bitmap)Image.FromFile(currentOMC.readFileNames[i]); CreatArray.creatPictureGreyArray(ReferencePictureBitmap, ref ReferencePictureGreyArray); functionFun.LoadgrayValuesArrayForMatch(ReferencePictureBitmap, ref ReferencePictureGreyArray); //带匹配照片灰度数组 CurrentPictureBitmap = (Bitmap)Image.FromFile(currentOMC.readFileNames[i + 1]); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); //创建待匹配照片灰度数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装载待匹配照片灰度数组 } //-------------选择需要处理的区域(功能空缺)------------------------------------- //---------------------光强修正------------------------------------------------- //先将原始数组拷贝 Im1 = new Apicturegrayinformation[ReferencePictureGreyArray.Length]; Im2 = new Apicturegrayinformation[CurrentPictureGreyArray.Length]; Array.Copy(ReferencePictureGreyArray, Im1, ReferencePictureGreyArray.Length); Array.Copy(CurrentPictureGreyArray, Im2, CurrentPictureGreyArray.Length); //functionFun.correction_illumination(ReferencePictureBitmap, ReferencePictureGreyArray, CurrentPictureGreyArray, window_shifting, size_average, ref Im2); //------------图片预处理(小波变换、高斯低通滤波)----------------------------------- //---先 小波变换------------- Apicturegrayinformation[] Im1WaveletArray = new Apicturegrayinformation[Im1.Length]; //Im1 小波变换后的数组(大小减半) Apicturegrayinformation[] Im2WaveletArray = new Apicturegrayinformation[Im2.Length]; //Im2 小波变换后的数组(大小减半) functionFun.WaveletFun(ReferencePictureBitmap, Im1, thresholding, dwtSeries, flagFilter, ref Im1WaveletArray); // 模板照片小波变换 functionFun.WaveletFun(CurrentPictureBitmap, Im2, thresholding, dwtSeries, flagFilter, ref Im2WaveletArray); // 匹配照片小波变换 //--再 高斯低通滤波----------------- double sigma = 1.5; //均方值 Apicturegrayinformation[] Im1GaussrasultGrayArray = new Apicturegrayinformation[Im1.Length]; //Im1 高斯滤波后数组 Apicturegrayinformation[] Im2GaussrasultGrayArray = new Apicturegrayinformation[Im2.Length]; //Im2 高斯滤波后数组 //调用高斯滤波函数 functionFun.GaussFunc(Im1WaveletArray, sigma, ref Im1GaussrasultGrayArray); functionFun.GaussFunc(Im2WaveletArray, sigma, ref Im2GaussrasultGrayArray); //------------光流计算----------------------------- }
//创建点光流结果数组 public void creatPointsResultArray(OpticMeasureClass opticFlowFunc, int CurPictureIndex, int RefPictureHight, int RefPictureWidth) { if (opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray == null) { opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray = new OpticflowResultForPointsGrey[RefPictureWidth * RefPictureHight]; } else { Array.Resize(ref opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray, RefPictureWidth * RefPictureHight); } }
public void Init(OpticMeasureClass _opmc, GetOpticflowResultOfSingleReferencePicture _singleOpticFlow) { compVector2 = _singleOpticFlow; currentEdit = _opmc; pictureVector2.Size = panelVector2.Size; drawVector2.CanvasSize = new Point(this.panelVector2.Width, panelVector2.Height); bool succ; succ = pamater.GetDefaultSetting(ref pamater.zbDrawParamater); if (succ == false) { pamater.zbDrawParamater.Init(); } // 如果参数表读取错误,则:取参数的初始值 viewImage = new Image2DView(pictureVector2, panelVector2, pamater); TreeNode node; string filename; int ppindex = -1; if (currentEdit.readFileNames != null) { for (int i = 0; i < currentEdit.readFileNames.Length; i++) { ppindex = i;//Convert.ToInt32(currentEdit.WaitMatchPictureIndexArray[i].ToString()); filename = currentEdit.readFileNames[ppindex]; node = new TreeNode(); node.Name = filename; node.Text = imageCommon.getFileNameOnly(filename); node.Tag = ppindex.ToString(); // 该照片 在数组中的序号 filetree.Nodes.Add(node); } if (filetree.Nodes.Count > 0) { filetree.SelectedNode = filetree.Nodes[0]; } } }
bool IsVibrationcorrection; //是否去震动 //单母板光流计算函数 public void GetOpticflowResultOfSingleReferencePictureFunc(OpticMeasureClass opticFlowFunc, int _InReferencePictureDataArrayIndex) { int CalcuateModer; //计算模式 InReferencePictureDataArrayIndex = _InReferencePictureDataArrayIndex; //第i张母板索引号为输入量 length = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray.Length; //第i张母板待匹配照片数组长度 StepValue = opticFlowFunc.StepValue; //像素点间间隔 IsStep = opticFlowFunc.IsStep; //=true表示需要跳点,跳点间隔=StepValue IsVibrationcorrection = opticFlowFunc.IsVibrationcorrection; //是否去震动 //----修改--switch case 判断四种情况--- //判断计算模型 if (IsStep == false & IsVibrationcorrection == false) { CalcuateModer = 0; } else if (IsStep == false & IsVibrationcorrection == true) { CalcuateModer = 1; } else if (IsStep == true & IsVibrationcorrection == false) { CalcuateModer = 2; } else { CalcuateModer = 3; } if (opticFlowFunc.ReferencePictureDataArray == null) { MessageBox.Show("还没有读入照片!"); } else { //装母板的灰度数组 functionFun = new FunctionFuncCalss(); ReferencePictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].ReferencePictureLuJin);//得到母板点的Bitmap RefPictureHight = ReferencePictureBitmap.Height; RefPictureWidth = ReferencePictureBitmap.Width; CreatArray.creatPictureGreyArray(ReferencePictureBitmap, ref ReferencePictureGreyArray); //创建母板灰度数组 functionFun.LoadgrayValuesArrayForMatch(ReferencePictureBitmap, ref ReferencePictureGreyArray); //装载母板灰度数组 //根据计算模板选择相应的光流计算 switch (CalcuateModer) { case 0: //逐像素不去震动 pixelNoVibrationcorrection(opticFlowFunc); break; case 1: //逐像素去震动 pixelWithVibrationcorrection(opticFlowFunc); break; case 2: //跳点不去震动 piontsNoVibrationcorrection(opticFlowFunc); break; case 3: //跳点去震动 piontsWithVibrationcorrection(opticFlowFunc); break; } } }
//跳点去震动函数:piontsWithVibrationcorrection() public void piontsWithVibrationcorrection(OpticMeasureClass opticFlowFunc) { int PointArraylength; //第i张母板点坐标数组长度 int InReferencePictureIndex = 0; //在母板系照片灰度中的索引 int s = 0; //点序号 Mt = new CSharpAlgorithm.Algorithm.MatrixOfAlgorithm(); trian = new Triangulation(); // 创建三角剖分对象 CalculateWidthAndHightOfPointImage(); //计算母板点数组的长和宽 //call装顶点表函数,装母板顶点表 trian.GetTrianglerVertexArrayFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, StepValue); PointArraylength = trian.TriangleVertexArray.Length; //母板点数组长度 //PointArraylength = RefPicturePointArrayWidth * RefPicturePointArrayHight;//母板点数组长度 packedPiontImageCoorditionArrayFunction(opticFlowFunc, PointArraylength); //装载到母板点数组中 //销毁trian对象 trian = null; //可以这么销毁 functionFun.ReadMarkPointsFunc(); //call读识标记点函数,将母板的标记点识取出来 //将第i张母板标记点存到PictureOpticflowDataResultArray[ReferencePictureDataArray[i].ReferencePictureIndex].PictureMarkpointsArray opticFlowFunc.PictureOpticflowDataResultArray[opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].ReferencePictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; CreatArray.creatInReferencePicturePixXYArray(RefPictureHight * RefPictureWidth, ref InReferencePicturePixXYArray); //创建像素经过旋转平移后在母板坐标系下的坐标数组 //=======匹配照片 循环计算===== for (int k = 0; k < length; k++) { CurPictureIndex = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexOfPictureForMachArray[k]; //待匹配照片在结果数组中的索引 CreatArray.creatPointsResultArray(opticFlowFunc, CurPictureIndex, RefPicturePointArrayHight, RefPicturePointArrayWidth); //创建点光流结果数组 CurrentPictureBitmap = (Bitmap)Image.FromFile(opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureLujin); CreatArray.creatPictureGreyArray(CurrentPictureBitmap, ref CurrentPictureGreyArray); //创建 匹配照片灰度数组 functionFun.LoadgrayValuesArrayForMatch(CurrentPictureBitmap, ref CurrentPictureGreyArray); //装待匹配照片灰度数组 CreatArray.creatPictureDlateGreyArray(CurrentPictureBitmap, ref PictureDlateGreyArray); //创建灰度差数组 CreatArray.creatHomologousPointsDisplacementsArray(PointArraylength, ref HomologousPointsDisplacementsArray); //创建位移场数组 functionFun.ReadMarkPointsFunc(); //call识标记点函数 opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].PictureMarkpointsArray = functionFun.MarkPointsArray; //将第K张待匹配照片标记点到光流结果数组中 // call 求旋转平移矩阵函数,得到母板照片旋转平移到当前待匹配照片上的旋转平移矩阵函数 functionFun.GetRotationMatrixAndTranslationFunc(ref Mt); // 求母板照片和待匹配照片灰度差 for (int j = 0; j < CurrentPictureGreyArray.Length; j++) { // 得到旋转平移后的坐标 functionFun.Get2DzuobiaoInReferencePictureFunc(opticFlowFunc, CurrentPictureBitmap, Mt, T, InReferencePictureDataArrayIndex, j, CurrentPictureGreyArray.Length, ref InReferencePicturePixXYArray); //计算编号 functionFun.CalculateIndexOfInReferencePictureFunc(RefPictureHight, RefPictureWidth, j, InReferencePicturePixXYArray, ref InReferencePictureIndex); //求灰度差 直接相减 PictureDlateGreyArray[j] = CurrentPictureGreyArray[j].OrigingrayValue - ReferencePictureGreyArray[InReferencePictureIndex].OrigingrayValue; } //清数组 Array.Resize(ref CurrentPictureGreyArray, 0); //=============待匹配照片 点循环 计算(去震动)================== //for (int j = 0; j < PointArraylength; j++) //{ // //将点坐标存起 // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[i].PiontImageCoorditionArray[j].X; // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[i].PiontImageCoorditionArray[j].Y; // // call求灰度差函数 // functionFun.racepossibleEdgePointIndexFunc(RefPicturePointArrayHight, RefPicturePointArrayWidth, opticFlowFunc.ReferencePictureDataArray[i].IndexArray[j], ref CurrentPixtNeighbourArray); // //判断 八邻域数组长度是否为8,不为8的话 梯度赋0 // if (CurrentPixtNeighbourArray.Count == 8) // { // //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]]; // } // else // { // Grad.X = 0; // Grad.Y = 0; // } // //将灰度差存到结果数组里面 // opticFlowFunc.PictureOpticflowDataResultArray[CurPictureIndex].OpticflowResultFOfPointsArray[j].Grad = Grad; //} //=====存到赵涛数组里=========== //装载显示点的坐标 for (int j = 0; j < PointArraylength; j++) { HomologousPointsDisplacementsArray[j].pointCoordinate.X = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].X; HomologousPointsDisplacementsArray[j].pointCoordinate.Y = opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].PiontImageCoorditionArray[j].Y; } //====母板点数组循环计算========= for (int j = 0; j < PointArraylength; j++) { //装八邻域数组 functionFun.racepossibleEdgePointIndexFunc(ReferencePictureBitmap.Height, ReferencePictureBitmap.Width, opticFlowFunc.ReferencePictureDataArray[InReferencePictureDataArrayIndex].IndexArray[j], ref CurrentPixtNeighbourArray); //判断 八邻域数组长度是否为8,不为8的话 梯度赋0 if (CurrentPixtNeighbourArray.Count == 8) { //soble算子 HomologousPointsDisplacementsArray[s].deltaX = 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]]; HomologousPointsDisplacementsArray[s].deltaY = -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]]; } else { HomologousPointsDisplacementsArray[s].deltaX = 0; HomologousPointsDisplacementsArray[s].deltaY = 0; } s++; } //销毁对象 functionFun = null; // 清除数组 Array.Resize(ref PictureDlateGreyArray, 0); CurrentPixtNeighbourArray.Clear(); } // 清除数组 Array.Resize(ref ReferencePictureGreyArray, 0); }
// 跳点不去震动函数: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); }
public void Init(OpticMeasureClass _currentOMC, int _primitivePictureIndex) { currentOMC = _currentOMC; primitivePictureIndex = _primitivePictureIndex; }
public DrawVector2Frm(OpticMeasureClass _opmc, GetOpticflowResultOfSingleReferencePicture _singleOpticFlow) { InitializeComponent(); currentEdit = _opmc; compVector2 = _singleOpticFlow; }
public GrayAddPicture(OpticMeasureClass _opmc) { InitializeComponent(); opmc = _opmc; }