public Action <Image <Gray, byte>, Image <Bgr, byte> > ProcessingStep1_Version2(
            int threshold,
            SampleType sampletype,
            int cHnum,
            int cWnum,
            bool whiteGrid,
            bool debugmode = false)
        {
            return((originalimg, colorimg) =>
            {
                try
                {
                    Stopwatch stw = new Stopwatch();
                    Stopwatch stw2 = new Stopwatch();
                    stw.Start();
                    stw2.Start();

                    var color_visual_img = colorimg.Clone();
                    var color_visual_img2 = colorimg.Clone();
                    var baseimg = originalimg.Clone();
                    PResult = new ImgPResult(
                        PData.UPAreaLimit,
                        PData.DWAreaLimit,
                        PData.IntenSumUPLimit,
                        PData.IntenSumDWLimit);

                    VectorOfVectorOfPoint contours;

                    if (debugmode)
                    {
                        contours = baseimg
                                   .Map(Proc_Method_List [sampletype])
                                   .Act(img => img.Save(TestFileSavePath.BasePath + "\\beforcntr.bmp"))
                                   .Map(FindContour)
                                   .Map(Sortcontours);
                    }
                    else
                    {
                        contours = baseimg
                                   .Map(Proc_Method_List [sampletype])
                                   .Map(FindContour)
                                   .Map(Sortcontours);
                    }
                    stw2.ElapsedMilliseconds.Print("Pre Contour : ");
                    stw2.Restart();


                    var centerMoment = contours.Map(CalcCenter);
                    stw2.ElapsedMilliseconds.Print("moment : ");
                    stw2.Restart();
                    var boxlist = contours.Map(ApplyBox);

                    var color_visual_img3 = colorimg.Clone();
                    DrawBox(color_visual_img3, boxlist);
                    if (debugmode)
                    {
                        color_visual_img3.Save(TestFileSavePath.BasePath + "\\AftercntrBox.bmp");
                    }

                    byte[,,]   indexingImage = null;
                    if (whiteGrid)
                    {
                        indexingImage = MatWhitePattern(cHnum, cWnum, 3);
                    }
                    else
                    {
                        indexingImage = MatPattern(cHnum, cWnum, 3);
                    }

                    stw2.ElapsedMilliseconds.Print("Create Pattern : ");
                    stw2.Restart();

                    byte[,,]   passfailPosData = new byte[cHnum, cWnum, 1];

                    var estRes = EstedChipPos_Ver2(cHnum, cWnum);                        // Y , X

                    var estedChipP = estRes.IndexPos
                                     .Act(est => DrawCenterPoint(color_visual_img, est));

                    // Index list pair with boxlist
                    var indexres = GetIndexOf(APBoxTolerance, boxlist, estRes.HLineEQs, estRes.VLineEQs);

                    //var idxtemp = indexres.ToArray();
                    //
                    //for ( int i = 0 ; i < boxlist.Len() ; i++ )
                    //{
                    //	Console.WriteLine( $"index {idxtemp [ i].Value.j} , {idxtemp [ i].Value.i}    Box : {boxlist[i].Y}  {boxlist [ i ].X}" );
                    //}

                    var resultGenerator = ImportResult.Apply(estRes.IndexPos)
                                          .Apply(boxlist)
                                          .Apply(indexres);

                    var drawing = DrawProcIdx.Apply(LineThickness)
                                  .Apply(color_visual_img)
                                  .Apply(indexingImage);


                    //var temp1 = NgResultInitializer(cHnum , cWnum);
                    //var temp2 = resultGenerator(temp1);
                    //
                    //
                    //var res2 = ImportResult( estRes.IndexPos , boxlist , indexres , temp1 );



                    PResult.OutData = NgResultInitializer(cHnum, cWnum)
                                      .Map(resultGenerator)
                                      .Flatten()
                                      .ToList();

                    PResult.OutData.ForEach(drawing);

                    //// ==== result done  ====

                    stw2.ElapsedMilliseconds.Print("In Out Check : ");
                    stw2.Restart();

                    for (int i = 0; i < estedChipP.GetLength(0); i++)
                    {
                        for (int j = 0; j < estedChipP.GetLength(1); j++)
                        {
                            var cirp = new CircleF();
                            cirp.Center = new System.Drawing.PointF(
                                ( float )(estedChipP [i, j, 1])
                                , ( float )(estedChipP [i, j, 0]));

                            color_visual_img3.Draw(
                                cirp
                                , ApCenteBoxColor, 1);
                        }
                    }
                    stw2.ElapsedMilliseconds.Print("Low Over Check : ");
                    stw2.Restart();

                    if (debugmode)
                    {
                        color_visual_img3.Save(TestFileSavePath.BasePath + "\\AftercntrBoxandEsted.bmp");
                    }

                    DrawCenterPoint(color_visual_img, estedChipP);
                    UpdateResult(PResult)(indexingImage, color_visual_img);
                    evtProcessingResult();
                    stw.Stop();
                    Console.WriteLine("Process Time : " + stw.ElapsedMilliseconds);
                }
                catch (Exception er)
                {
                    System.Windows.Forms.MessageBox.Show(er.ToString());
                    evtProcessingDone(true);
                }
            });
        }
        public Action <Image <Gray, byte>, Image <Bgr, byte> > ProcessingStep1_Version2_WithEL(
            int threshold,
            SampleType sampletype,
            int cHnum,
            int cWnum,
            bool whiteGrid,
            List <ELData> eldata,
            bool debugmode = false
            )
        {
            return((originalimg, colorimg) =>
            {
                try
                {
                    var color_visual_img = colorimg.Clone();
                    var color_visual_img2 = colorimg.Clone();
                    var baseimg = originalimg.Clone();
                    PResult = new ImgPResult(
                        PData.UPAreaLimit,
                        PData.DWAreaLimit,
                        PData.IntenSumUPLimit,
                        PData.IntenSumDWLimit);

                    VectorOfVectorOfPoint contours;

                    if (debugmode)
                    {
                        contours = baseimg
                                   .Map(Proc_Method_List[sampletype])
                                   .Act(img => img.Save(TestFileSavePath.BasePath + "\\beforcntr.bmp"))
                                   .Map(FindContour)
                                   .Map(Sortcontours);
                    }
                    else
                    {
                        contours = baseimg
                                   .Map(Proc_Method_List[sampletype])
                                   .Map(FindContour)
                                   .Map(Sortcontours);
                    }



                    var centerMoment = contours.Map(CalcCenter);

                    var boxlist = contours.Map(ApplyBox);

                    var color_visual_img3 = colorimg.Clone();
                    DrawBox(color_visual_img3, boxlist);
                    if (debugmode)
                    {
                        color_visual_img3.Save(TestFileSavePath.BasePath + "\\AftercntrBox.bmp");
                    }

                    byte[,,] indexingImage = null;
                    if (whiteGrid)
                    {
                        indexingImage = MatWhitePattern(cHnum, cWnum, 3);
                    }
                    else
                    {
                        indexingImage = MatPattern(cHnum, cWnum, 3);
                    }


                    byte[,,] passfailPosData = new byte[cHnum, cWnum, 1];

                    var estRes = EstedChipPos_Ver2(cHnum, cWnum); // Y , X

                    var estedChipP = estRes.IndexPos
                                     .Act(est => DrawCenterPoint(color_visual_img, est));

                    // Index list pair with boxlist
                    var indexres = GetIndexOf(APBoxTolerance, boxlist, estRes.HLineEQs, estRes.VLineEQs);



                    var resultGenerator = ImportResult.Apply(estRes.IndexPos)
                                          .Apply(boxlist)
                                          .Apply(indexres);

                    var drawing = DrawProcIdx.Apply(LineThickness)
                                  .Apply(color_visual_img)
                                  .Apply(indexingImage);

                    PResult.OutData = NgResultInitializer(cHnum, cWnum)
                                      .Map(resultGenerator)
                                      .Flatten()
                                      .ToList();

                    PResult.OutData.ForEach(drawing);

                    //// ==== result done  ====

                    for (int i = 0; i < estedChipP.GetLength(0); i++)
                    {
                        for (int j = 0; j < estedChipP.GetLength(1); j++)
                        {
                            var cirp = new CircleF();
                            cirp.Center = new System.Drawing.PointF(
                                (float)(estedChipP[i, j, 1])
                                , (float)(estedChipP[i, j, 0]));

                            color_visual_img3.Draw(
                                cirp
                                , ApCenteBoxColor, 1);
                        }
                    }

                    if (debugmode)
                    {
                        color_visual_img3.Save(TestFileSavePath.BasePath + "\\AftercntrBoxandEsted.bmp");
                    }

                    DrawCenterPoint(color_visual_img, estedChipP);
                    color_visual_img = DrawELData(color_visual_img, estedChipP, eldata);
                    UpdateResult(PResult)(indexingImage, color_visual_img);
                    evtProcessingResult();
                }
                catch (Exception er)
                {
                    System.Windows.Forms.MessageBox.Show(er.ToString());
                    evtProcessingDone(true);
                }
            });
        }