private void backWorkLoadData_DoWork(object sender, DoWorkEventArgs e) //private void btn_load_Click(object sender, EventArgs e) { ExperimentsNames wsiIndexItem = new ExperimentsNames(); this.Invoke(new MethodInvoker(delegate() { wsiIndexItem = (ExperimentsNames)cmbBox_experiments.SelectedItem; })); int wsiIndex = wsiIndexItem.Order; richTextBox1.Invoke((MethodInvoker) delegate { richTextBox1.Text = $"Načitávam facts"; }); factorsOfMisclassification = LoadDatabase.Load_Factors(ExplanationDatabase.factOfMisclass_dir_path[wsiIndex], richTextBox1); string cancer_path = ExplanationDatabase.wsi_paths[wsiIndex]; string label_path = ExplanationDatabase.wsi_labels_paths[wsiIndex]; var cancer_img = new Bitmap(cancer_path); this.cancerBm = cancer_img; richTextBox1.Invoke((MethodInvoker) delegate { richTextBox1.Text = $"Načitávam label"; }); var label_img = new Bitmap(label_path); this.labelBm = label_img; this.memberships = LoadDatabase.LoadMemberships(wsiIndex); this.data_memberships = LoadDatabase.LoadDataMembership(); this.data_paths = LoadDatabase.LoadDataPaths(); trackBar1.Invoke((MethodInvoker) delegate { trackBar1.Visible = true; }); pcBx_cancer.Image = cancer_img; pcBx_label.Image = label_img; this.history = new ExperimentHistory(); this.wsi_name = wsiIndexItem.Name; folderPathToSaveResult = ExplanationDatabase.WSI_DATA_PATH + wsi_name + "\\results"; Directory.CreateDirectory(folderPathToSaveResult); // load sugggested point to examine this.suggestedPoints = Utilities.LoadSuggestedPoints(this.wsi_name); this.suggestedPoints.Shuffle(); }
private void pcBx_cancer_Click(object sender, EventArgs e) { if (pcBx_cancer.Image != null && pcBx_label.Image != null) { MouseEventArgs me = (MouseEventArgs)e; Point coordinates = me.Location; if (me.Button == System.Windows.Forms.MouseButtons.Left) { var coord = Utilities.GetAbsolutCoordinates(coordinates, ORIGINAL_SIZE, pcBx_cancer); this.actualCoord = coord; int x = coord[0]; int y = coord[1]; var pxColor = labelBm.GetPixel(x, y); int predictedLabel = ExplanationDatabase.GetLabel(pxColor); var facts = LoadDatabase.GetFactors(factorsOfMisclassification, predictedLabel, x, y); richTextBox1.Text = Utilities.ExtractSemantic(predictedLabel, facts); Utilities.HighlightWords(ExplanationDatabase.classes.Values.ToArray(), richTextBox1); // show image on wchich decision was made float[] membValue = LoadDatabase.GetMembershipVector(memberships, x, y); string decisionImagePath = LoadDatabase.GetTheMostSimilarImagePath( predictedLabel, predictedLabel, membValue[predictedLabel - 1], data_memberships, data_paths); pcBx_decisionImg.Image = new Bitmap(decisionImagePath); pcBx_decisionImg.Refresh(); //label_pcBx_decisionImg.Text = $"Tkanivo {ExplanationDatabase.classes[predictedLabel]}"; label_pcBx_decisionImg.Text = $"Tissue {ExplanationDatabase.classes[predictedLabel]}"; // show high similar image if there are any var pcBoxList = MergePcBxAndClear(); var labelList = MergeLabelsAndClear(); var highProbLabels = Utilities.GetElementsByValue(facts, "3"); var lowProbLabels = Utilities.GetElementsByValue(facts, "2"); foreach (var prob in highProbLabels) { string imgPath = LoadDatabase.GetTheMostSimilarImagePath( predictedLabel, prob, membValue[prob - 1], data_memberships, data_paths); if (pcBoxList.Count > 0) { pcBoxList[0].Image = new Bitmap(imgPath); Graphics graphics = Graphics.FromImage((Image)pcBoxList[0].Image); Pen pen = new Pen(Color.Red, 8); Rectangle rect = new Rectangle(0, 0, 150, 150); graphics.DrawRectangle(pen, rect); pcBoxList[0].Refresh(); labelList[0].Text = $"Tissue {ExplanationDatabase.classes[prob]}"; //labelList[0].Text = $"Tkanivo {ExplanationDatabase.classes[prob]}"; pcBoxList.RemoveAt(0); labelList.RemoveAt(0); } } foreach (var prob in lowProbLabels) { string imgPath = LoadDatabase.GetTheMostSimilarImagePath( predictedLabel, prob, membValue[prob - 1], data_memberships, data_paths); if (pcBoxList.Count > 0) { pcBoxList[0].Image = new Bitmap(imgPath); Graphics graphics = Graphics.FromImage((Image)pcBoxList[0].Image); Pen pen = new Pen(Color.Yellow, 8); Rectangle rect = new Rectangle(0, 0, 150, 150); graphics.DrawRectangle(pen, rect); pcBoxList[0].Refresh(); labelList[0].Text = $"Tissue {ExplanationDatabase.classes[prob]}"; //labelList[0].Text = $"Tkanivo {ExplanationDatabase.classes[prob]}"; pcBoxList.RemoveAt(0); labelList.RemoveAt(0); } } this.actualPredicted = predictedLabel; groupBox_accuracy.Enabled = true; this.pointer = this.SetNormalizePoint(coordinates); this.newPointer = this.SetNormalizePoint(coordinates); pcBx_label.Refresh(); pcBx_cancer.Refresh(); } } }