public OtsuSegmentation(Panel mainPanel, ImageAnalyser IA) { this.IA = IA; //Core panel panel.Dock = DockStyle.Top; panel.BackColor = IA.FileBrowser.BackGround2Color1; panel.ForeColor = IA.FileBrowser.ShriftColor1; panel.Visible = false; panel.Height = 150; mainPanel.Controls.Add(panel); panel.BringToFront(); #region Options GroupBox optionGB = new GroupBox(); optionGB.Text = "Options:"; optionGB.BackColor = IA.FileBrowser.BackGround2Color1; optionGB.ForeColor = IA.FileBrowser.ShriftColor1; optionGB.Dock = DockStyle.Top; optionGB.Height = 85; panel.Controls.Add(optionGB); optionGB.BringToFront(); Label Name = new Label(); Name.Text = "Thresholds:"; Name.Width = TextRenderer.MeasureText(Name.Text, Name.Font).Width; Name.Location = new Point(5, 18); optionGB.Controls.Add(Name); Name.BringToFront(); ComboBox cb = thresholdsNumCB; cb.Text = "0"; cb.Items.AddRange(new string[] { "0", "1", "2", "3", "4" }); cb.Width = 40; cb.Location = new Point(80, 15); optionGB.Controls.Add(cb); cb.BringToFront(); cb.DropDownStyle = ComboBoxStyle.DropDownList; cb.SelectedIndex = 0; cb.AutoSize = false; cb.SelectedIndexChanged += new EventHandler(delegate(object o, EventArgs e) { TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI; fi.thresholdsCBoxIndex[fi.cValue] = cb.SelectedIndex; IA.ReloadImages(); }); CheckBox checkB = sumHistogramsCheckBox; checkB.Text = "Use SUM histogram"; checkB.Tag = "Use SUM histogram:\nCalculates histograms for all images\nand merge them into one"; checkB.Width = 150; checkB.Checked = true; checkB.MouseHover += Control_MouseOver; checkB.Location = new Point(7, 35); optionGB.Controls.Add(checkB); checkB.BringToFront(); checkB.CheckedChanged += new EventHandler(delegate(object o, EventArgs e) { TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI; fi.sumHistogramChecked[fi.cValue] = checkB.Checked; if (((CheckBox)o).Focused == true) { IA.ReloadImages(); } }); { Button btn = ProcessBtn; btn.Width = 115; btn.FlatStyle = FlatStyle.Standard; btn.BackColor = SystemColors.ButtonFace; btn.ForeColor = Color.Black; btn.Text = "Process"; btn.Location = new Point(5, 58); optionGB.Controls.Add(btn); btn.BringToFront(); btn.Click += new EventHandler(delegate(object o, EventArgs a) { int MLEVEL = thresholdsNumCB.SelectedIndex + 1; if (IA.Segmentation.SegmentationCBox.SelectedIndex == 2) { IA.Segmentation.Kmeans.Start(MLEVEL); return; } if (IA.Segmentation.SegmentationCBox.SelectedIndex != 1) { return; } TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI; if (fi.available == false) { MessageBox.Show("Image is not ready yet! \nTry again later."); } else { //background worker var bgw = new BackgroundWorker(); bgw.WorkerReportsProgress = true; bgw.DoWork += new DoWorkEventHandler(delegate(Object o1, DoWorkEventArgs a1) { try { //Segmentation event run(fi, MLEVEL); } catch { } //report progress ((BackgroundWorker)o1).ReportProgress(0); }); bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o1, ProgressChangedEventArgs a1) { fi.available = true; IA.FileBrowser.StatusLabel.Text = "Ready"; IA.MarkAsNotSaved(); IA.ReloadImages(); }); //Apply status IA.FileBrowser.StatusLabel.Text = "Segmentation..."; fi.available = false; //start bgw bgw.RunWorkerAsync(); } }); } #endregion Options #region Thresholds GroupBox threshGB = new GroupBox(); threshGB.Text = "Thresholds:"; threshGB.BackColor = IA.FileBrowser.BackGround2Color1; threshGB.ForeColor = IA.FileBrowser.ShriftColor1; threshGB.Dock = DockStyle.Fill; threshGB.Height = 50; panel.Controls.Add(threshGB); threshGB.BringToFront(); //Color btns Panel colorPanel = new Panel(); colorPanel.Dock = DockStyle.Left; colorPanel.Width = 25; threshGB.Controls.Add(colorPanel); Panel UpPanel = new Panel(); UpPanel.Dock = DockStyle.Top; UpPanel.Height = 15; threshGB.Controls.Add(UpPanel); UpPanel.BringToFront(); for (int i = 0; i < colorBtns.Length; i++) { Button btn = new Button(); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.ForeColor = Color.Black; btn.Text = ""; btn.Tag = i; btn.Dock = DockStyle.Top; btn.Height = 25; colorPanel.Controls.Add(btn); colorBtns[i] = btn; btn.BringToFront(); btn.Visible = false; btn.MouseDown += new MouseEventHandler(ColorBtn_Click); btn.MouseHover += new EventHandler(delegate(object o, EventArgs a) { if (btn.Text == "") { TurnOnToolTip.SetToolTip(btn, "Color " + ((int)btn.Tag).ToString() + ":\nLeft click to Disable\nRight click to change color"); } else { TurnOnToolTip.SetToolTip(btn, "Color " + ((int)btn.Tag).ToString() + " - Disabled\nLeft click to Enable"); } }); } //threshold track bars for (int i = 0; i < threshTrackBars.Length; i++) { CTTrackBar tb = new CTTrackBar(); tb.Initialize(); tb.Panel.Dock = DockStyle.Top; tb.BackColor(IA.FileBrowser.BackGround2Color1); tb.ForeColor(IA.FileBrowser.ShriftColor1); tb.Panel.Visible = false; tb.Refresh(0, 0, 10); tb.Name.Text = "T" + (i + 1).ToString(); tb.NamePanel.Width = 30; threshGB.Controls.Add(tb.Panel); threshTrackBars[i] = tb; tb.Panel.BringToFront(); tb.Value.Changed += new ChangedValueEventHandler(delegate(Object o, ChangeValueEventArgs a) { TrackBar_ValueChange(a, tb); }); } #endregion Thresholds }
public SpotDetector(Panel mainPanel, ImageAnalyser IA) { this.IA = IA; Panel p1 = new Panel(); p1.Height = 5; p1.Dock = DockStyle.Top; mainPanel.Controls.Add(p1); p1.BringToFront(); #region Threshold { CTTrackBar tb = new CTTrackBar(); tb.Initialize(); tb.Panel.Dock = DockStyle.Top; tb.BackColor(IA.FileBrowser.BackGround2Color1); tb.ForeColor(IA.FileBrowser.ShriftColor1); tb.Panel.Visible = true; tb.Refresh(0, 0, 10); tb.Name.Text = "Threshold:"; tb.NamePanel.Width = 62; mainPanel.Controls.Add(tb.Panel); thresh = tb; tb.Panel.BringToFront(); tb.Value.Changed += new ChangedValueEventHandler(delegate(Object o, ChangeValueEventArgs a) { thresh_valueChange(int.Parse(a.Value)); }); } #endregion Threshold #region Options { CTTrackBar tb = new CTTrackBar(); tb.Initialize(); tb.Panel.Dock = DockStyle.Top; tb.BackColor(IA.FileBrowser.BackGround2Color1); tb.ForeColor(IA.FileBrowser.ShriftColor1); tb.Panel.Visible = true; tb.Refresh(100, 1, 100); tb.Name.Text = "Sensitivity:"; tb.NamePanel.Width = 62; mainPanel.Controls.Add(tb.Panel); sensitivity = tb; tb.Panel.BringToFront(); tb.Value.Changed += new ChangedValueEventHandler(delegate(Object o, ChangeValueEventArgs a) { sensitivity_valueChange(int.Parse(a.Value)); }); } Panel p = new Panel(); p.Height = 30; p.Dock = DockStyle.Top; mainPanel.Controls.Add(p); p.BringToFront(); //Thresh list box selectT.Tag = "Select Threshold"; selectT.Width = 60; selectT.Location = new Point(53, 1); selectT.Items.Add("None"); selectT.DropDownStyle = ComboBoxStyle.DropDownList; selectT.SelectedIndex = 0; selectT.AutoSize = false; p.Controls.Add(selectT); selectT.BringToFront(); selectT.MouseHover += Control_MouseOver; selectT.SelectedIndexChanged += selectT_IndexChange; //ThreshType box tType.Tag = "Set threshold type"; tType.Width = 60; tType.Location = new Point(120, 1); tType.Items.AddRange(new string[] { "Pixels", "% Max" }); tType.DropDownStyle = ComboBoxStyle.DropDownList; tType.SelectedIndex = 0; tType.AutoSize = false; p.Controls.Add(tType); tType.BringToFront(); tType.MouseHover += Control_MouseOver; tType.SelectedIndexChanged += TType_IndexChange; //Color btn { Button btn = new Button(); ColBtn = btn; btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.BackColor = Color.Red; btn.ForeColor = Color.Black; btn.Location = new Point(3, 1); btn.Text = ""; btn.Tag = "Select color for the spots"; btn.Height = 22; btn.Width = 25; p.Controls.Add(btn); btn.BringToFront(); btn.Visible = true; btn.MouseHover += Control_MouseOver; btn.MouseDown += ColBtn_Click; } //<>btn { Button btn = new Button(); TailType = btn; btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.ForeColor = Color.White; btn.Location = new Point(28, 1); btn.Text = ">"; btn.Tag = "Set spot intensity diapason"; btn.Height = 22; btn.Width = 25; p.Controls.Add(btn); btn.BringToFront(); btn.Visible = true; btn.MouseHover += Control_MouseOver; btn.Click += TailType_Click; } #endregion Options }
private void TrackBar_ValueChange(ChangeValueEventArgs e, CTTrackBar tb) { //variables TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI; int[] vals = fi.thresholdValues[fi.cValue]; int val = int.Parse(e.Value); int valRef = val; //find trackbar index int index = 0; for (int i = 0; i < threshTrackBars.Length; i++) { if (threshTrackBars[i] == tb) { index = i; break; } } //Check the avaliable min if (index > 0) { if (val <= vals[index]) { val = vals[index] + 1; } } //Check the avaliable max if (index < fi.thresholds[fi.cValue] - 1) { if (val >= vals[index + 2]) { val = vals[index + 2] - 1; } } //refresh if value is wrong if (val != valRef) { tb.Refresh(val, tb.TrackBar1.Minimum, tb.TrackBar1.Maximum); } //apply changes if (val != vals[index + 1]) { if (tb.TrackBar1.Focused == true | tb.TextBox1.Focused == true | tb.ApplyBtn.Focused == true) { #region apply to history fi.delHist = true; IA.delHist = true; IA.UnDoBtn.Enabled = true; IA.DeleteFromHistory(); fi.History.Add("segmentation.SetThreshOld(" + fi.cValue + "," + (index + 1).ToString() + "," + vals[index + 1].ToString() + ")"); fi.History.Add("segmentation.SetThreshOld(" + fi.cValue + "," + (index + 1).ToString() + "," + val.ToString() + ")"); IA.UpdateUndoBtns(); IA.MarkAsNotSaved(); #endregion apply to history } vals[index + 1] = val; IA.ReloadImages(); } }
public void ReloadImage(TifFileInfo fi) { #region selectT load selectT.Items.Clear(); selectT.Items.Add("None"); selectT.Items.Add("Min"); if (IA.Segmentation.SegmentationCBox.SelectedIndex == 1) { for (int i = 0; i < fi.thresholds[fi.cValue]; i++) { selectT.Items.Add("T" + (i + 1).ToString()); } } selectT.Items.Add("Max"); if (fi.SelectedSpotThresh[fi.cValue] < selectT.Items.Count) { selectT.SelectedIndex = fi.SelectedSpotThresh[fi.cValue]; } else { selectT.SelectedIndex = 0; } #endregion region selectT load #region type thresh tType.SelectedIndex = fi.typeSpotThresh[fi.cValue]; switch (tType.SelectedIndex) { case 0: thresh.Refresh(fi.SpotThresh[fi.cValue], 0, Convert.ToInt32(fi.sizeX * fi.sizeY * 0.1)); break; case 1: if (fi.SpotThresh[fi.cValue] <= 100) { thresh.Refresh(fi.SpotThresh[fi.cValue], 0, 100); } else { fi.SpotThresh[fi.cValue] = 0; thresh.Refresh(0, 0, 100); } break; } #endregion type thresh Color col = fi.SpotColor[fi.cValue]; if (col != Color.Transparent) { ColBtn.BackColor = col; ColBtn.Text = ""; } else { ColBtn.BackColor = Color.White; ColBtn.Text = "NaN"; } TailType.Text = fi.SpotTailType[fi.cValue]; sensitivity.Refresh(fi.spotSensitivity[fi.cValue], 1, 100); }