private void xAxisTB_ChangeIndex(object sender, EventArgs e)
        {
            if (xAxisTB.Focused == false)
            {
                return;
            }
            //find selected image
            TifFileInfo fi = null;

            try
            {
                fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
            }
            catch { return; }
            if (fi == null)
            {
                return;
            }

            if (fi.xAxisTB == xAxisTB.SelectedIndex)
            {
                return;
            }
            //Parse value
            fi.delHist         = true;
            IA.delHist         = true;
            IA.UnDoBtn.Enabled = true;
            IA.DeleteFromHistory();
            AddXAxisTBToHistory(fi);

            fi.xAxisTB = xAxisTB.SelectedIndex;

            AddXAxisTBToHistory(fi);
            //ReloadImage
            IA.UpdateUndoBtns();
            IA.MarkAsNotSaved();
            IA.ReloadImages();
        }
示例#2
0
        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
        }
示例#3
0
        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();
            }
        }
示例#4
0
        private void createDialog()
        {
            Dialog.FormBorderStyle = FormBorderStyle.FixedDialog;
            Dialog.Text            = "Watershed";
            Dialog.StartPosition   = FormStartPosition.CenterScreen;
            Dialog.WindowState     = FormWindowState.Normal;
            Dialog.MinimizeBox     = false;
            Dialog.MaximizeBox     = false;
            Dialog.BackColor       = IA.FileBrowser.BackGround2Color1;
            Dialog.ForeColor       = IA.FileBrowser.ShriftColor1;

            Dialog.FormClosing += new FormClosingEventHandler(delegate(object o, FormClosingEventArgs a)
            {
                Dialog.Visible = false;
                a.Cancel       = true;
            });

            Dialog.Width  = 240;
            Dialog.Height = 190;

            Dialog.SuspendLayout();

            /*
             * Label ThresholdLab = new Label();
             * ThresholdLab.Text = "Select threshold:";
             * ThresholdLab.Width = 100;
             * ThresholdLab.Location = new System.Drawing.Point(10,15);
             * Dialog.Controls.Add(ThresholdLab);
             *
             * ThresholdCB.Width = 30;
             * ThresholdCB.Location = new System.Drawing.Point(110, 13);
             * Dialog.Controls.Add(ThresholdCB);
             * ThresholdCB.SelectedIndexChanged += new EventHandler(delegate (object o, EventArgs a)
             * {
             *  threshold = ThresholdCB.SelectedIndex + 1;
             * });
             */

            Label ToleranceLab = new Label();

            ToleranceLab.Text     = "Tolerance:";
            ToleranceLab.Width    = 100;
            ToleranceLab.Location = new System.Drawing.Point(10, 15);
            Dialog.Controls.Add(ToleranceLab);

            ToleranceTB.Text     = tolerance.ToString();
            ToleranceTB.Width    = 30;
            ToleranceTB.Location = new System.Drawing.Point(110, 13);
            Dialog.Controls.Add(ToleranceTB);

            Label DistanceLab = new Label();

            DistanceLab.Text     = "Distance Transform:";
            DistanceLab.Width    = 100;
            DistanceLab.Location = new System.Drawing.Point(10, 45);
            Dialog.Controls.Add(DistanceLab);

            ComboBox DistanceCB = new ComboBox();

            DistanceCB.Width = 110;
            DistanceCB.Items.AddRange(new string[] { "Euclidean", "SquaredEuclidean", "Chessboard", "Manhattan" });
            DistanceCB.SelectedIndex         = 0;
            DistanceCB.SelectedIndexChanged += new EventHandler(delegate(object o, EventArgs a)
            {
                switch (DistanceCB.SelectedIndex)
                {
                case 0:
                    distance = DistanceTransformMethod.Euclidean;
                    break;

                case 1:
                    distance = DistanceTransformMethod.SquaredEuclidean;
                    break;

                case 2:
                    distance = DistanceTransformMethod.Chessboard;
                    break;

                case 3:
                    distance = DistanceTransformMethod.Manhattan;
                    break;

                default:
                    distance = DistanceTransformMethod.Euclidean;
                    break;
                }
            });
            DistanceCB.Location = new System.Drawing.Point(110, 43);
            Dialog.Controls.Add(DistanceCB);

            FillHolesCB.Text     = "Fill holes";
            FillHolesCB.Location = new System.Drawing.Point(15, 75);
            Dialog.Controls.Add(FillHolesCB);

            //buttons
            Panel okBox = new Panel();

            okBox.Height = 40;
            okBox.Dock   = DockStyle.Bottom;
            Dialog.Controls.Add(okBox);

            Button okBtn = new Button();

            okBtn.Text      = "Process";
            okBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
            okBtn.ForeColor = System.Drawing.Color.Black;
            okBtn.Location  = new System.Drawing.Point(20, 10);
            okBtn.Anchor    = AnchorStyles.Top | AnchorStyles.Left;
            okBox.Controls.Add(okBtn);

            Button cancelBtn = new Button();

            cancelBtn.Text      = "Cancel";
            cancelBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
            cancelBtn.Location  = new System.Drawing.Point(Dialog.Width - cancelBtn.Width - 60, 10);
            cancelBtn.ForeColor = System.Drawing.Color.Black;
            cancelBtn.Anchor    = AnchorStyles.Top | AnchorStyles.Right;
            okBox.Controls.Add(cancelBtn);

            okBtn.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                try
                {
                    tolerance = float.Parse(ToleranceTB.Text);
                }
                catch
                {
                    MessageBox.Show("Tolerance must be numeric!");
                    return;
                }
                Dialog.Visible = false;
                //event
                TifFileInfo fi = null;
                try
                {
                    fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
                }
                catch { return; }

                if (fi == null)
                {
                    return;
                }
                if (!fi.available)
                {
                    MessageBox.Show("Image is not ready yet! \nTry again later.");
                    return;
                }
                int C = fi.cValue;
                //background worker
                var bgw = new BackgroundWorker();
                bgw.WorkerReportsProgress = true;
                fi.available = false;
                fi.fillHoles = FillHolesCB.Checked;
                //Add event for projection here
                bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
                {
                    ProcessFilter(fi, C, this.tolerance, 1, this.distance);
                    ((BackgroundWorker)o).ReportProgress(0);
                });

                bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
                {
                    if (a.ProgressPercentage == 0)
                    {
                        IA.Segmentation.MyFilters.addToHistoryOldInfo(C, fi);

                        fi.newFilterHistory[C].Add(
                            ToString(fi, C, this.tolerance, 1, this.distance));

                        IA.Segmentation.MyFilters.addToHistoryNewInfo(C, fi);

                        IA.MarkAsNotSaved();
                        IA.ReloadImages();
                    }
                    fi.available = true;
                    IA.FileBrowser.StatusLabel.Text = "Ready";
                });
                //Start background worker
                IA.FileBrowser.StatusLabel.Text = "Watershed...";
                //start bgw
                bgw.RunWorkerAsync();
            });

            cancelBtn.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                Dialog.Visible = false;
            });

            Dialog.KeyPreview = true;
            Dialog.KeyDown   += new KeyEventHandler(delegate(object sender, KeyEventArgs e)
            {
                switch (e.KeyCode)
                {
                case Keys.Escape:
                    Dialog.Visible = false;
                    break;

                case Keys.Enter:
                    okBtn.PerformClick();
                    break;

                default:
                    break;
                }
            });

            Dialog.ResumeLayout();
        }
示例#5
0
        private void ColBtn_Click(object sender, MouseEventArgs e)
        {
            TifFileInfo fi  = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
            Button      btn = (Button)sender;

            if (e.Button == MouseButtons.Left)
            {
                //disable/enable color
                if (fi.SpotColor[fi.cValue] == Color.Transparent)
                {
                    fi.SpotColor[fi.cValue] = fi.RefSpotColor[fi.cValue];
                }
                else
                {
                    fi.SpotColor[fi.cValue] = Color.Transparent;
                }

                #region apply to history
                //segmentation.SpotDetector(chanelN,ThreshVal,HTML color, tail type, thresh type)
                Color val    = fi.RefSpotColor[fi.cValue];
                Color oldVal = Color.Transparent;

                if (fi.SpotColor[fi.cValue] == Color.Transparent)
                {
                    val = Color.Transparent; oldVal = fi.RefSpotColor[fi.cValue];
                }

                fi.delHist         = true;
                IA.delHist         = true;
                IA.UnDoBtn.Enabled = true;
                IA.DeleteFromHistory();
                fi.History.Add("segmentation.SpotDetector("
                               + fi.cValue.ToString() + "," +
                               fi.SpotThresh[fi.cValue].ToString() + "," +
                               fi.spotSensitivity[fi.cValue].ToString() + "," +
                               ColorTranslator.ToHtml(oldVal) + "," +
                               fi.SpotTailType[fi.cValue] + "," +
                               fi.SelectedSpotThresh[fi.cValue].ToString() + "," +
                               fi.typeSpotThresh[fi.cValue].ToString() + ")");
                fi.History.Add("segmentation.SpotDetector("
                               + fi.cValue.ToString() + "," +
                               fi.SpotThresh[fi.cValue].ToString() + "," +
                               fi.spotSensitivity[fi.cValue].ToString() + "," +
                               ColorTranslator.ToHtml(val) + "," +
                               fi.SpotTailType[fi.cValue] + "," +
                               fi.SelectedSpotThresh[fi.cValue].ToString() + "," +
                               fi.typeSpotThresh[fi.cValue].ToString() + ")");
                IA.UpdateUndoBtns();
                IA.MarkAsNotSaved();
                #endregion apply to history

                IA.ReloadImages();
            }
            else if (e.Button == MouseButtons.Right & btn.Text == "")
            {
                //change color
                ColorDialog colorDialog1 = new ColorDialog();
                colorDialog1.AllowFullOpen = true;
                colorDialog1.AnyColor      = true;
                colorDialog1.FullOpen      = true;
                colorDialog1.Color         = fi.RefSpotColor[fi.cValue];
                //set Custom Colors
                if (IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex] != "@")
                {
                    List <int> colorsList = new List <int>();
                    foreach (string j in IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex]
                             .Split(new[] { "\t" }, StringSplitOptions.None))
                    {
                        colorsList.Add(int.Parse(j));
                    }
                    colorDialog1.CustomColors = colorsList.ToArray();
                }
                // Show the color dialog.
                DialogResult result = colorDialog1.ShowDialog();
                //Copy Custom Colors
                int[]  colors = (int[])colorDialog1.CustomColors.Clone();
                string txt    = "@";
                if (colors.Length > 0)
                {
                    txt = colors[0].ToString();
                    for (int j = 1; j < colors.Length; j++)
                    {
                        txt += "\t" + colors[j].ToString();
                    }
                }
                IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex] = txt;
                IA.settings.Save();

                if (result == DialogResult.OK)
                {
                    #region apply to history
                    //segmentation.SpotDetector(chanelN,ThreshVal,HTML color, tail type, thresh type)
                    fi.delHist         = true;
                    IA.delHist         = true;
                    IA.UnDoBtn.Enabled = true;
                    IA.DeleteFromHistory();
                    fi.History.Add("segmentation.SpotDetector("
                                   + fi.cValue.ToString() + "," +
                                   fi.SpotThresh[fi.cValue].ToString() + "," +
                                   fi.spotSensitivity[fi.cValue].ToString() + "," +
                                   ColorTranslator.ToHtml(fi.RefSpotColor[fi.cValue]) + "," +
                                   fi.SpotTailType[fi.cValue] + "," +
                                   fi.SelectedSpotThresh[fi.cValue].ToString() + "," +
                                   fi.typeSpotThresh[fi.cValue].ToString() + ")");
                    fi.History.Add("segmentation.SpotDetector("
                                   + fi.cValue.ToString() + "," +
                                   fi.SpotThresh[fi.cValue].ToString() + "," +
                                   fi.spotSensitivity[fi.cValue].ToString() + "," +
                                   ColorTranslator.ToHtml(colorDialog1.Color) + "," +
                                   fi.SpotTailType[fi.cValue] + "," +
                                   fi.SelectedSpotThresh[fi.cValue].ToString() + "," +
                                   fi.typeSpotThresh[fi.cValue].ToString() + ")");
                    IA.UpdateUndoBtns();
                    IA.MarkAsNotSaved();
                    #endregion apply to history

                    fi.RefSpotColor[fi.cValue] = colorDialog1.Color;
                    fi.SpotColor[fi.cValue]    = colorDialog1.Color;
                    IA.ReloadImages();
                }
            }
        }