Пример #1
0
        public List <List <string> > GetPathInDir(string dirPath)
        {
            FormatConvert         fcv    = new FormatConvert();
            List <List <string> > output = new List <List <string> >();

            string[] filenames = System.IO.Directory.GetFiles(dirPath);

            List <string> box0 = new List <string>();
            List <string> box1 = new List <string>();
            List <string> box2 = new List <string>();
            List <string> box3 = new List <string>();

            foreach (string onefile in filenames)
            {
                string   item = System.IO.Path.GetFileName(onefile);
                string[] temp = System.Text.RegularExpressions.Regex.Split(item, "_");

                //Debug.Assert(onefile != "000_000.dat");
                item = dirPath + "\\" + item;
                if (temp[0] == "000")
                {
                    box0.Add(item);
                }
                if (temp[0] == "001")
                {
                    box1.Add(item);
                }
                if (temp[0] == "002")
                {
                    box2.Add(item);
                }
                if (temp[0] == "003")
                {
                    box3.Add(item);
                }
            }

            if (box0.Count > 0)
            {
                output.Add(box0);
            }
            if (box1.Count > 0)
            {
                output.Add(box1);
            }
            if (box2.Count > 0)
            {
                output.Add(box2);
            }
            if (box3.Count > 0)
            {
                output.Add(box3);
            }

            //Debug.Assert(output.Count == 2);
            //Debug.Assert(output[0].Count == 3);

            return(output);
        }
Пример #2
0
 byte[,] PutinListBox(string path, FormatConvert fcv, int strPosX, int strPosY, int endPosX, int endPosY, double scale)
 {
     byte[,] originalFileMat = fcv.Dat2DownMat(path, ImgInfo.WH, scale);
     byte[,] transOri        = originalFileMat.Transpose();
     byte[,] pickedMat       = PickPixel(transOri, (int)(strPosX / scale), (int)(strPosY / scale), (int)(endPosX / scale), (int)(endPosY / scale));
     originalFileMat         = null;
     return(Matrix.Transpose(pickedMat));
 }
Пример #3
0
        public byte[] GetLineProfileData(string[,] inputPath)
        {
            FormatConvert fcv = new FormatConvert();

            /* X축과 Y축 중에 더 긴쪽을 중심으로 전개한다. 같은 경우는 X축으로 */
            if (Math.Abs(LineData.StartPoint.X - LineData.EndPoint.X) >= Math.Abs(LineData.StartPoint.Y - LineData.EndPoint.Y))
            {
                return(XOrder(inputPath, LineData));
            }
            else
            {
                return(YOrder(inputPath, LineData));
            }

            /* y의 끝점이 한개의 이미지의 y끝점에서  안에 있는지, 이미지보다 위로 가는지 아래로 가는지*/
        }
Пример #4
0
        public List <List <byte[, ]> > ListDownScaledZoomedMat(List <List <string> > input, ZoomData data)
        {
            /* data에 들어있는 리얼 포지션 좌표 값은 스케일링이 안되있다. */
            /* 1. 각 원본 DAt 파일에 어느 좌표부터 어느 좌표까지 가져와야 하는지 계산 */
            /* 2. 데이터를 가져온다음에 리사이즈 */
            /**/
            /**/
            /**/
            /**/

            //Check Start End File Pos and scale ===
            data.Scale = CalcScale(input, data);
            double scale = data.Scale; // 여기서 스케일이 정해진다. 이것은 실제 데이터 가져온후 이미지 -> 스케일변환 ->

            Console.WriteLine("Scale Value is " + $"  {scale} ");
            /* Class Instance*/
            FormatConvert fcv = new FormatConvert();

            Matrix2Bitmap = new MatrixToImage();
            Bitmap2matrix = new ImageToMatrix();

            int width  = data.Ex - data.Sx;
            int height = data.Ey - data.Sy;
            int WCount = data.endNumX - data.startNumX;
            int HCount = data.endNumY - data.startNumY;


            int strPosX = 0;
            int strPosY = 0;
            int endPosX = 0;
            int endPosY = 0;

            List <List <byte[, ]> > box = new List <List <byte[, ]> >();

            if ((data.endNumX - data.startNumX) == 0 && (data.endNumY - data.startNumY) == 0)
            {
                /*OK*/
                #region
                List <byte[, ]> tempbox = new List <byte[, ]>();
                string          path    = input[data.startNumX][data.startNumY];
                strPosX = data.Sx - data.startNumX * data.Wo;
                strPosY = data.Sy - data.startNumY * data.Ho;
                endPosX = data.Ex - data.endNumX * data.Wo;
                endPosY = data.Ey - data.endNumY * data.Ho;

                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                box.Add(tempbox);
                #endregion
            }
            else if ((data.endNumY - data.startNumY) == 0)
            {
                /*OK*/
                #region
                for (int i = data.startNumX; i <= data.endNumX; i++)
                {
                    string path = input[i][data.startNumY];

                    List <byte[, ]> tempbox = new List <byte[, ]>();
                    if (i == data.startNumX)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else if (i == data.endNumX)
                    {
                        strPosX = 0;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Ex - data.endNumX * data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else
                    {
                        strPosX = 0;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    box.Add(tempbox);
                }
                #endregion
            }
            else if ((data.endNumX - data.startNumX) == 0)
            {
                /*OK*/
                #region
                List <byte[, ]> tempbox = new List <byte[, ]>();
                for (int j = data.startNumY; j <= data.endNumY; j++)
                {
                    string path = input[data.startNumX][j];
                    if (j == data.startNumY)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = data.Sy - data.startNumY * data.Ho;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else if (j == data.endNumY)
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = 0;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ey - data.endNumY * data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                    else
                    {
                        strPosX = data.Sx - data.startNumX * data.Wo;
                        strPosY = 0;
                        endPosX = data.Ex - data.startNumX * data.Wo;
                        endPosY = data.Ho;
                        tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                    }
                }
                box.Add(tempbox);
                #endregion
            }
            else
            {
                for (int i = data.startNumX; i <= data.endNumX; i++)
                {
                    List <byte[, ]> tempbox = new List <byte[, ]>();

                    if (i == data.startNumX)
                    {
                        #region Start X Pos
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                /* Pixel Position in One File Matrix*/
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = data.Sx - i * data.Wo;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    else if (i == data.endNumX)
                    {
                        #region End X Pos
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                strPosX = 0;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Ex - i * data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region Middle
                        for (int j = data.startNumY; j <= data.endNumY; j++)
                        {
                            string path = input[i][j];
                            if (j == data.startNumY)
                            {
                                strPosX = 0;
                                strPosY = data.Sy - j * data.Ho;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else if (j == data.endNumY)
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ey - j * data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                            else
                            {
                                strPosX = 0;
                                strPosY = 0;
                                endPosX = data.Wo;
                                endPosY = data.Ho;
                                tempbox.Add(PutinListBox(path, fcv, strPosX, strPosY, endPosX, endPosY, scale));
                            }
                        }
                        #endregion
                    }
                    box.Add(tempbox);
                }
            }

            return(box);
        }
Пример #5
0
        byte[] YOrder(string[,] inputPath, LineProfileData lineData)
        {
            double resultForAssert = lineData.EndPoint.Y - lineData.StartPoint.Y;

            int x    = LineData.StartNumX;
            int y    = LineData.StartNumY;
            int xend = LineData.EndNumX;
            int yend = LineData.EndNumY;

            try
            {
                FormatConvert fcv = new FormatConvert();
                /* y의 끝점이 한개의 이미지의 y끝점에서  안에 있는지, 이미지보다 위로 가는지 아래로 가는지*/
                List <byte> outputlist = new List <byte>();
                int         innerSX    = (int)lineData.StartPoint.X - x * ImgInfo.W;
                int         innerSY    = (int)lineData.StartPoint.Y - y * ImgInfo.H;
                int         innerEY    = (int)lineData.EndPoint.Y - yend * ImgInfo.H;

                while (true)
                {
                    byte[,] data = fcv.Dat2Mat(inputPath[y, x]); // string[row,col] 순 이므로 [y,x] 순이 된다.
                    double By = innerSX - EqData.Ay * innerSY;   // ok

                    if (y == lineData.EndNumY)
                    {
                        if (x == xend)
                        {
                            for (int j = innerSY; j < innerEY; j++)
                            {
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0? (int)(EqData.Ay * j + By - 1): 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            break;
                        }
                        else if (x > xend)
                        {
                            for (int j = innerSY; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + By < 0)
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = ImgInfo.W;
                            x--;
                        }
                        else
                        {
                            for (int j = 0; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + By > ImgInfo.W)
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = 0;
                            x++;
                        }
                    } // Y is in End


                    else if (y == lineData.StartNumY)
                    {
                        if ((EqData.Ay * ImgInfo.H + By) < 0)
                        {
                            for (int j = innerSY; j < ImgInfo.H; j++)
                            {
                                if (EqData.Ay * j + By < 0) // 칸을 넘어갔을경우
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = ImgInfo.W;
                            x--;
                        }
                        else if ((EqData.Ay * ImgInfo.H + By) > ImgInfo.W)
                        {
                            for (int j = 0; j < ImgInfo.H; j++)
                            {
                                if (EqData.Ay * j + By > ImgInfo.W)
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = 0;
                            x++;
                        }
                        else
                        {
                            for (int j = innerSY; j < ImgInfo.H; j++)
                            {
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSY = 0;
                            y++;
                        }
                    }
                    else
                    {
                        if ((EqData.Ay * ImgInfo.H + By) < 0)
                        {
                            for (int j = innerSY; j < ImgInfo.H; j++)
                            {
                                if (EqData.Ay * j + By < 0)
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = ImgInfo.W;
                            x--;
                        }
                        else if ((EqData.Ay * ImgInfo.H + By) > ImgInfo.W)
                        {
                            for (int j = innerSY; j < ImgInfo.H; j++)
                            {
                                if (EqData.Ay * j + By > ImgInfo.W)
                                {
                                    innerSY = j;
                                    break;
                                }
                                int xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSX = 0;
                            x++;
                        }
                        else
                        {
                            int xPos = 0;
                            for (int j = innerSY; j < ImgInfo.H; j++)
                            {
                                xPos = (int)(EqData.Ay * j + By - 1) >= 0 ? (int)(EqData.Ay * j + By - 1) : 0;
                                outputlist.Add(data[j, xPos]);
                            }
                            innerSY = 0;
                            innerSX = xPos;
                            y++;
                        }
                    } // Y is not in End
                }

                /* 하나의 라인데이터가 리스트로 저장이 된다. 이 리스트를 byte[] 로 변환해준다. */

                byte[] output = ConvertList2ByteArr(outputlist);
                Debug.Assert(resultForAssert == output.Length);
                return(output);
            }
            catch (Exception eex)
            {
                Console.WriteLine(eex.ToString());
                return(new byte[0]);
            }
        }
Пример #6
0
        byte[] XOrder(string[,] inputPath, LineProfileData lineData) // lineData 는 문제없음.
        {
            double resultForAssert = lineData.EndPoint.X - lineData.StartPoint.X;


            int x    = LineData.StartNumX;
            int y    = LineData.StartNumY;
            int xend = LineData.EndNumX;
            int yend = LineData.EndNumY;

            try
            {
                FormatConvert fcv        = new FormatConvert();
                List <byte>   outputlist = new List <byte>();
                /* y의 끝점이 한개의 이미지의 y끝점에서  안에 있는지, 이미지보다 위로 가는지 아래로 가는지*/
                int innerSX = (int)lineData.StartPoint.X - x * ImgInfo.W;
                int innerSY = (int)lineData.StartPoint.Y - y * ImgInfo.H;
                int innerEX = (int)lineData.EndPoint.X - xend * ImgInfo.W;

                while (true)
                {
                    byte[,] data = fcv.Dat2Mat(inputPath[y, x]); // string[row,col] 순 이므로 [y,x] 순이 된다.  =>ok
                    double Bx = innerSY - EqData.Ax * innerSX;   //inner 시작점 => ok

                    if (x == lineData.EndNumX)                   // End
                    {
                        if (y == yend)
                        {
                            for (int j = innerSX; j < innerEX; j++)
                            {
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]); // j = x
                            }
                            break;
                        }
                        else if (y > yend)
                        {
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx < 0)
                                {
                                    innerSX = j;
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]); // j = x
                            }
                            innerSY = ImgInfo.H;
                            y--;
                        }
                        else
                        {
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx > ImgInfo.H)
                                {
                                    innerSX = j;
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]);
                            }
                            innerSY = 0;
                            y++;
                        }
                    } // X is in End


                    else if (x == lineData.StartNumX) // Start
                    {
                        if ((EqData.Ax * ImgInfo.W + Bx) < 0)
                        {
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx < 0)
                                {
                                    innerSX = j;
                                    innerSY = (y * ImgInfo.H);
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]); // j = x
                            }
                            innerSY = ImgInfo.H;
                            y--;
                        }
                        else if ((EqData.Ax * ImgInfo.W + Bx) > ImgInfo.H)
                        {
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx > ImgInfo.H)
                                {
                                    innerSX = j;
                                    innerSY = (y * ImgInfo.H);
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]);
                            }
                            innerSY = 0;
                            y++;
                        }
                        else
                        {
                            int yPos = 0;
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]);
                            }
                            innerSX = 0;
                            innerSY = yPos;
                            x++;
                        }
                    }
                    else // Middle
                    {
                        if ((EqData.Ax * ImgInfo.W + Bx) < 0)
                        {
                            for (int j = 0; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx < 0)
                                {
                                    innerSX = j;
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]); // j = x
                            }
                            innerSY = ImgInfo.H;
                            y--;
                        }
                        else if ((EqData.Ax * ImgInfo.W + Bx) > ImgInfo.H)
                        {
                            for (int j = 0; j < ImgInfo.W; j++)
                            {
                                if (EqData.Ax * j + Bx > ImgInfo.H)
                                {
                                    innerSX = j;
                                    break;
                                }
                                int yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]);
                            }
                            innerSY = 0;
                            y++;
                        }
                        else // mid
                        {
                            int yPos = 0;
                            for (int j = innerSX; j < ImgInfo.W; j++)
                            {
                                yPos = (int)(EqData.Ax * j + Bx - 1) >= 0 ? (int)(EqData.Ax * j + Bx - 1) : 0;
                                outputlist.Add(data[yPos, j]);
                            }
                            innerSX = 0;
                            innerSY = yPos;
                            x++;
                        }
                    } // X is not in End
                }


                byte[] output = ConvertList2ByteArr(outputlist);
                Debug.Assert(resultForAssert == output.Length);
                return(output);
            }
            catch (Exception eex)
            {
                MessageBox.Show(eex.ToString());
                return(new byte[0]);
            }
        }