private void TextBox3_TextChanged(object sender, EventArgs e) { TextBox3 = (TextBox)sender; string theText3 = TextBox3.Text; ImageSegmentation ImageSeg = new ImageSegmentation(); // ImageSeg.Compute(InpFile, OutFile); }
private void kśrednichToolStripMenuItem_Click(object sender, EventArgs e) { ImageSeg = new ImageSegmentation(); Bitmap image = ImageSeg.Compute((Bitmap)this.pctbImage.Image); ImageSeg = null; SetImageAndHist(image); }
////~~~~~~~~~~~~~~~~~~~~~~~~~ Some crucial methods /// private void analyze() { //Do different image segmentations, depending on the choices if (comboBox1.SelectedIndex > -1) { String select = comboBox1.Text; if (select == "K Clustering") { //do the K clustering method segmentation = "K Cluster"; //System.Windows.Forms.MessageBox.Show("No image imported"); } else if (select == "Edge Detection") { //have this done in edge detection segmentation = "Edge Detection"; } else { System.Windows.Forms.MessageBox.Show("No Segmentation Type Selected."); return; } } //first, the base case: we analyze when the user didn't put in a picture if (pic == null) { System.Windows.Forms.MessageBox.Show("No image imported"); return; } else { if (segmentation == "K Cluster") { //before doing the segmentation, check if "temp.jpg" exists and "Segmented Image" exists //using the method from KMC.cs if (searched == 0) { Bitmap temp = (Bitmap)pic; //set the name of the files created from the segmentation temp.Save("t3mp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //temp.Dispose(); searched = 1; } //string directoryName = Path.GetDirectoryName("temp.jpg"); //string sourcePath = Directory.GetCurrentDirectory(); string path = Directory.GetCurrentDirectory(); //Now the color segmented images are in a folder called "Segmented Image" string directory = path + "\\S3gmented Image"; //if there has not been K-clustering, skip the process and go to the API if (!(System.IO.Directory.Exists(directory))) { //Trying Amanda's method ImageSegmentation.Compute("t3mp.jpg"); } files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories); int numFiles = files.GetLength(0); //if the user enters another term after the images were already sent to API, we don't need to send to API again if (API_sent == 0) { ImageCollections = new string[numFiles]; int tempCounter = 0; //array that collects the accurate terms list API_results = new List <string> [numFiles]; //Now we go inside the Segmented Image folder and loop foreach (string file in files) { ImageCollections[tempCounter] = file; Google.Cloud.Vision.V1.Image integer = Google.Cloud.Vision.V1.Image.FromFile(ImageCollections[tempCounter]); //Keeps track of the terms used API_results[tempCounter] = Vision.containsElement(integer); tempCounter++; } //so we don't have to loop over again. We already have the information API_sent = 1; } //our algorithm is first loop over each picture and if the user_query match, save the matching image and the rank in the array // then continue over and if the user_query match on the next file and if the rank in the array is lower (more front), switch the saved image int rank = 999; for (int i = 1; i < numFiles; i++) { int count = API_results[i].Count; for (int k = 0; k < count; k++) { if (String.Equals(user_query, API_results[i][k])) { //found a better and more accurate image. higher ranked if (rank > k) { //want to free up our files, so we can delete later if (resultBitmap != null) { resultBitmap.Dispose(); } resultBitmap = new Bitmap(ImageCollections[i]); rank = k; } } } } // no API term found if (rank == 999) { System.Windows.Forms.MessageBox.Show("No search term of \"" + user_query + "\" found"); } /* * List<String> output = API_results[1]; * String printing = output[1]; * * System.Windows.Forms.MessageBox.Show(printing.ToString()); */ //string name = ImageCollections[1]; //testNum = Vision.containsElement(ImageCollections[1], theText1); //for the test purpose, get the second image that has been cropped //resultBitmap = new Bitmap(ImageCollections[2]); //Google.Cloud.Vision.V1.Image i = Google.Cloud.Vision.V1.Image.FromFile(ImageCollections[2]); //testNum = Vision.containsElement(i, theText1); //System.Windows.Forms.MessageBox.Show(testNum.ToString()); //pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; if (resultBitmap != null) { pictureBox1.Image = resultBitmap; } } //System.Windows.Forms.MessageBox.Show(segmentation); if (segmentation == "Edge Detection") { if (resultBitmap != null) { resultBitmap.Dispose(); } //System.Windows.Forms.MessageBox.Show("Here"); resultBitmap = Filter.ApplyFilter((Bitmap)pic, EdgeFilter); //Image finaloutput = (Image)resultBitmap; //pictureBox2.SizeMode = PictureBoxSizeMode.Zoom; //resultBitmap.UnlockBits pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox1.Image = resultBitmap; } } }
public void TestMethod1() { Stopwatch stopwatch = new Stopwatch(); ImageSegmentation segmentation = new ImageSegmentation(); ////foreach ((Image image, int? frameIndex, _) in Imaging.Image.FromFile(@"D:\source.bmp")) ////foreach ((Image image, _, _) in Imaging.Image.FromFile(@"C:\Users\Alexander\Desktop\hcfa.png")) ////foreach ((Image image, _, _) in Imaging.Image.FromFile(@"C:\Users\Alexander\Desktop\07227200002.tif")) foreach ((Image image, int?frameIndex, _) in Imaging.Image.FromFile(@"L:\FormXtra\HCFA\BW\SET1\07227200002.tif")) ////foreach ((Image image, int? frameIndex, _) in Imaging.Image.FromFile(@"C:\Users\avolgunin\Desktop\hcfa.png")) ////foreach ((Image image, _, _) in Image.FromFile(@"C:\DNN\dnn\test4.jpg")) { Image xxx = image.ConvertTo(null, 1).CleanOverscan(0.5f, 0.5f).Deskew(null).Despeckle(null); Image yyy = xxx.CreateTemplate(null, xxx.BitsPerPixel); ////LineDetector.FindLines(xxx, new LineDetectionOptions()); /*Pix pix = Pix.FromImage(xxx);*/ ////int[] a = new int[10000]; ////for (int kw = 49; kw <= 49; kw++) { ////xxx.Dilate(yyy, StructuringElement.Brick(1, kw), 1, BorderType.BorderConst, 0); ////pix.DilateGray(1, kw); ////Pix pix = Pix.FromImage(image); stopwatch.Restart(); for (int i = 0; i < 1; i++) { segmentation.Segment(xxx, null, CancellationToken.None); ////xxx.Binarize(yyy, 0, 0, 0, 0, true, 0, 0); ////Statistic.Smooth(a.Length, a, 0); ////pix.DilateGray(1, kw); ////xxx.Convert8To1(yyy, 128); ////xxx.Dilate(yyy, StructuringElement.Brick(1, kw), 1, BorderType.BorderConst, 0); ////xxx.Dilate3x3(yyy, BorderType.BorderConst, 0); ////xxx.Dilate(yyy, StructuringElement.Brick(3, 3), 1, BorderType.BorderConst, 0); } #if false stopwatch.Restart(); for (int i = 0; i < 10; i++) { workImage.FindConnectedComponents(8); } ////workImage.DistanceToBackground(4, 8); stopwatch.Stop(); Console.WriteLine("{0:F4} ms", stopwatch.ElapsedMilliseconds /* / Count*/); using (Pix pixComp = Pix.FromImage(workImage)) { stopwatch.Restart(); using (Pix pixDist = pixComp.DistanceFunction(4, 8, 1)) { } stopwatch.Stop(); Console.WriteLine("{0:F4} ms", stopwatch.ElapsedMilliseconds /* / Count*/); } #endif /*workImage = workImage.CleanOverscan(0.5f, 0.5f).Deskew(null).Despeckle(null); * workImage.SetResolution(300, 300); * ISet<LineShape> components = LineDetector.FindLines(workImage, new LineDetectionOptions());*/ stopwatch.Stop(); ////Console.WriteLine("{0}: {1:F4} ms", kw, stopwatch.ElapsedMilliseconds/* / Count*/); Console.WriteLine("{0:F4} ms", stopwatch.ElapsedMilliseconds /* / Count*/); } Console.WriteLine(segmentation.PrintPerformanceReport(1)); } }
private async Task applyImageSegmentation() { ImageSegmentation imageSegmentation = new ImageSegmentation(this.ModifiedPicture); await imageSegmentation.ApplyImageSegmentation(6, 10); }