diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs deleted file mode 100644 index 2f2677a..0000000 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using OpenCvSharp; -using OpenCvSharp.XImgProc; - -namespace deepTIAS_feature_labColor -{ - class ImgProc - { - private void ThinningIte(ref Mat img, int pattern) - { - Mat del_marker = img.Clone(); - - int x, y; - int[] v = new int[9]; - - for (y = 1; y < img.Rows - 1; ++y) - { - - for (x = 1; x < img.Cols - 1; ++x) - { - v[8] = 0; v[1] = 0; v[2] = 0; - v[7] = 0; v[0] = 0; v[3] = 0; - v[6] = 0; v[5] = 0; v[4] = 0; - - unsafe - { - v[0] = img.DataPointer[(y * img.Step() + x * img.ElemSize())]; - v[1] = img.DataPointer[(y - 1) * img.Step() + x * img.ElemSize()]; - v[2] = img.DataPointer[(y - 1) * img.Step() + (x + 1) * img.ElemSize()]; - v[3] = img.DataPointer[y * img.Step() + (x + 1) * img.ElemSize()]; - v[4] = img.DataPointer[(y + 1) * img.Step() + (x + 1) * img.ElemSize()]; - v[5] = img.DataPointer[(y + 1) * img.Step() + x * img.ElemSize()]; - v[6] = img.DataPointer[(y + 1) * img.Step() + (x - 1) * img.ElemSize()]; - v[7] = img.DataPointer[y * img.Step() + (x - 1) * img.ElemSize()]; - v[8] = img.DataPointer[(y - 1) * img.Step() + (x - 1) * img.ElemSize()]; - - } - int S = 0; - if (v[2] == 0 && v[3] == 1) S++; - if (v[3] == 0 && v[4] == 1) S++; - if (v[4] == 0 && v[5] == 1) S++; - if (v[5] == 0 && v[6] == 1) S++; - if (v[6] == 0 && v[7] == 1) S++; - if (v[7] == 0 && v[8] == 1) S++; - if (v[8] == 0 && v[1] == 1) S++; - if (v[1] == 0 && v[2] == 1) S++; - - int N = v[1] + v[2] + v[3] + v[4] + v[5] + v[6] + v[7] + v[8]; - - int m1 = 0, m2 = 0; - - if (pattern == 0) m1 = (v[1] * v[3] * v[5]); - if (pattern == 1) m1 = (v[1] * v[3] * v[7]); - - if (pattern == 0) m2 = (v[3] * v[5] * v[7]); - if (pattern == 1) m2 = (v[1] * v[5] * v[7]); - - if (S == 1 && (N >= 2 && N <= 6) && m1 == 0 && m2 == 0) - { - unsafe - { - del_marker.DataPointer[y * del_marker.Step() + x * del_marker.ElemSize()] = 0; - } - } - } - } - img &= del_marker; - } - - public Mat Thinning(Mat src) - { - Mat dst = src.Clone(); - dst /= 255; // 0は0 , 1以上は1に変換される - Mat prev = Mat.Zeros(dst.Size(), MatType.CV_8UC1); - Mat diff = new Mat(); - do - { - ThinningIte(ref dst, 0); - ThinningIte(ref dst, 1); - Cv2.Absdiff(dst, prev, diff); - dst.CopyTo(prev); - - Cv2.ImShow("thinning", dst * 255); - Cv2.WaitKey(100); - System.Threading.Thread.Sleep(100); - - } while (Cv2.CountNonZero(diff) > 0); - dst *= 255; - return dst; - } - } -} diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj index 54fbaff..8c74de6 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj @@ -88,7 +88,6 @@ - Form_Display.cs diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/ColorExtractor.cs b/Tongue extraction_cropresizemethod/Tongue extraction/ColorExtractor.cs new file mode 100644 index 0000000..813ef73 --- /dev/null +++ b/Tongue extraction_cropresizemethod/Tongue extraction/ColorExtractor.cs @@ -0,0 +1,730 @@ +using OpenCvSharp; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +namespace Tongue_extraction +{ + class ColorExtractor + { + const int RADIUS_COLORAREA = 10; + public static Bitmap bitmap; + + float[] a = new float[17]; + float[] b = new float[17]; + float[] c = new float[17]; + float d; + float e; + float f; + int k; + public static bool m_getColor = false; + public static Mat m_CalibFrame; //キャリブレーション用画像 + public static OpenCvSharp.Point[] getRGBpoint = new OpenCvSharp.Point[24];//RGB取得用 + double[] m_BforLab = new double[24]; + double[] m_GforLab = new double[24]; + double[] m_RforLab = new double[24]; + public static bool m_bCalib; + public static OpenCvSharp.Point pt = new OpenCvSharp.Point();//キャリブレーション用のポイント入れ + public static Mat m_PointedFrame; //ポイントされたMat + public static int click = 0; //クリック回数 + + OpenCvSharp.Point P1 = new OpenCvSharp.Point(); + OpenCvSharp.Point P2 = new OpenCvSharp.Point(); + + public void ColorExtract() + { + // GetImage() + var path_oriImg = @"data_lab\d\Shot0001.bmp"; + var path_calibCsv = @"data_lab\d\Calib.csv"; + var path_colorMatrixXYZ = "xyz.txt"; + using (Mat mat_oriImg = Cv2.ImRead(path_oriImg, ImreadModes.Color)) + { + // Process_DeepTIAS() + var path_mask = @"data_lab\d\Shot0001_mask.bmp"; + Mat mat_finalMask = Cv2.ImRead(path_mask, ImreadModes.Grayscale); + Cv2.Threshold(mat_finalMask, mat_finalMask, 128, 255, ThresholdTypes.Binary); + + // マスクされた舌領域画像の作成 + Mat mat_maskedImg = new Mat(); + mat_oriImg.CopyTo(mat_maskedImg, mat_finalMask); + + // 5点クリック法(2010石川) + List list_5points = Get5points(mat_finalMask); + + // 8領域の取得 + List list_8area = Get8area(list_5points); + Show8area(mat_oriImg.Clone(), list_8area); + + /* + // 色抽出 + List list_8Bgr = Get8colors(mat_maskedImg, list_8area); + + // 色変換(RGB->XYZ->Lab) + List list_8Lab = Calc8Lab(list_8Bgr, path_calibCsv, path_colorMatrixXYZ); + + // 色の表示 + Show8colors(list_8Bgr, list_8Lab); + + // 保存 + // Write8colors(list_8Bgr, list_8Lab); + */ + + + // 廃棄 + mat_finalMask.Dispose(); + mat_maskedImg.Dispose(); + GC.Collect(); + } + } + + private List Get5points(Mat mat_finalMask) + { + List li_dst; + + // 表示用 + var mat_dst = mat_finalMask.Clone(); + Cv2.CvtColor(mat_dst, mat_dst, ColorConversionCodes.GRAY2BGR); + + // マスクの舌領域画素座標 + var mat_nonZeroCoordinates = new Mat(); + Cv2.FindNonZero(mat_finalMask, mat_nonZeroCoordinates); + + // 舌領域上の点をすべてlistに詰める + var list_X = new List(); + var list_Y = new List(); + for (int i = 0; i < mat_nonZeroCoordinates.Total(); i++) + { + var x = mat_nonZeroCoordinates.At(i).X; + var y = mat_nonZeroCoordinates.At(i).Y; + list_X.Add(x); + list_Y.Add(y); + } + + /// method1 + // 端っこを探索(ラスタ左上から) + var p_top = mat_nonZeroCoordinates.At(list_Y.IndexOf(list_Y.Min())); + var p_bottom = mat_nonZeroCoordinates.At(list_Y.IndexOf(list_Y.Max())); + var p_left = mat_nonZeroCoordinates.At(list_X.IndexOf(list_X.Min())); + var p_right = mat_nonZeroCoordinates.At(list_X.IndexOf(list_X.Max())); + + // 舌尖領域を示すy座標を取得(割合を今回は決め打ち) + var y_apex = (int)(p_top.Y + ((p_bottom.Y - p_top.Y) * 0.8)); + var p_apex_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Min()); + var p_apex_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Max()); + + // 表示してみる + //Cv2.Circle(mat_dst, p_top, 20, new Scalar(255, 255, 0), -1); + Cv2.Circle(mat_dst, p_bottom, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_left, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_right, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_apex_left, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_apex_right, 20, new Scalar(255, 255, 0), -1); + + /// method2 + // 重心(CoG)計算 + var moments = Cv2.Moments(mat_finalMask, true); + var moment_x = moments.M10 / moments.M00; + var moment_y = moments.M01 / moments.M00; + + // 輪郭座標 + OpenCvSharp.Point[][] contours; + HierarchyIndex[] hierarchy; + Cv2.FindContours(mat_finalMask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple); + + // 重心-輪郭の距離 + double maxDistance_lefttop = 0.0; + double maxDistance_righttop = 0.0; + double maxDistance_bottom = 0.0; + var p_left_2 = new OpenCvSharp.Point(); + var p_right_2 = new OpenCvSharp.Point(); + var p_bottom_2 = new OpenCvSharp.Point(); + // 距離が最も遠いものを採択 + for (int i = 0; i < contours[0].Length; i++) + { + // 重心より上側 + if (contours[0][i].Y < moment_y) + { + // 重心より上側左側 + if (contours[0][i].X < moment_x) + { + var distance = contours[0][i].DistanceTo(new OpenCvSharp.Point(moment_x, moment_y)); + if (distance > maxDistance_lefttop) + { + maxDistance_lefttop = distance; + p_left_2 = contours[0][i]; + } + + } + // 重心より上側右側 + if (contours[0][i].X >= moment_x) + { + var distance = contours[0][i].DistanceTo(new OpenCvSharp.Point(moment_x, moment_y)); + if (distance > maxDistance_righttop) + { + maxDistance_righttop = distance; + p_right_2 = contours[0][i]; + } + } + } + else + { + var distance = contours[0][i].DistanceTo(new OpenCvSharp.Point(moment_x, moment_y)); + if (distance > maxDistance_bottom) + { + maxDistance_bottom = distance; + p_bottom_2 = contours[0][i]; + } + } + } + + // 舌尖領域を示すy座標を取得(割合を今回は決め打ち) + var y_top_avg_ = (p_left_2.Y + p_right_2.Y) / 2.0; + var y_apex_2 = (int)(y_top_avg_ + ((p_bottom_2.Y - y_top_avg_) * 0.53)); + var p_apex_left_2 = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex_2).Min()); + var p_apex_right_2 = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex_2).Max()); + + // 表示 + //Cv2.Circle(mat_dst, p_left_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_right_2, 20, new Scalar(255, 0, 0), -1); + Cv2.Circle(mat_dst, p_bottom_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_apex_left_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_apex_right_2, 20, new Scalar(255, 0, 0), -1); + Cv2.Circle(mat_dst, new OpenCvSharp.Point(moment_x, moment_y), 10, new Scalar(200, 60, 200), -1); //重心 + //Cv2.DrawContours(mat_dst, contours, 0, new Scalar(0, 255, 255), 4); // 輪郭 + + /// method3 + // 重心とtopの中点を算出する + var y_topToCoG = (int)(moment_y + p_top.Y) / 2; + var p_topToCoG_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_topToCoG).Min()); + var p_topToCoG_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_topToCoG).Max()); + var p_topToCoG_center = new OpenCvSharp.Point((int)((p_topToCoG_left.X + p_topToCoG_right.X) / 2), y_topToCoG); + // 重心とbottomの中点を算出する + var y_bottomToCoG = (int)(moment_y + p_bottom.Y) / 2; + var p_bottomToCoG_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_bottomToCoG).Min()); + var p_bottomToCoG_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_bottomToCoG).Max()); + var p_bottomToCoG_center = new OpenCvSharp.Point((int)((p_bottomToCoG_left.X + p_bottomToCoG_right.X) / 2), y_bottomToCoG); + // 直線フィッティング + var line = Cv2.FitLine(new OpenCvSharp.Point[2] { p_topToCoG_center, p_bottomToCoG_center }, DistanceTypes.L2, 0, 0.01, 0.0); + var lefty = (int)((-line.X1 * line.Vy / line.Vx) + line.Y1); + var righty = (int)(((mat_finalMask.Cols - line.X1) * line.Vy / line.Vx) + line.Y1); + // 直線上の輪郭点 + var mat_centerline = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + var mat_contour = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + var mat_and = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + Cv2.Line(mat_centerline, new OpenCvSharp.Point(0, lefty), new OpenCvSharp.Point(mat_finalMask.Cols - 1, righty), 3); + Cv2.DrawContours(mat_contour, contours, 0, 3); + Cv2.BitwiseAnd(mat_centerline, mat_contour, mat_and); + Cv2.FindNonZero(mat_and, mat_and); + var bottom_y_3 = 0; + var bottom_x_3 = 0; + for (int i = 0; i < mat_and.Total(); i++) + { + var x = mat_and.At(i).X; + var y = mat_and.At(i).Y; + if (bottom_y_3 < y) + { + bottom_y_3 = y; + bottom_x_3 = x; + } + } + var p_bottom_3 = new OpenCvSharp.Point(bottom_x_3, bottom_y_3); + + //Cv2.Circle(mat_dst, p_topToCoG_left, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_topToCoG_right, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_topToCoG_center, 20, new Scalar(0, 0, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_left, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_right, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_center, 20, new Scalar(0, 0, 255), -1); + //Cv2.Line(mat_dst, new OpenCvSharp.Point(0, lefty), new OpenCvSharp.Point(mat_finalMask.Cols - 1, righty), new Scalar(0, 100, 255)); //近似直線 + Cv2.Circle(mat_dst, p_bottom_3, 20, new Scalar(0, 0, 255), -1); + + // DEBUG + Cv2.NamedWindow("dst", WindowMode.KeepRatio ^ WindowMode.AutoSize); + Cv2.ImShow("dst", mat_dst.Resize(new OpenCvSharp.Size((int)mat_dst.Width * 0.5, (int)mat_dst.Height * 0.5))); + + // 出力 + // li_dst = new List { p_left, p_apex_left, p_bottom, p_apex_right, p_right }; + li_dst = new List { p_left_2, p_apex_left_2, p_bottom_2, p_apex_right_2, p_right_2 }; + + // 破棄 + mat_dst.Dispose(); + mat_nonZeroCoordinates.Dispose(); + GC.Collect(); + return li_dst; + } + + private List Get8area(List list_5points) + { + var li_dst = new List(); + // ROIマスク画像1 + // 0____________ 4 + // | | + // | | + // | | + // 1|● ●|3 + // 舌    / + // 舌_______/ + // 2 + + var points1 = new int[2, 3] { { 0, 2, 1 }, { 4, 2, 3 } }; + var area1 = new OpenCvSharp.Point(); + for (int i = 0; i < 2; i++) + { + var cx1 = (list_5points[points1[i, 0]].X + list_5points[points1[i, 1]].X) / 2; + var cy1 = (list_5points[points1[i, 0]].Y + list_5points[points1[i, 1]].Y) / 2; + area1.X = (list_5points[points1[i, 2]].X + cx1) / 2; + area1.Y = (list_5points[points1[i, 2]].Y + cy1) / 2; + li_dst.Add(area1); + } + + // ROIマスク画像2 + // 0____________ 4 + // | ● ● | + // | | + // | | + // 1| |3 + // 舌    / + // 舌_______/ + // 2 + + var points2 = new int[2, 4] { { 0, 3, 0, 4 }, { 4, 1, 4, 0 } }; + var area2 = new OpenCvSharp.Point(); + for (int i = 0; i < 2; i++) + { + float cx1 = list_5points[points2[i, 0]].X + (list_5points[points2[i, 1]].X - list_5points[points2[i, 0]].X) / 4; + float cy1 = list_5points[points2[i, 0]].Y + (list_5points[points2[i, 1]].Y - list_5points[points2[i, 0]].Y) / 4; + float cx2 = (list_5points[points2[i, 2]].X + list_5points[points2[i, 3]].X) / 2; + float cy2 = (list_5points[points2[i, 2]].Y + list_5points[points2[i, 3]].Y) / 2; + area2.X = (int)(cx1 + cx2) / 2; + area2.Y = (int)(cy1 + cy2) / 2; + li_dst.Add(area2); + } + + // ROIマスク画像3 + // 0____________ 4 + // | | + // | | + // | | + // 1| ● ● |3 + // 舌    / + // 舌_______/ + // 2 + var points3 = new int[2, 3] { { 0, 3, 2 }, { 4, 1, 2 } }; + var area3 = new OpenCvSharp.Point(); + for (int i = 0; i < 2; i++) + { + float cx1 = list_5points[points3[i, 0]].X + (list_5points[points3[i, 1]].X - list_5points[points3[i, 0]].X) / 4; + float cy1 = list_5points[points3[i, 0]].Y + (list_5points[points3[i, 1]].Y - list_5points[points3[i, 0]].Y) / 4; + area3.X = (int)(list_5points[points3[i, 2]].X + cx1) / 2; + area3.Y = (int)(list_5points[points3[i, 2]].Y + cy1) / 2; + li_dst.Add(area3); + } + + // ROIマスク画像3 + // 0____________ 4 + // | | + // | | + // | | + // 1| |3 + // 舌    / + // 舌_●_●_/ + // 2 + var points4 = new int[2, 2] { { 0, 2 }, { 4, 2 } }; + var area4 = new OpenCvSharp.Point(); + for (int i = 0; i < 2; i++) + { + area4.X = list_5points[points4[i, 0]].X + (list_5points[points4[i, 1]].X - list_5points[points4[i, 0]].X) * 7 / 8; + area4.Y = list_5points[points4[i, 0]].Y + (list_5points[points4[i, 1]].Y - list_5points[points4[i, 0]].Y) * 7 / 8; + li_dst.Add(area4); + } + + // To do : もし8areaが舌領域に載っていなかったら修正 + //bool isOnTongueArea = DiscriminateOnTongueArea(li_dst); + //if (isOnTongueArea) + //{ + + //} + + return li_dst; + } + + private List Get8colors(Mat mat_maskedImg, List list_8area) + { + List li_dst = new List(); + for (int i = 0; i < list_8area.Count(); i++) + { + using (Mat mat_colorRoi = Mat.Zeros(mat_maskedImg.Size(), MatType.CV_8UC1)) + { + // 色抽出領域を示すマスク画像を作成 + Cv2.Circle(mat_colorRoi, list_8area[i], RADIUS_COLORAREA, 255, -1); + + // 領域で色を抽出 + var color = Cv2.Mean(mat_maskedImg, mat_colorRoi); + li_dst.Add(color); + } + } + return li_dst; + } + + private void Show8area(Mat oriImg, List list_8area) + { + Cv2.Circle(oriImg, list_8area[0], 10, new Scalar(0, 255, 0), -1); + Cv2.Circle(oriImg, list_8area[1], 10, new Scalar(0, 255, 0), -1); + Cv2.Circle(oriImg, list_8area[2], 10, new Scalar(255, 255, 255), -1); + Cv2.Circle(oriImg, list_8area[3], 10, new Scalar(255, 255, 255), -1); + Cv2.Circle(oriImg, list_8area[4], 10, new Scalar(255, 255, 0), -1); + Cv2.Circle(oriImg, list_8area[5], 10, new Scalar(255, 255, 0), -1); + Cv2.Circle(oriImg, list_8area[6], 10, new Scalar(255, 0, 0), -1); + Cv2.Circle(oriImg, list_8area[7], 10, new Scalar(255, 0, 0), -1); + Cv2.NamedWindow("dst_", WindowMode.KeepRatio ^ WindowMode.Normal); + Cv2.ImShow("dst_", oriImg.Resize(new OpenCvSharp.Size((int)oriImg.Width * 0.5, (int)oriImg.Height * 0.5))); + } + + private List Calc8Lab(List list_8colors, string path_calibCsv, string path_colorMatrixXYZ) + { + GetColorMatrixRGB(path_calibCsv); + CalcTransMat(path_colorMatrixXYZ); + + + + + Read_TranslationMatrix(); + var li_dst = new List(); + for (int i = 0; i < list_8colors.Count(); i++) + { + var LabValue = CalcLab(list_8colors[i]); + li_dst.Add(LabValue); + } + return li_dst; + } + + private void GetColorMatrixRGB(string path_calibCsv) + { + System.Text.Encoding encoding = GetType(path_calibCsv); + System.IO.FileStream fs3 = new System.IO.FileStream(path_calibCsv, System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.IO.StreamReader sr3 = new System.IO.StreamReader(fs3, encoding); + string strLine = ""; + string[] aryLine; + sr3.ReadLine(); // headerをスルー + int i = 0; + while ((strLine = sr3.ReadLine()) != null) + { + aryLine = strLine.Split(','); + var no = Convert.ToSingle(aryLine[0]); + float r = Convert.ToSingle(aryLine[1]); + float g = Convert.ToSingle(aryLine[2]); + float b = Convert.ToSingle(aryLine[3]); + m_BforLab[i] = b; + m_GforLab[i] = g; + m_RforLab[i] = r; + i++; + } + sr3.Close(); + fs3.Close(); + } + + private void CalcTransMat(string path_colorMatrixXYZ) + { + Mat RGBmat = new Mat(24, 17, MatType.CV_64F, new Scalar(1.0f)); + Mat XYZmat = new Mat(24, 4, MatType.CV_64F, new Scalar(1.0f)); + + // ColorChartのXYZ読み込み + string line; + string[] split = new string[3]; + double valueX = 0, valueY = 0, valueZ = 0; + System.Text.Encoding encoding3 = GetType(path_colorMatrixXYZ); + System.IO.FileStream fs3 = new System.IO.FileStream(path_colorMatrixXYZ, System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.IO.StreamReader sr3 = new System.IO.StreamReader(fs3, encoding3); + for (int i = 0; i < 24; i++) + { + line = sr3.ReadLine(); + split = line.Split(' '); + valueX = Convert.ToDouble(split[0]); + valueY = Convert.ToDouble(split[1]); + valueZ = Convert.ToDouble(split[2]); + XYZmat.Set(i, 0, valueX); + XYZmat.Set(i, 1, valueY); + XYZmat.Set(i, 2, valueZ); + } + sr3.Close(); + fs3.Close(); + + // 変換行列の計算 + for (int j = 0; j < 24; j++) + { + //順番 + //R,G,B,RG,RB,GB,R^2,G^2,B^2 + //R^2B,R^2G,G^2,R,G^2B,B^2R,B^2G,RGB + RGBmat.Set(j, 2, m_BforLab[j]); + RGBmat.Set(j, 1, m_GforLab[j]); + RGBmat.Set(j, 0, m_RforLab[j]); + //2V次の項 + RGBmat.Set(j, 3, m_RforLab[j] * m_GforLab[j]); + RGBmat.Set(j, 4, m_RforLab[j] * m_BforLab[j]); + RGBmat.Set(j, 5, m_GforLab[j] * m_BforLab[j]); + RGBmat.Set(j, 6, m_RforLab[j] * m_RforLab[j]); + RGBmat.Set(j, 7, m_GforLab[j] * m_GforLab[j]); + RGBmat.Set(j, 8, m_BforLab[j] * m_BforLab[j]); + //3V次の項 + RGBmat.Set(j, 9, m_RforLab[j] * m_RforLab[j] * m_BforLab[j]); + RGBmat.Set(j, 10, m_RforLab[j] * m_RforLab[j] * m_GforLab[j]); + RGBmat.Set(j, 11, m_GforLab[j] * m_GforLab[j] * m_RforLab[j]); + RGBmat.Set(j, 12, m_GforLab[j] * m_GforLab[j] * m_BforLab[j]); + RGBmat.Set(j, 13, m_BforLab[j] * m_BforLab[j] * m_RforLab[j]); + RGBmat.Set(j, 14, m_BforLab[j] * m_BforLab[j] * m_GforLab[j]); + RGBmat.Set(j, 15, m_RforLab[j] * m_BforLab[j] * m_GforLab[j]); + } + // 変換行列の生成 + Mat translation = new Mat(); + var canSolve = Cv2.Solve(RGBmat, XYZmat, translation, DecompTypes.SVD); + + // 保存 + string CSVfilename = "translateMatrix.csv"; + FileStream CSV_file = File.Open(CSVfilename, FileMode.OpenOrCreate, FileAccess.Write); + CSV_file.Seek(0, SeekOrigin.Begin); + CSV_file.SetLength(0); + CSV_file.Close(); + StreamWriter CSV_data = new StreamWriter(CSVfilename); + string s2 = ""; + for (int i = 0; i <= 16; i++) + { + for (int j = 0; j <= 2; j++) + { + double s1 = translation.At(i, j); + s2 += s1.ToString() + ","; + } + CSV_data.WriteLine(s2); + s2 = ""; + } + CSV_data.Close(); + } + + private void Read_TranslationMatrix() + { + // 変換行列を読み込みなおす + System.Text.Encoding encoding = GetType("translateMatrix.csv"); + System.IO.FileStream fs1 = new System.IO.FileStream("translateMatrix.csv", System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.IO.StreamReader sr1 = new System.IO.StreamReader(fs1, encoding); + for (int i = 0; i < 17; i++) + { + a[i] = 0; + b[i] = 0; + c[i] = 0; + } + k = 0; + string strLine = ""; + string[] aryLine = null; + while ((strLine = sr1.ReadLine()) != null) + { + aryLine = strLine.Split(','); + a[k] = Convert.ToSingle(aryLine[0]); + b[k] = Convert.ToSingle(aryLine[1]); + c[k] = Convert.ToSingle(aryLine[2]); + k++; + } + sr1.Close(); + fs1.Close(); + } + + private OpenCvSharp.Scalar CalcLab(OpenCvSharp.Scalar BgrValue) + { + // CIELabの計算 + // XYZに変換 + double X, Y, Z; + double m_B = BgrValue.Val0; + double m_G = BgrValue.Val1; + double m_R = BgrValue.Val2; + X = m_R * a[0] + m_G * a[1] + m_B * a[2] + + a[3] * m_R * m_G + a[4] * m_R * m_B + a[5] * m_G * m_B + + a[6] * m_R * m_R + a[7] * m_G * m_G + a[8] * m_B * m_B + + a[9] * m_R * m_R * m_B + a[10] * m_R * m_R * m_G + + a[11] * m_G * m_G * m_R + a[12] * m_G * m_G * m_B + + a[13] * m_B * m_B * m_R + a[14] * m_B * m_B * m_G + + a[15] * m_R * m_G * m_B + + a[16]; + Y = m_R * b[0] + m_G * b[1] + m_B * b[2] + + b[3] * m_R * m_G + b[4] * m_R * m_B + b[5] * m_G * m_B + + b[6] * m_R * m_R + b[7] * m_G * m_G + b[8] * m_B * m_B + + b[9] * m_R * m_R * m_B + b[10] * m_R * m_R * m_G + + b[11] * m_G * m_G * m_R + b[12] * m_G * m_G * m_B + + b[13] * m_B * m_B * m_R + b[14] * m_B * m_B * m_G + + b[15] * m_R * m_G * m_B + + b[16]; + Z = m_R * c[0] + m_G * c[1] + m_B * c[2] + + c[3] * m_R * m_G + c[4] * m_R * m_B + c[5] * m_G * m_B + + c[6] * m_R * m_R + c[7] * m_G * m_G + c[8] * m_B * m_B + + c[9] * m_R * m_R * m_B + c[10] * m_R * m_R * m_G + + c[11] * m_G * m_G * m_R + c[12] * m_G * m_G * m_B + + c[13] * m_B * m_B * m_R + c[14] * m_B * m_B * m_G + + c[15] * m_R * m_G * m_B + + c[16]; + if (X < 0) X = 0; + if (Y < 0) Y = 0; + if (Z < 0) Z = 0; + + // Labに変換(固定の計算式) + // TIAS 光源 (測定値20201023)  + // double Xn = 99.5829; + // double Yn = 100.0; + // double Zn = 57.1402; + + // Tangさん,竹田さんが使用してた値 (おそらく昔のTIAS光源の測定値) + //double Xn = 102.07; + //double Yn = 100.0; + //double Zn = 79.41; + + // 石川さん,中口先生が使用している値 人口太陽照明? + double Xn = 92.219; + double Yn = 100.0; + double Zn = 95.965; + double cL = 116.0 * Math.Pow((Y / Yn), 1.0 / 3.0) - 16.0; + double ca = 500.0 * (Math.Pow((X / Xn), 1.0 / 3.0) - Math.Pow((Y / Yn), 1.0 / 3.0)); + double cb = 200.0 * (Math.Pow((Y / Yn), 1.0 / 3.0) - Math.Pow((Z / Zn), 1.0 / 3.0)); + + return new OpenCvSharp.Scalar(cL, ca, cb); + } + + private void Show8colors(List list_8Bgr, List list_8Lab) + { + Invoke((MethodInvoker)delegate + { + textBox1.Text = list_8Bgr[0].ToString() + " " + list_8Bgr[1].ToString(); + textBox2.Text = list_8Bgr[2].ToString() + " " + list_8Bgr[3].ToString(); + textBox3.Text = list_8Bgr[4].ToString() + " " + list_8Bgr[5].ToString(); + textBox4.Text = list_8Bgr[6].ToString() + " " + list_8Bgr[7].ToString(); + textBox5.Text = list_8Lab[0].ToString() + " " + list_8Lab[1].ToString(); + textBox6.Text = list_8Lab[2].ToString() + " " + list_8Lab[3].ToString(); + textBox7.Text = list_8Lab[4].ToString() + " " + list_8Lab[5].ToString(); + textBox8.Text = list_8Lab[6].ToString() + " " + list_8Lab[7].ToString(); + }); + } + + private void Write8colors(List list_8Bgr, List list_8Lab) + { + // 保存 + string CSVfilename = "CalculatedLab.csv"; + FileStream CSV_file = File.Open(CSVfilename, FileMode.OpenOrCreate, FileAccess.Write); + CSV_file.Seek(0, SeekOrigin.Begin); + CSV_file.SetLength(0); + CSV_file.Close(); + + StreamWriter CSV_data = new StreamWriter(CSVfilename); + CSV_data.WriteLine("Area,R,G,B,L,a,B"); + for (int i = 0; i < list_8Bgr.Count(); i++) + { + string str = (i + 1).ToString() + ","; + str += + list_8Bgr[i].Val2.ToString("0.0000") + "," + + list_8Bgr[i].Val1.ToString("0.0000") + "," + + list_8Bgr[i].Val0.ToString("0.0000") + "," + + list_8Lab[i].Val0.ToString("0.0000") + "," + + list_8Lab[i].Val1.ToString("0.0000") + "," + + list_8Lab[i].Val2.ToString("0.0000"); + CSV_data.WriteLine(str); + } + CSV_data.Close(); + } + + private List IndexOfAll(List li, int target) + { + int num = li.IndexOf(target); + var li_num = new List(); + if (num > 0) + { + li_num.Add(num); + // IndexOfメソッドで見つからなくなるまで繰り返す + while (num > 0) + { + //見つかった位置の次の位置から検索 + num = li.IndexOf(target, num + 1); + if (num > 0) + { + li_num.Add(num); + } + } + } + else + { + Console.WriteLine("{0}は見つかりませんでした", target); + } + return li_num; + } + + + public static System.Text.Encoding GetType(string FILE_NAME) + { + System.IO.FileStream fs = new System.IO.FileStream(FILE_NAME, System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.Text.Encoding r = GetType(fs); + fs.Close(); + return r; + } + + public static System.Text.Encoding GetType(System.IO.FileStream fs) + { + byte[] Unicode = new byte[] { 0xFF, 0xFE, 0x41 }; + byte[] UnicodeBIG = new byte[] { 0xFE, 0xFF, 0x00 }; + byte[] UTF8 = new byte[] { 0xEF, 0xBB, 0xBF }; + System.Text.Encoding reVal = System.Text.Encoding.Default; + + System.IO.BinaryReader r = new System.IO.BinaryReader(fs, System.Text.Encoding.Default); + int i; + int.TryParse(fs.Length.ToString(), out i); + byte[] ss = r.ReadBytes(i); + if (IsUTF8Bytes(ss) || (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF)) + { + reVal = System.Text.Encoding.UTF8; + } + else if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00) + { + reVal = System.Text.Encoding.BigEndianUnicode; + } + else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41) + { + reVal = System.Text.Encoding.Unicode; + } + r.Close(); + return reVal; + } + + private static bool IsUTF8Bytes(byte[] data) + { + int charByteCounter = 1; + byte curByte; + for (int i = 0; i < data.Length; i++) + { + curByte = data[i]; + if (charByteCounter == 1) + { + if (curByte >= 0x80) + { + while (((curByte <<= 1) & 0x80) != 0) + { + charByteCounter++; + } + if (charByteCounter == 1 || charByteCounter > 6) + { + return false; + } + } + } + else + { + if ((curByte & 0xC0) != 0x80) + { + return false; + } + charByteCounter--; + } + } + if (charByteCounter > 1) + { + throw new Exception("Error"); + } + return true; + } + + } +} diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTIAS1.9.csproj b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTIAS1.9.csproj index dae0f1c..882082c 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTIAS1.9.csproj +++ b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTIAS1.9.csproj @@ -75,6 +75,7 @@ DeepTongue_Icon.ico + Form diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs index bd233d3..277b527 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs @@ -34,6 +34,8 @@ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.label_mode = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); + this.pictureBox_detection = new System.Windows.Forms.PictureBox(); + this.pictureBox_input = new System.Windows.Forms.PictureBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); @@ -42,6 +44,7 @@ this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); + this.pictureBox_cropResized = new System.Windows.Forms.PictureBox(); this.pictureBox_output = new System.Windows.Forms.PictureBox(); this.pictureBox_outputSRG = new System.Windows.Forms.PictureBox(); this.pictureBox_maskSRG = new System.Windows.Forms.PictureBox(); @@ -51,23 +54,20 @@ this.panel2 = new System.Windows.Forms.Panel(); this.button_pause = new System.Windows.Forms.Button(); this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); - this.pictureBox_cropResized = new System.Windows.Forms.PictureBox(); - this.pictureBox_detection = new System.Windows.Forms.PictureBox(); - this.pictureBox_input = new System.Windows.Forms.PictureBox(); this.panel3 = new System.Windows.Forms.Panel(); - this.button_mode = new System.Windows.Forms.Button(); - this.textBox1 = new System.Windows.Forms.TextBox(); + this.comboBox_mode = new System.Windows.Forms.ComboBox(); + this.label9 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_extraction)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_detection)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_input)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_cropResized)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_output)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_outputSRG)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_maskSRG)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_last)).BeginInit(); this.panel2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_cropResized)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_detection)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_input)).BeginInit(); this.panel3.SuspendLayout(); this.SuspendLayout(); // @@ -102,7 +102,7 @@ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F)); - this.tableLayoutPanel1.Controls.Add(this.panel3, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.panel3, 2, 4); this.tableLayoutPanel1.Controls.Add(this.label_mode, 1, 5); this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 4); this.tableLayoutPanel1.Controls.Add(this.pictureBox_detection, 1, 0); @@ -123,8 +123,7 @@ this.tableLayoutPanel1.Controls.Add(this.pictureBox_last, 3, 2); this.tableLayoutPanel1.Controls.Add(this.label_processingFileName, 0, 5); this.tableLayoutPanel1.Controls.Add(this.label_totalProgress, 2, 5); - this.tableLayoutPanel1.Controls.Add(this.panel2, 3, 4); - this.tableLayoutPanel1.Controls.Add(this.textBox1, 2, 4); + this.tableLayoutPanel1.Controls.Add(this.panel2, 1, 4); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); @@ -137,6 +136,11 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(1018, 554); this.tableLayoutPanel1.TabIndex = 5; // @@ -149,7 +153,6 @@ this.label_mode.Name = "label_mode"; this.label_mode.Size = new System.Drawing.Size(246, 21); this.label_mode.TabIndex = 22; - this.label_mode.Text = "mode="; this.label_mode.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // panel1 @@ -162,6 +165,28 @@ this.panel1.Size = new System.Drawing.Size(246, 49); this.panel1.TabIndex = 6; // + // pictureBox_detection + // + this.pictureBox_detection.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox_detection.Location = new System.Drawing.Point(257, 4); + this.pictureBox_detection.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); + this.pictureBox_detection.Name = "pictureBox_detection"; + this.pictureBox_detection.Size = new System.Drawing.Size(250, 209); + this.pictureBox_detection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox_detection.TabIndex = 2; + this.pictureBox_detection.TabStop = false; + // + // pictureBox_input + // + this.pictureBox_input.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox_input.Location = new System.Drawing.Point(3, 4); + this.pictureBox_input.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); + this.pictureBox_input.Name = "pictureBox_input"; + this.pictureBox_input.Size = new System.Drawing.Size(250, 209); + this.pictureBox_input.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox_input.TabIndex = 1; + this.pictureBox_input.TabStop = false; + // // label1 // this.label1.AutoSize = true; @@ -258,6 +283,17 @@ this.label8.Text = "Gloss"; this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // + // pictureBox_cropResized + // + this.pictureBox_cropResized.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox_cropResized.Location = new System.Drawing.Point(511, 4); + this.pictureBox_cropResized.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); + this.pictureBox_cropResized.Name = "pictureBox_cropResized"; + this.pictureBox_cropResized.Size = new System.Drawing.Size(250, 209); + this.pictureBox_cropResized.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox_cropResized.TabIndex = 3; + this.pictureBox_cropResized.TabStop = false; + // // pictureBox_output // this.pictureBox_output.Dock = System.Windows.Forms.DockStyle.Fill; @@ -327,7 +363,7 @@ // this.panel2.Controls.Add(this.button_pause); this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel2.Location = new System.Drawing.Point(767, 479); + this.panel2.Location = new System.Drawing.Point(259, 479); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(246, 47); this.panel2.TabIndex = 21; @@ -349,69 +385,41 @@ this.backgroundWorker1.WorkerSupportsCancellation = true; this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.BackgroundWorker1_DoWork); // - // pictureBox_cropResized - // - this.pictureBox_cropResized.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox_cropResized.Location = new System.Drawing.Point(511, 4); - this.pictureBox_cropResized.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); - this.pictureBox_cropResized.Name = "pictureBox_cropResized"; - this.pictureBox_cropResized.Size = new System.Drawing.Size(250, 209); - this.pictureBox_cropResized.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox_cropResized.TabIndex = 3; - this.pictureBox_cropResized.TabStop = false; - // - // pictureBox_detection - // - this.pictureBox_detection.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox_detection.Location = new System.Drawing.Point(257, 4); - this.pictureBox_detection.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); - this.pictureBox_detection.Name = "pictureBox_detection"; - this.pictureBox_detection.Size = new System.Drawing.Size(250, 209); - this.pictureBox_detection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox_detection.TabIndex = 2; - this.pictureBox_detection.TabStop = false; - // - // pictureBox_input - // - this.pictureBox_input.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox_input.Location = new System.Drawing.Point(3, 4); - this.pictureBox_input.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); - this.pictureBox_input.Name = "pictureBox_input"; - this.pictureBox_input.Size = new System.Drawing.Size(250, 209); - this.pictureBox_input.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox_input.TabIndex = 1; - this.pictureBox_input.TabStop = false; - // // panel3 // - this.panel3.Controls.Add(this.button_mode); + this.panel3.Controls.Add(this.label9); + this.panel3.Controls.Add(this.comboBox_mode); this.panel3.Dock = System.Windows.Forms.DockStyle.Left; - this.panel3.Location = new System.Drawing.Point(257, 478); + this.panel3.Location = new System.Drawing.Point(511, 478); this.panel3.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(246, 49); this.panel3.TabIndex = 23; // - // button_mode + // comboBox_mode // - this.button_mode.Dock = System.Windows.Forms.DockStyle.Fill; - this.button_mode.Location = new System.Drawing.Point(0, 0); - this.button_mode.Margin = new System.Windows.Forms.Padding(1, 2, 1, 2); - this.button_mode.Name = "button_mode"; - this.button_mode.Size = new System.Drawing.Size(246, 49); - this.button_mode.TabIndex = 0; - this.button_mode.Text = "Mode"; - this.button_mode.UseVisualStyleBackColor = true; - this.button_mode.Click += new System.EventHandler(this.button_mode_Click); + this.comboBox_mode.Dock = System.Windows.Forms.DockStyle.Bottom; + this.comboBox_mode.FormattingEnabled = true; + this.comboBox_mode.Items.AddRange(new object[] { + "Image", + "Image&Calib.csv", + "Image&Calib.csv&Mask"}); + this.comboBox_mode.Location = new System.Drawing.Point(0, 29); + this.comboBox_mode.Name = "comboBox_mode"; + this.comboBox_mode.Size = new System.Drawing.Size(246, 20); + this.comboBox_mode.TabIndex = 0; + this.comboBox_mode.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // - // textBox1 + // label9 // - this.textBox1.AcceptsReturn = true; - this.textBox1.Location = new System.Drawing.Point(513, 479); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(246, 19); - this.textBox1.TabIndex = 24; - this.textBox1.Visible = false; + this.label9.AutoSize = true; + this.label9.Dock = System.Windows.Forms.DockStyle.Fill; + this.label9.Font = new System.Drawing.Font("Arial Narrow", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label9.Location = new System.Drawing.Point(0, 0); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(47, 24); + this.label9.TabIndex = 1; + this.label9.Text = "Input"; // // Form1 // @@ -424,19 +432,21 @@ this.Name = "Form1"; this.Text = "DeepTIAS1.8"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_extraction)).EndInit(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_detection)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_input)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox_cropResized)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_output)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_outputSRG)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_maskSRG)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox_last)).EndInit(); this.panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_cropResized)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_detection)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox_input)).EndInit(); this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); this.ResumeLayout(false); } @@ -465,12 +475,12 @@ private System.Windows.Forms.Button button_pause; private System.Windows.Forms.Label label_totalProgress; private System.Windows.Forms.Label label_mode; - private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Button button_mode; private System.Windows.Forms.PictureBox pictureBox_detection; private System.Windows.Forms.PictureBox pictureBox_input; private System.Windows.Forms.PictureBox pictureBox_cropResized; - private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.ComboBox comboBox_mode; + private System.Windows.Forms.Label label9; } } diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs index f8ace4b..dc370ee 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs @@ -78,10 +78,14 @@ "Width" + "," + "Height" + "," + "Area" + "," + "Gloss Count"); } + private void Form1_Load(object sender, EventArgs e) + { + comboBox_mode.SelectedIndex = 0; + } + [Conditional("DEBUG")] private void ShowDebugBox() { - textBox1.Visible = true; } private void Button_start_Click(object sender, EventArgs e) @@ -334,6 +338,7 @@ private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { + using (MemoryStream ms = new MemoryStream()) { for (int a = 0; a < path.Length; a++) @@ -956,7 +961,7 @@ Console.WriteLine("file closed"); } - private void button_mode_Click(object sender, EventArgs e) + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { }