diff --git a/.gitignore b/.gitignore index 5f072cf..387ac1d 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ *.resources *.xml *.config +*.pb diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj index f1b098b..b069c3c 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj +++ b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj @@ -106,10 +106,9 @@ - - Always - + + diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs index d00ddbb..822cbd3 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.Designer.cs @@ -76,7 +76,7 @@ this.button_start.TabIndex = 0; this.button_start.Text = "Start"; this.button_start.UseVisualStyleBackColor = true; - this.button_start.Click += new System.EventHandler(this.button_start_Click); + this.button_start.Click += new System.EventHandler(this.Button_start_Click); // // pictureBox_input // @@ -361,7 +361,7 @@ // backgroundWorker1 // this.backgroundWorker1.WorkerSupportsCancellation = true; - this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.BackgroundWorker1_DoWork); // // Form1 // diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs index 45342f4..d9e4657 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs @@ -65,7 +65,7 @@ InitializeComponent(); } - private void button_start_Click(object sender, EventArgs e) + private void Button_start_Click(object sender, EventArgs e) { path = Directory.GetFiles("data"); button_start.Enabled = false; @@ -312,7 +312,7 @@ return bmp; } - private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { using (MemoryStream ms = new MemoryStream()) { @@ -334,315 +334,313 @@ mat_drawBox = mat_input.Clone(); mat_cropped = new Mat(mat_input.Size(), MatType.CV_8UC3, 1); byte_inputDetection = Bitmap2Byte(bitmap_bitch); - //using (var graph = new TFGraph()) - //{ - // var model = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/Detection_Normal.pb"); - // graph.Import(model, ""); + using (var graph = new TFGraph()) + { + var model = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/Detection_Normal.pb"); + graph.Import(model, ""); - // using (var session = new TFSession(graph)) - // { - // var tensor = ImageUtil.CreateTensorFromImageFile(byte_inputDetection, TFDataType.UInt8); + using (var session = new TFSession(graph)) + { + var tensor = ImageUtil.CreateTensorFromImageFile(byte_inputDetection, TFDataType.UInt8); - // var runner = session.GetRunner(); - // runner + var runner = session.GetRunner(); + runner - // .AddInput(graph["image_tensor"][0], tensor) - // .Fetch("detection_boxes", "detection_scores", "detection_classes", "num_detections"); + .AddInput(graph["image_tensor"][0], tensor) + .Fetch("detection_boxes", "detection_scores", "detection_classes", "num_detections"); - // var output = runner.Run(); - // var boxes = (float[,,])output[0].GetValue(); - // var scores = (float[,])output[1].GetValue(); - // //var classes = (float[,])output[2].GetValue(); - // //var detections = (float[])output[3].GetValue(); + var output = runner.Run(); + var boxes = (float[,,])output[0].GetValue(); + var scores = (float[,])output[1].GetValue(); + //var classes = (float[,])output[2].GetValue(); + //var detections = (float[])output[3].GetValue(); - // check_detection = 0; - // max_score = 0; + check_detection = 0; + max_score = 0; - // for (int i = 0; i < scores.Length; i++) - // { - // if ((scores[0, i] > 0.5) && (scores[0, i] > max_score)) - // { - // max_score = scores[0, i]; - // float y_min = boxes[0, i, 0] * (float)bitmap_bitch.Height; - // float x_min = boxes[0, i, 1] * (float)bitmap_bitch.Width; - // float y_max = boxes[0, i, 2] * (float)bitmap_bitch.Height; - // float x_max = boxes[0, i, 3] * (float)bitmap_bitch.Width; - // P1.X = (int)x_min; - // P1.Y = (int)y_min; - // P2.X = (int)x_max; - // P2.Y = (int)y_max; - // Cv2.Rectangle(mat_drawBox, P1, P2, new Scalar(0, 255, 0), 5); - // rectangle.X = (int)x_min; - // rectangle.Y = (int)y_min; - // rectangle.Width = (int)(x_max - x_min); - // rectangle.Height = (int)(y_max - y_min); + for (int i = 0; i < scores.Length; i++) + { + if ((scores[0, i] > 0.5) && (scores[0, i] > max_score)) + { + max_score = scores[0, i]; + float y_min = boxes[0, i, 0] * (float)bitmap_bitch.Height; + float x_min = boxes[0, i, 1] * (float)bitmap_bitch.Width; + float y_max = boxes[0, i, 2] * (float)bitmap_bitch.Height; + float x_max = boxes[0, i, 3] * (float)bitmap_bitch.Width; + P1.X = (int)x_min; + P1.Y = (int)y_min; + P2.X = (int)x_max; + P2.Y = (int)y_max; + Cv2.Rectangle(mat_drawBox, P1, P2, new Scalar(0, 255, 0), 5); + rectangle.X = (int)x_min; + rectangle.Y = (int)y_min; + rectangle.Width = (int)(x_max - x_min); + rectangle.Height = (int)(y_max - y_min); - // check_detection = 1; - // } - // } - // } - //} - //if (check_detection == 1) - //{ - // mat_drawBox.SaveImage(basepath + "\\detection" + imageFile); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_drawBox); - // pictureBox_detection.Image = bitmap_bitch; - // pictureBox_detection.Refresh(); - // label1.BackColor = Color.White; - // label2.BackColor = Color.Red; - //} - //else - //{ - // MessageBox.Show("Error: Sorry can not detect any tongue in this image. Press [OK] to skip preprocessing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - // time = DateTime.Now.ToLocalTime().ToString(); - // File.AppendAllText("DetectionFailedLog.txt ", time + " " + imageFile + "\n"); - // pictureBox_detection.Image = null; - // pictureBox_detection.Refresh(); - // pictureBox_cropResized.Image = null; - // pictureBox_cropResized.Refresh(); - // pictureBox_output.Image = null; - // pictureBox_output.Refresh(); - // pictureBox_outputSRG.Image = null; - // pictureBox_outputSRG.Refresh(); - // pictureBox_maskSRG.Image = null; - // pictureBox_maskSRG.Refresh(); - // pictureBox_extraction.Image = null; - // pictureBox_extraction.Refresh(); - // pictureBox_contract.Image = null; - // pictureBox_contract.Refresh(); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); - // byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); + check_detection = 1; + } + } + } + } + if (check_detection == 1) + { + mat_drawBox.SaveImage(basepath + "\\detection" + imageFile); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_drawBox); + pictureBox_detection.Image = bitmap_bitch; + pictureBox_detection.Refresh(); + label1.BackColor = Color.White; + label2.BackColor = Color.Red; + } + else + { + MessageBox.Show("Error: Sorry can not detect any tongue in this image. Press [OK] to skip preprocessing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + time = DateTime.Now.ToLocalTime().ToString(); + File.AppendAllText("DetectionFailedLog.txt ", time + " " + imageFile + "\n"); + pictureBox_detection.Image = null; + pictureBox_detection.Refresh(); + pictureBox_cropResized.Image = null; + pictureBox_cropResized.Refresh(); + pictureBox_output.Image = null; + pictureBox_output.Refresh(); + pictureBox_outputSRG.Image = null; + pictureBox_outputSRG.Refresh(); + pictureBox_maskSRG.Image = null; + pictureBox_maskSRG.Refresh(); + pictureBox_extraction.Image = null; + pictureBox_extraction.Refresh(); + pictureBox_contract.Image = null; + pictureBox_contract.Refresh(); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); + byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); - // Thread.Sleep(1000); - // modelFile = DownloadDefaultModel_noBoxPix2Pix(basepath); - // using (var graph = new TFGraph()) - // { - // var model = File.ReadAllBytes(modelFile); - // graph.Import(model, ""); + Thread.Sleep(1000); + modelFile = DownloadDefaultModel_noBoxPix2Pix(basepath); + using (var graph = new TFGraph()) + { + var model = File.ReadAllBytes(modelFile); + graph.Import(model, ""); - // using (var session = new TFSession(graph)) - // { - // var tensor = ImageUtil2.CreateTensorFromImageFile(byte_inputSegmentation); + using (var session = new TFSession(graph)) + { + var tensor = ImageUtil2.CreateTensorFromImageFile(byte_inputSegmentation); - // var runner = session.GetRunner(); - // runner - // .AddInput(graph["generator/input_image"][0], tensor) - // .Fetch(graph["generator/prediction"][0]); - // var output = runner.Run(); - // float[,,,] resultfloat = (float[,,,])output[0].GetValue(jagged: false); + var runner = session.GetRunner(); + runner + .AddInput(graph["generator/input_image"][0], tensor) + .Fetch(graph["generator/prediction"][0]); + var output = runner.Run(); + float[,,,] resultfloat = (float[,,,])output[0].GetValue(jagged: false); - // for (int p = 0; p < 256; p++) - // { - // for (int q = 0; q < 256; q++) - // { - // float check = resultfloat[0, p, q, 0]; - // if (check < 0) - // { - // mask[ii] = 0; - // } - // else - // { - // mask[ii] = 255; - // } - // ii++; - // } - // } - // } - // } - // Thread.Sleep(1000); - // bitmap_bitch = ToGrayBitmap(mask, 256, 256); - // mat_outputNoBox = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputNoBox); - // pictureBox_output.Image = bitmap_bitch; - // pictureBox_output.Refresh(); - // label1.BackColor = Color.White; - // label4.BackColor = Color.Red; - // mat_outputNoBox.SaveImage(basepath + "\\output256" + imageFile); - // try - // { - // RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\output_changed1" + imageFile, 500, 1, 1); - // RemoveSmallRegion(basepath + "\\output_changed1" + imageFile, basepath + "\\output_changed2" + imageFile, 500, 0, 0); - // } - // catch - // { - // MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - // break; - // } - // mat_outputSRGNoBox = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.GrayScale); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRGNoBox); - // pictureBox_outputSRG.Image = bitmap_bitch; - // pictureBox_outputSRG.Refresh(); - // label4.BackColor = Color.White; - // label5.BackColor = Color.Red; - // Cv2.Resize(mat_outputSRGNoBox, mat_mask, mat_input.Size()); - // mat_mask.SaveImage(basepath + "\\mask" + imageFile); - // try - // { - // RemoveSmallRegion(basepath + "\\mask" + imageFile, basepath + "\\mask_changed1" + imageFile, 500, 1, 1); - // RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 500, 0, 0); - // } - // catch - // { - // MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - // break; - // } - // mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.GrayScale); - // Cv2.Threshold(mat_maskSRG, mat_maskSRG, 128, 255, ThresholdTypes.Binary); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_maskSRG); - // pictureBox_maskSRG.Image = bitmap_bitch; - // pictureBox_maskSRG.Refresh(); - // label5.BackColor = Color.White; - // label6.BackColor = Color.Red; - // mat_extraction = mat_input.Clone(); - // for (int i = 0; i < mat_input.Height; i++) - // { - // for (int j = 0; j < mat_input.Width; j++) - // { - // Vec3b pix = mat_extraction.At(i, j); - // if (mat_maskSRG.At(i, j) == 0) - // { - // pix[0] = (byte)(255); - // pix[1] = (byte)(255); - // pix[2] = (byte)(255); - // mat_extraction.Set(i, j, pix); - // } - // else - // { - // pix[0] = (byte)(mat_extraction.At(i, j).Item0); - // pix[1] = (byte)(mat_extraction.At(i, j).Item1); - // pix[2] = (byte)(mat_extraction.At(i, j).Item2); - // mat_extraction.Set(i, j, pix); - // } - // } - // } - // mat_extraction.SaveImage(basepath + "\\extraction" + imageFile); - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_extraction); - // pictureBox_extraction.Image = bitmap_bitch; - // pictureBox_extraction.Refresh(); - // label6.BackColor = Color.White; - // label7.BackColor = Color.Red; - // bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); - // pictureBox_contract.Image = bitmap_bitch; - // pictureBox_contract.Refresh(); - // label7.BackColor = Color.White; - // label8.BackColor = Color.Red; - // continue; - //} - //for (int i = P1.Y; i < P2.Y; i++) - //{ - // for (int j = P1.X; j < P2.X; j++) - // { - // Vec3b pix = mat_input.At(i, j); - // mat_cropped.Set(i, j, pix); - // } - //} - //mat_cropped.SaveImage(basepath + "\\cropped" + imageFile); - //OpenCvSharp.Size size_roi = new OpenCvSharp.Size(); - //size_roi.Height = rectangle.Height; - //size_roi.Width = rectangle.Width; - //roi = new Rect(P1, size_roi); - //mat_roisize = mat_input.Clone(roi); - //Cv2.Resize(mat_roisize, mat_roi, mat_roi256.Size()); - //mat_roi.SaveImage(basepath + "\\cropresized" + imageFile); - //bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_roi); - //pictureBox_cropResized.Image = bitmap_bitch; - //pictureBox_cropResized.Refresh(); - //label2.BackColor = Color.White; - //label3.BackColor = Color.Red; - //byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); - //Thread.Sleep(1000); - //modelFile = DownloadDefaultModel(basepath); - //using (var graph = new TFGraph()) - //{ - // var model = File.ReadAllBytes(modelFile); - // graph.Import(model, ""); + for (int p = 0; p < 256; p++) + { + for (int q = 0; q < 256; q++) + { + float check = resultfloat[0, p, q, 0]; + if (check < 0) + { + mask[ii] = 0; + } + else + { + mask[ii] = 255; + } + ii++; + } + } + } + } + Thread.Sleep(1000); + bitmap_bitch = ToGrayBitmap(mask, 256, 256); + mat_outputNoBox = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputNoBox); + pictureBox_output.Image = bitmap_bitch; + pictureBox_output.Refresh(); + label1.BackColor = Color.White; + label4.BackColor = Color.Red; + mat_outputNoBox.SaveImage(basepath + "\\output256" + imageFile); + try + { + RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\output_changed1" + imageFile, 500, 1, 1); + RemoveSmallRegion(basepath + "\\output_changed1" + imageFile, basepath + "\\output_changed2" + imageFile, 500, 0, 0); + } + catch + { + MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + break; + } + mat_outputSRGNoBox = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.Grayscale); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRGNoBox); + pictureBox_outputSRG.Image = bitmap_bitch; + pictureBox_outputSRG.Refresh(); + label4.BackColor = Color.White; + label5.BackColor = Color.Red; + Cv2.Resize(mat_outputSRGNoBox, mat_mask, mat_input.Size()); + mat_mask.SaveImage(basepath + "\\mask" + imageFile); + try + { + RemoveSmallRegion(basepath + "\\mask" + imageFile, basepath + "\\mask_changed1" + imageFile, 500, 1, 1); + RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 500, 0, 0); + } + catch + { + MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + break; + } + mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.Grayscale); + Cv2.Threshold(mat_maskSRG, mat_maskSRG, 128, 255, ThresholdTypes.Binary); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_maskSRG); + pictureBox_maskSRG.Image = bitmap_bitch; + pictureBox_maskSRG.Refresh(); + label5.BackColor = Color.White; + label6.BackColor = Color.Red; + mat_extraction = mat_input.Clone(); + for (int i = 0; i < mat_input.Height; i++) + { + for (int j = 0; j < mat_input.Width; j++) + { + Vec3b pix = mat_extraction.At(i, j); + if (mat_maskSRG.At(i, j) == 0) + { + pix[0] = (byte)(255); + pix[1] = (byte)(255); + pix[2] = (byte)(255); + mat_extraction.Set(i, j, pix); + } + else + { + pix[0] = (byte)(mat_extraction.At(i, j).Item0); + pix[1] = (byte)(mat_extraction.At(i, j).Item1); + pix[2] = (byte)(mat_extraction.At(i, j).Item2); + mat_extraction.Set(i, j, pix); + } + } + } + mat_extraction.SaveImage(basepath + "\\extraction" + imageFile); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_extraction); + pictureBox_extraction.Image = bitmap_bitch; + pictureBox_extraction.Refresh(); + label6.BackColor = Color.White; + label7.BackColor = Color.Red; + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); + pictureBox_contract.Image = bitmap_bitch; + pictureBox_contract.Refresh(); + label7.BackColor = Color.White; + label8.BackColor = Color.Red; + continue; + } + for (int i = P1.Y; i < P2.Y; i++) + { + for (int j = P1.X; j < P2.X; j++) + { + Vec3b pix = mat_input.At(i, j); + mat_cropped.Set(i, j, pix); + } + } + mat_cropped.SaveImage(basepath + "\\cropped" + imageFile); + OpenCvSharp.Size size_roi = new OpenCvSharp.Size(); + size_roi.Height = rectangle.Height; + size_roi.Width = rectangle.Width; + roi = new Rect(P1, size_roi); + mat_roisize = mat_input.Clone(roi); + Cv2.Resize(mat_roisize, mat_roi, mat_roi256.Size()); + mat_roi.SaveImage(basepath + "\\cropresized" + imageFile); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_roi); + pictureBox_cropResized.Image = bitmap_bitch; + pictureBox_cropResized.Refresh(); + label2.BackColor = Color.White; + label3.BackColor = Color.Red; + byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); + Thread.Sleep(1000); + modelFile = DownloadDefaultModel(basepath); + using (var graph = new TFGraph()) + { + var model = File.ReadAllBytes(modelFile); + graph.Import(model, ""); - // using (var session = new TFSession(graph)) - // { - // var tensor = ImageUtil2.CreateTensorFromImageFile(byte_inputSegmentation); - // var runner = session.GetRunner(); - // runner - // //.AddInput(graph["generator/input_image"][0], tensor) - // //.Fetch(graph["generator/prediction"][0]); + using (var session = new TFSession(graph)) + { + var tensor = ImageUtil2.CreateTensorFromImageFile(byte_inputSegmentation); + var runner = session.GetRunner(); + runner + .AddInput(graph["generator/input_image"][0], tensor) + .Fetch(graph["generator/prediction"][0]); - // .AddInput(graph["input_image"][0], tensor) - // .Fetch(graph["generator1/decoder_1/Tanh"][0]); + //.AddInput(graph["input_image"][0], tensor) + //.Fetch(graph["generator1/decoder_1/Tanh"][0]); - // var output = runner.Run(); - // float[,,,] resultfloat = (float[,,,])output[0].GetValue(jagged: false); + var output = runner.Run(); + float[,,,] resultfloat = (float[,,,])output[0].GetValue(jagged: false); - // for (int p = 0; p < 256; p++) - // { - // for (int q = 0; q < 256; q++) - // { - // float check = resultfloat[0, p, q, 0]; - // if (check < 0) - // { - // mask[ii] = 0; - // } - // else - // { - // mask[ii] = 255; - // } - // ii++; - // } - // } - // } - //} - //Thread.Sleep(1000); - //bitmap_bitch = ToGrayBitmap(mask, 256, 256); - //mat_output = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); - //bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_output); - //pictureBox_output.Image = bitmap_bitch; - //pictureBox_output.Refresh(); - //label3.BackColor = Color.White; - //label4.BackColor = Color.Red; - //mat_output.SaveImage(basepath + "\\output256" + imageFile); - //try - //{ - // RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\output_changed1" + imageFile, 500, 1, 1); - // RemoveSmallRegion(basepath + "\\output_changed1" + imageFile, basepath + "\\output_changed2" + imageFile, 500, 0, 0); - //} - //catch - //{ - // MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - // break; - //} - //mat_outputSRG = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.GrayScale); - //bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRG); - //pictureBox_outputSRG.Image = bitmap_bitch; - //pictureBox_outputSRG.Refresh(); - //label4.BackColor = Color.White; - //label5.BackColor = Color.Red; - //Cv2.Resize(mat_outputSRG, mat_outputChanged, mat_roisize.Size()); - //mat_outputChanged.SaveImage(basepath + "\\output_resized" + imageFile); - //mat_mask = new Mat(mat_input.Size(), MatType.CV_8UC1, 1); - //for (int i = P1.Y; i < P2.Y; i++) - //{ - // for (int j = P1.X; j < P2.X; j++) - // { - // int pix = mat_outputChanged.At(mmp, pmm); - // mat_mask.Set(i, j, pix); - // pmm++; - // } - // mmp++; - // pmm = 0; - //} - //mmp = 0; - //Cv2.Resize(mat_mask, mat_mask, mat_input.Size()); - //mat_mask.SaveImage(basepath + "\\mask" + imageFile); - //try - //{ - // RemoveSmallRegion(basepath + "\\mask" + imageFile, basepath + "\\mask_changed1" + imageFile, 500, 1, 1); - // RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 500, 0, 0); - //} - //catch - //{ - // MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - // break; - //} - RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\mask_changed1" + imageFile, 2000, 1, 1); - RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 2000, 0, 0); + for (int p = 0; p < 256; p++) + { + for (int q = 0; q < 256; q++) + { + float check = resultfloat[0, p, q, 0]; + if (check < 0) + { + mask[ii] = 0; + } + else + { + mask[ii] = 255; + } + ii++; + } + } + } + } + Thread.Sleep(1000); + bitmap_bitch = ToGrayBitmap(mask, 256, 256); + mat_output = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_output); + pictureBox_output.Image = bitmap_bitch; + pictureBox_output.Refresh(); + label3.BackColor = Color.White; + label4.BackColor = Color.Red; + mat_output.SaveImage(basepath + "\\output256" + imageFile); + try + { + RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\output_changed1" + imageFile, 500, 1, 1); + RemoveSmallRegion(basepath + "\\output_changed1" + imageFile, basepath + "\\output_changed2" + imageFile, 500, 0, 0); + } + catch + { + MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + break; + } + mat_outputSRG = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.Grayscale); + bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRG); + pictureBox_outputSRG.Image = bitmap_bitch; + pictureBox_outputSRG.Refresh(); + label4.BackColor = Color.White; + label5.BackColor = Color.Red; + Cv2.Resize(mat_outputSRG, mat_outputChanged, mat_roisize.Size()); + mat_outputChanged.SaveImage(basepath + "\\output_resized" + imageFile); + mat_mask = new Mat(mat_input.Size(), MatType.CV_8UC1, 1); + for (int i = P1.Y; i < P2.Y; i++) + { + for (int j = P1.X; j < P2.X; j++) + { + int pix = mat_outputChanged.At(mmp, pmm); + mat_mask.Set(i, j, pix); + pmm++; + } + mmp++; + pmm = 0; + } + mmp = 0; + Cv2.Resize(mat_mask, mat_mask, mat_input.Size()); + mat_mask.SaveImage(basepath + "\\mask" + imageFile); + try + { + RemoveSmallRegion(basepath + "\\mask" + imageFile, basepath + "\\mask_changed1" + imageFile, 500, 1, 1); + RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 500, 0, 0); + } + catch + { + MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + break; + } mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.Grayscale); Cv2.Threshold(mat_maskSRG, mat_maskSRG, 128, 255, ThresholdTypes.Binary); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_maskSRG);