private void Chart1_MouseUp(object sender, MouseEventArgs e)
        {
            TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;

            moveMax = false;
            moveMin = false;

            applyToHistory(fi.cValue,
                           fi.MinBrightness[fi.cValue],
                           fi.MaxBrightness[fi.cValue]);

            Chart1.Cursor = Cursors.Default;
            //Chart1.Capture = false;
            //System.Windows.Forms.Cursor.Clip = new Rectangle(0, 0, 0, 0);
            calculateHistogramArray(fi, true);
            if (applyToAll.Checked == true & autoDetect.Checked == false)
            {
                int curC = fi.cValue;
                for (int c = 0; c < fi.sizeC; c++)
                {
                    fi.cValue = c;
                    IA.BandC.calculateHistogramArray(fi, true);
                }
                fi.cValue = curC;
                calculateHistogramArray(fi, true);
            }

            IA.ReloadImages();
        }
        private void optionForm_Hide()
        {
            if (functions.Length > 0)
            {
                Properties.Settings.Default.CTChart_Functions[IA.TabPages.ActiveAccountIndex] = "@\n" +
                                                                                                string.Join("\n", functions);
            }
            else
            {
                Properties.Settings.Default.CTChart_Functions[IA.TabPages.ActiveAccountIndex] = "@";
            }

            Properties.Settings.Default.Save();

            OptionForm.Hide();
            LoadFunctions();
            IA.ReloadImages();
        }
Example #3
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
        }
Example #4
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();
            }
        }
Example #5
0
        private void Control_MouseDown(object sender, MouseEventArgs e)
        {
            Button ctr = (Button)sender;
            int    i   = 0;

            foreach (Button btn in ColorBtnList)
            {
                if (btn == ctr)
                {
                    break;
                }
                i++;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (ctr.ImageIndex == 0)
                {
                    int count = 0;
                    foreach (Button btn in ColorBtnList)
                    {
                        if (btn.ImageIndex == 0)
                        {
                            count++;
                        }
                    }

                    if (count < 2)
                    {
                        return;
                    }
                    ctr.ImageIndex = 1;

                    #region apply to history
                    TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
                    fi.delHist         = true;
                    IA.delHist         = true;
                    IA.UnDoBtn.Enabled = true;
                    IA.DeleteFromHistory();
                    fi.History.Add("enableColorChanel("
                                   + ColorBtnList.IndexOf(ctr).ToString() + ",true)");
                    fi.History.Add("enableColorChanel("
                                   + ColorBtnList.IndexOf(ctr).ToString() + ",false)");
                    IA.UpdateUndoBtns();
                    #endregion apply to history
                    //apply settings

                    if (i < tifFI.sizeC & i == tifFI.cValue)
                    {
                        IA.RoiMan.current = null;
                        for (int j = 0; j < ColorBtnList.Count - 1; j++)
                        {
                            if (ColorBtnList[j].ImageIndex == 0)
                            {
                                tifFI.cValue = j;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ctr.ImageIndex = 0;

                    #region apply to history
                    TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
                    fi.delHist         = true;
                    IA.delHist         = true;
                    IA.UnDoBtn.Enabled = true;
                    IA.DeleteFromHistory();
                    fi.History.Add("enableColorChanel("
                                   + ColorBtnList.IndexOf(ctr).ToString() + ",false)");
                    fi.History.Add("enableColorChanel("
                                   + ColorBtnList.IndexOf(ctr).ToString() + ",true)");
                    IA.UpdateUndoBtns();
                    #endregion apply to history

                    if (ColorBtnList[tifFI.cValue].ImageIndex != 0)
                    {
                        for (int j = 0; j < ColorBtnList.Count - 1; j++)
                        {
                            if (ColorBtnList[j].ImageIndex == 0)
                            {
                                IA.RoiMan.current = null;
                                tifFI.cValue      = j;
                                break;
                            }
                        }
                    }
                }

                IA.ReloadImages();
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (i >= tifFI.LutList.Count)
                {
                    return;
                }

                ColorDialog colorDialog1 = new ColorDialog();
                colorDialog1.AllowFullOpen = true;
                colorDialog1.AnyColor      = true;
                colorDialog1.FullOpen      = true;

                colorDialog1.Color = tifFI.LutList[i];
                //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)
                {
                    IA.Input.ChangeValueFunction("LUT(" + i.ToString() + "," +
                                                 ColorTranslator.ToHtml(colorDialog1.Color).ToString() + ")");
                }
            }
        }
        public void ApplyCT3Tags(string[] BigVals, TifFileInfo fi)
        {
            int ind = LibTB.SelectedIndex;

            LibTB.SuspendLayout();
            string[] newBigVals = new string[BigVals.Length - 1];
            Array.Copy(BigVals, 1, newBigVals, 0, newBigVals.Length);

            string[] vals = BigVals[0].Split(new string[] { "\t" }, StringSplitOptions.None);

            titleTB.Text           = vals[0];
            FiltersCB.Checked      = bool.Parse(vals[1]);
            SegmentationCB.Checked = bool.Parse(vals[2]);
            SpotDetCB.Checked      = bool.Parse(vals[3]);
            TrackingCB.Checked     = bool.Parse(vals[4]);

            int sizeC = int.Parse(vals[5]);

            if (vals.Length > 6)
            {
                ChartAxisCB.Checked = bool.Parse(vals[6]);
            }
            else
            {
                ChartAxisCB.Checked = false;
            }

            if (vals.Length > 7)
            {
                TimeStepCB.Checked = bool.Parse(vals[7]);
            }
            else
            {
                TimeStepCB.Checked = false;
            }

            if (sizeC == fi.sizeC)
            {
                fi.available = false;
                fi.watershedList.Clear();
                fi.tempWatershedList.Clear();
                fi.FilterHistory.Clear();
                fi.image16bitFilter     = fi.image16bit;
                fi.image8bitFilter      = fi.image8bit;
                fi.newFilterHistory     = null;
                fi.tempNewFilterHistory = null;
                //Apply settings
                int[] filters = IA.TabPages.myFileDecoder.ApplyCT3Tags(newBigVals, fi);
                //background worker

                var bgw = new BackgroundWorker();
                bgw.WorkerReportsProgress = true;

                //Add event for projection here
                bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
                {
                    if (fi.tempNewFilterHistory == null || fi.tempNewFilterHistory.Length != fi.sizeC)
                    {
                        fi.isBinary             = new bool[fi.sizeC];
                        fi.tempNewFilterHistory = new List <string> [fi.sizeC];
                        for (int i = 0; i < fi.sizeC; i++)
                        {
                            fi.tempNewFilterHistory[i] = new List <string>();
                            fi.isBinary[i]             = false;
                        }
                    }

                    if (filters != null)
                    {
                        foreach (int i in filters)
                        {
                            for (int C = 0; C < fi.sizeC; C++)
                            {
                                string str = IA.Segmentation.MyFilters.DecodeOldFilters(C, i);
                                fi.tempNewFilterHistory[C].Add(str);
                            }
                        }
                    }

                    if (fi.tempWatershedList != null)
                    {
                        foreach (string val in fi.tempWatershedList)
                        {
                            int C = int.Parse(val.Split(new string[] { "\t" }, StringSplitOptions.None)[0]);
                            fi.tempNewFilterHistory[C].Add("wshed\t" + val);
                        }
                    }
                    fi.tempWatershedList.Clear();
                    //new filters
                    if (fi.tempNewFilterHistory != null)
                    {
                        try
                        {
                            foreach (List <string> commands in fi.tempNewFilterHistory)
                            {
                                if (commands != null)
                                {
                                    foreach (string command in commands)
                                    {
                                        IA.Segmentation.MyFilters.FilterFromString(command, fi);
                                    }
                                }
                            }
                            fi.newFilterHistory = fi.tempNewFilterHistory;

                            for (int i = 0; i < fi.sizeC; i++)
                            {
                                if (fi.newFilterHistory[i] == null)
                                {
                                    fi.newFilterHistory[i] = new List <string>();
                                }
                            }

                            fi.tempNewFilterHistory = null;
                        }
                        catch { }
                    }

                    ((BackgroundWorker)o).ReportProgress(0);
                });

                bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
                {
                    IA.ReloadImages();
                    fi.available = true;
                    IA.FileBrowser.StatusLabel.Text = "Ready";

                    Loading             = true;
                    LibTB.SelectedIndex = ind;
                    LibTB.ResumeLayout();
                    Loading = false;
                });
                //Start background worker
                IA.FileBrowser.StatusLabel.Text = "Loading settings...";
                //start bgw
                bgw.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("Selected settings can be applied only on image with " + sizeC + " chanels!");
            }
        }
        public static bool OpenFile(List <TabPage> Collection, string path, TabPage tp, ImageAnalyser IA, ToolStripStatusLabel StatusLabel)
        {
            StatusLabel.Text = "Reading Metadata...";

            // read metadata using ImageReader

            loci.formats.ImageReader FirstReader = new loci.formats.ImageReader();

            try
            {
                FirstReader.setId(OSStringConverter.StringToDir(path));
            }
            catch
            {
                FirstReader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }

            bool isRGB = FirstReader.isRGB();

            //check is it rgb colored
            loci.formats.ChannelSeparator reader = loci.formats.ChannelSeparator.makeChannelSeparator(FirstReader);
            FirstReader = null;

            TifFileInfo fi = tp.tifFI;

            fi.seriesCount = reader.getSeriesCount();
            //Select which series to open!!!!!
            int ser = SelectSeries(reader, IA.TabPages.FileBrowser.StatusLabel);

            if (ser == -1)
            {
                fi = null;
                reader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }
            else
            {
                reader.setSeries(ser);
            }
            //Check file bits per pixel - currently supported: 8 bit GrayScale, 16 bit GrayScale
            fi.bitsPerPixel = reader.getBitsPerPixel();
            if (fi.bitsPerPixel <= 8)
            {
                fi.bitsPerPixel = 8;
            }
            else if (fi.bitsPerPixel <= 16)
            {
                fi.bitsPerPixel = 16;
            }
            else
            {
                fi = null;
                reader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }
            //Check is the metadata complieted and return message if not

            /*
             * if (reader.isMetadataComplete() == false)
             * {
             *  MessageBox.Show("Metadata is not complete!");
             * }
             */
            //read tags

            fi.imageCount = reader.getImageCount();
            fi.sizeX      = reader.getSizeX();
            fi.sizeY      = reader.getSizeY();
            fi.sizeZ      = reader.getSizeZ();
            fi.sizeC      = reader.getSizeC();
            fi.sizeT      = reader.getSizeT();
            //fi.dimensionOrder = reader.getDimensionOrder();
            fi.dimensionOrder              = "XYCZT";
            fi.umZ                         = 0;
            fi.umXY                        = 0;
            fi.pixelType                   = reader.getPixelType();
            fi.FalseColored                = reader.isFalseColor();
            fi.isIndexed                   = reader.isIndexed();
            fi.MetadataComplete            = reader.isMetadataComplete();
            fi.DatasetStructureDescription = reader.getDatasetStructureDescription();
            string description = getLibTifFileDescription(path);

            fi.FileDescription = string.Join("\n", new string[] { "-----------------", "CoreMetadata:\n", reader.getCoreMetadataList().ToString(),
                                                                  "-----------------", "GlobalMetadata:\n", reader.getGlobalMetadata().ToString(),
                                                                  "-----------------", "SeriesMetadata:\n", reader.getSeriesMetadata().ToString(),
                                                                  "-----------------", "FileDescription:\n", description });
            //Apply def settings
            fi.Dir       = path;
            fi.xAxisTB   = IA.chart.Properties.xAxisTB.SelectedIndex;
            fi.yAxisTB   = IA.chart.Properties.yAxisTB.SelectedIndex;
            fi.available = false;
            fi.original  = false;
            //Create LUT table
            if (isRGB)
            {
                fi.LutList = new List <Color>()
                {
                    Color.FromArgb(255, 255, 0, 0),
                    Color.FromArgb(255, 0, 255, 0),
                    Color.FromArgb(255, 0, 0, 255)
                };
            }
            else
            {
                fi.LutList = new List <Color>();
                for (int i = 0; i < fi.sizeC; i++)
                {
                    fi.LutList.Add(Color.White);
                }
            }
            //Create time steps table
            fi.TimeSteps = new List <double>();
            fi.TimeSteps.Add(fi.imageCount + 1);
            fi.TimeSteps.Add(1);

            //If its IQ3 format or Dragonflye - try to read the colors and the timesteps
            TryAndorDecoders(fi, description);

            if (fi.sizeC == 0)
            {
                fi.sizeC = 1;
            }
            if (fi.sizeZ == 0)
            {
                fi.sizeZ = 1;
            }
            if (fi.sizeT == 0)
            {
                fi.sizeT = 1;
            }

            #region Segmentation variables
            fi.SegmentationCBoxIndex = new int[fi.sizeC];
            fi.SegmentationProtocol  = new int[fi.sizeC];
            fi.thresholdsCBoxIndex   = new int[fi.sizeC];
            fi.sumHistogramChecked   = new bool[fi.sizeC];
            fi.thresholdValues       = new int[fi.sizeC][];
            fi.thresholdColors       = new Color[fi.sizeC][];
            fi.RefThresholdColors    = new Color[fi.sizeC][];
            fi.thresholds            = new int[fi.sizeC];
            fi.SpotColor             = new Color[fi.sizeC];
            fi.RefSpotColor          = new Color[fi.sizeC];
            fi.SelectedSpotThresh    = new int[fi.sizeC];
            fi.SpotThresh            = new int[fi.sizeC];
            fi.typeSpotThresh        = new int[fi.sizeC];
            fi.SpotTailType          = new string[fi.sizeC];
            fi.spotSensitivity       = new int[fi.sizeC];
            fi.roiList          = new List <ROI> [fi.sizeC];
            fi.tracking_MaxSize = new int[fi.sizeC];
            fi.tracking_MinSize = new int[fi.sizeC];
            fi.tracking_Speed   = new int[fi.sizeC];
            for (int i = 0; i < fi.sizeC; i++)
            {
                fi.sumHistogramChecked[i] = false;
                fi.thresholdValues[i]     = new int[5];
                fi.thresholdColors[i]     = new Color[]
                { Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent };
                fi.RefThresholdColors[i] = new Color[]
                { Color.Black, Color.Orange, Color.Green, Color.Blue, Color.Magenta };
                fi.SpotColor[i]        = Color.Red;
                fi.RefSpotColor[i]     = Color.Red;
                fi.SpotTailType[i]     = "<";
                fi.spotSensitivity[i]  = 100;
                fi.tracking_MaxSize[i] = 10000;
                fi.tracking_MinSize[i] = 5;
                fi.tracking_Speed[i]   = 5;
            }
            #endregion Segmentation variables

            //background worker
            var bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress = true;
            bool loaded = false;
            //Add handlers to the backgroundworker
            bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
            {
                //prepare array and read file
                if (isLibTifCompatible(path) && !isRGB)
                {
                    int[] dimOrder = GetFrameIndexes(reader, fi);
                    Tiff image     = Tiff.Open(OSStringConverter.StringToDir(path), "r");
                    //prepare array and read file
                    int midFrame = fi.sizeC * fi.sizeZ;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[image.NumberOfDirectories()][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image8bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;

                    case 16:
                        fi.image16bit = new ushort[image.NumberOfDirectories()][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image16bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //parallel readers
                    IA.TabPages.myFileDecoder.ImageReader_BGW(Collection, image, fi, IA, path, dimOrder);
                    //report progress
                    dimOrder = null;
                    image.Close();

                    ((BackgroundWorker)o).ReportProgress(1);
                }
                else
                {
                    //Read the first T
                    byte[] buf;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[fi.imageCount][][];

                        buf = new byte[fi.sizeX * fi.sizeY];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image8bit[i] = Image8bit_readFrame(
                                    reader.openBytes(
                                        reader.getIndex(z, c, 0), buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }

                        break;

                    case 16:
                        fi.image16bit = new ushort[fi.imageCount][][];
                        buf           = new byte[fi.sizeX * fi.sizeY * 2];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image16bit[i] = Image16bit_readFrame(
                                    reader.openBytes(
                                        reader.getIndex(z, c, 0), buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //Read the rest T
                    byte[][] bigBuf = new byte[fi.imageCount][];

                    int ZCcount = fi.sizeC * fi.sizeZ;

                    for (int t = 1, i = ZCcount; t < fi.sizeT; t++)
                    {
                        for (int z = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                if (fi.image8bit != null || fi.image16bit != null)
                                {
                                    bigBuf[i] = reader.openBytes(reader.getIndex(z, c, t));
                                }
                            }
                        }
                    }
                    //Format the arrays for CellTool
                    Parallel.For(ZCcount, fi.imageCount, (int i) =>
                    {
                        try
                        {
                            switch (fi.bitsPerPixel)
                            {
                            case 8:
                                if (fi.image8bit != null)
                                {
                                    fi.image8bit[i] = Image8bit_readFrame(bigBuf[i],
                                                                          fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;

                            case 16:
                                if (fi.image16bit != null)
                                {
                                    fi.image16bit[i] = Image16bit_readFrame(bigBuf[i],
                                                                            fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;
                            }
                        }
                        catch { }
                    });
                    bigBuf = null;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(1);
                }
            });
            bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
            {
                if (a.ProgressPercentage == 0)
                {
                    fi.openedImages = fi.sizeC * fi.sizeZ;
                    try
                    {
                        IA.ReloadImages();
                    }
                    catch { }
                }
                else if (a.ProgressPercentage == 1)
                {
                    //dispose the reader
                    reader.close();
                    reader = null;
                    //mark as loaded
                    fi.openedImages = fi.imageCount;
                    fi.available    = true;
                    fi.loaded       = true;

                    IA.TabPages.myFileDecoder.CalculateAllRois(fi);

                    IA.ReloadImages();
                    bool check = true;
                    foreach (TabPage tp1 in Collection)
                    {
                        if (tp1.tifFI != null && tp1.tifFI.available == false)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check == true)
                    {
                        IA.TabPages.myFileDecoder.loadingTimer.Stop();
                        StatusLabel.Text = "Ready";
                    }

                    if (IA.Segmentation.AutoSetUp.LibTB.SelectedIndex > 0 &&
                        IA.Segmentation.AutoSetUp.ApplyToNewCheckB.Checked &&
                        MessageBox.Show("Do you want to open the image with the following protocol:\n" +
                                        IA.Segmentation.AutoSetUp.LibTB.Text,
                                        "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        IA.Segmentation.AutoSetUp.ApplyCT3Tags(IA.Segmentation.AutoSetUp.protocols[
                                                                   IA.Segmentation.AutoSetUp.LibTB.SelectedIndex].Split(
                                                                   new string[] { ";\n" }, StringSplitOptions.None), fi);
                    }
                }
            });

            //Start background worker
            StatusLabel.Text = "Reading Image...";
            //Clear OldImage
            IA.IDrawer.ClearImage();

            //start bgw
            bgw.RunWorkerAsync();
            //add taskbar
            tp.tifFI.tpTaskbar.Initialize(IA.TabPages.ImageMainPanel, IA, fi);

            try
            {
                if (loaded == true)
                {
                    IA.ReloadImages();
                }
            }
            catch { }
            //out put
            return(true);
        }
        private void Node_Click(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button)
            {
                return;
            }
            tv.SelectedNode = e.Node;
            TreeNode n = e.Node;

            if (n == null || n.Tag == null)
            {
                return;
            }

            ROI roi = (ROI)n.Tag;

            if (roi == null)
            {
                roi = (ROI)n.Parent.Tag;
            }

            int ind = 0;

            if (n.Text.IndexOf("Layer") > -1)
            {
                ind = int.Parse(n.Text.Substring(n.Text.LastIndexOf("r") + 1, n.Text.Length - n.Text.LastIndexOf("r") - 1));
            }

            //ColorBrowser
            ColorDialog colorDialog1 = new ColorDialog();

            colorDialog1.AllowFullOpen = true;
            colorDialog1.AnyColor      = true;
            colorDialog1.FullOpen      = true;
            colorDialog1.Color         = roi.colors[ind];
            //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)
            {
                IA.AddToHistoryOld("Chart.SetSeriesColor(" + GetChanel(roi).ToString() + ","
                                   + roi.getID.ToString() + "," + ind.ToString() + "," + ColorTranslator.ToHtml(roi.colors[ind]) + ")");

                roi.colors[ind] = colorDialog1.Color;

                IA.AddToHistoryNew("Chart.SetSeriesColor(" + GetChanel(roi).ToString() + ","
                                   + roi.getID.ToString() + "," + ind.ToString() + "," + ColorTranslator.ToHtml(colorDialog1.Color) + ")");


                foreach (Color col in RefColors)
                {
                    if (colorDialog1.Color == col)
                    {
                        IA.ReloadImages();
                        return;
                    }
                }

                RefColors.Add(colorDialog1.Color);
                createImagesFortTV(colorDialog1.Color);

                IA.ReloadImages();
            }
        }
Example #9
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();
        }
Example #10
0
        private static bool SubstackToolStripMenuItem_click(string path, List <TabPage> Collection, TabPage tp, ImageAnalyser IA, loci.formats.ChannelSeparator reader, int[][] dim)
        {
            TifFileInfo fi = tp.tifFI;

            if (dim == null)
            {
                return(false);
            }
            ////////
            /////background worker
            bool loaded = false;
            //Add handlers to the backgroundworker
            var bgw = new BackgroundWorker();

            bgw.WorkerReportsProgress = true;

            TifFileInfo newFI = null;

            //Add event for projection here
            bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
            {
                //Prepare matrix
                int T, Z, C, f = 0,
                curT, curZ, curC;
                List <int> matrix = new List <int>();
                for (T = 0, curT = dim[0][0] - 1; T < fi.sizeT; T++)
                {
                    if (T == curT && T < dim[0][1])
                    {
                        for (Z = 0, curZ = dim[1][0] - 1; Z < fi.sizeZ; Z++)
                        {
                            if (Z == curZ && Z < dim[1][1])
                            {
                                for (C = 0, curC = dim[2][0] - 1; C < fi.sizeC; C++, f++)
                                {
                                    if (C == curC && C < dim[2][1])
                                    {
                                        //matrix.Add(f);
                                        matrix.Add(reader.getIndex(Z, C, T));
                                        curC += dim[2][2];
                                    }
                                }

                                curZ += dim[1][2];
                            }
                            else
                            {
                                f += fi.sizeC;
                            }
                        }

                        curT += dim[0][2];
                    }
                    else
                    {
                        f += fi.sizeC * fi.sizeZ;
                    }
                }

                newFI     = fi;
                newFI.Dir = newFI.Dir.Substring(0, newFI.Dir.LastIndexOf(".")) +
                            "_Substack.tif";

                newFI.sizeT = 0;
                for (int i = dim[0][0] - 1; i < dim[0][1]; i += dim[0][2])
                {
                    newFI.sizeT++;
                }

                newFI.sizeZ = 0;
                for (int i = dim[1][0] - 1; i < dim[1][1]; i += dim[1][2])
                {
                    newFI.sizeZ++;
                }

                newFI.sizeC          = 0;
                List <Color> colList = new List <Color>();
                for (int i = dim[2][0] - 1; i < dim[2][1]; i += dim[2][2])
                {
                    newFI.sizeC++;
                    colList.Add(fi.LutList[i]);
                }

                newFI.imageCount   = matrix.Count;
                newFI.openedImages = matrix.Count;
                AddEmptyArraysToFI(newFI);
                newFI.LutList = colList;

                //read image

                //Read the first T
                //prepare array and read file
                if (isLibTifCompatible(path) && !reader.isRGB())
                {
                    int[] dimOrder = matrix.ToArray();
                    Tiff image     = Tiff.Open(path, "r");
                    //prepare array and read file
                    int midFrame = fi.sizeC * fi.sizeZ;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[fi.imageCount][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image8bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;

                    case 16:
                        fi.image16bit = new ushort[fi.imageCount][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image16bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //parallel readers
                    IA.TabPages.myFileDecoder.ImageReader_BGW(Collection, image, fi, IA, path, dimOrder);
                    //report progress
                    dimOrder = null;
                    image.Close();

                    ((BackgroundWorker)o).ReportProgress(1);
                }
                else
                {
                    byte[] buf;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[fi.imageCount][][];

                        buf = new byte[fi.sizeX * fi.sizeY];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image8bit[i] = Image8bit_readFrame(
                                    reader.openBytes(
                                        matrix[i], buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }

                        break;

                    case 16:
                        fi.image16bit = new ushort[fi.imageCount][][];
                        buf           = new byte[fi.sizeX * fi.sizeY * 2];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image16bit[i] = Image16bit_readFrame(
                                    reader.openBytes(
                                        matrix[i], buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //Read the rest T
                    byte[][] bigBuf = new byte[fi.imageCount][];

                    int ZCcount = fi.sizeC * fi.sizeZ;

                    for (int t = 1, i = ZCcount; t < fi.sizeT; t++)
                    {
                        for (int z = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                if (fi.image8bit != null || fi.image16bit != null)
                                {
                                    bigBuf[i] = reader.openBytes(matrix[i]);
                                }
                            }
                        }
                    }
                    //Format the arrays for CellTool
                    Parallel.For(ZCcount, fi.imageCount, (int i) =>
                    {
                        try
                        {
                            switch (fi.bitsPerPixel)
                            {
                            case 8:
                                if (fi.image8bit != null)
                                {
                                    fi.image8bit[i] = Image8bit_readFrame(bigBuf[i],
                                                                          fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;

                            case 16:
                                if (fi.image16bit != null)
                                {
                                    fi.image16bit[i] = Image16bit_readFrame(bigBuf[i],
                                                                            fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;
                            }
                        }
                        catch { }
                    });
                    bigBuf = null;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(1);
                }
            });
            bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
            {
                if (a.ProgressPercentage == 0)
                {
                    fi.openedImages = fi.sizeC * fi.sizeZ;
                    try
                    {
                        IA.ReloadImages();
                    }
                    catch { }
                }
                else if (a.ProgressPercentage == 1)
                {
                    //dispose the reader
                    reader.close();
                    reader = null;
                    //mark as loaded
                    fi.openedImages = fi.imageCount;
                    fi.available    = true;
                    fi.loaded       = true;
                    newFI.original  = false;

                    IA.TabPages.myFileDecoder.CalculateAllRois(fi);

                    IA.ReloadImages();
                    bool check = true;
                    foreach (TabPage tp1 in Collection)
                    {
                        if (tp1.tifFI != null && tp1.tifFI.available == false)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check == true)
                    {
                        IA.TabPages.myFileDecoder.loadingTimer.Stop();
                        IA.FileBrowser.StatusLabel.Text = "Ready";
                    }

                    if (IA.Segmentation.AutoSetUp.LibTB.SelectedIndex > 0 &&
                        IA.Segmentation.AutoSetUp.ApplyToNewCheckB.Checked &&
                        MessageBox.Show("Do you want to open the image with the following protocol:\n" +
                                        IA.Segmentation.AutoSetUp.LibTB.Text,
                                        "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        IA.Segmentation.AutoSetUp.ApplyCT3Tags(IA.Segmentation.AutoSetUp.protocols[
                                                                   IA.Segmentation.AutoSetUp.LibTB.SelectedIndex].Split(
                                                                   new string[] { ";\n" }, StringSplitOptions.None), fi);
                    }
                }
            });

            //Start background worker
            IA.FileBrowser.StatusLabel.Text = "Reading Image...";
            //Clear OldImage
            IA.IDrawer.ClearImage();

            //start bgw
            bgw.RunWorkerAsync();
            //add taskbar
            tp.tifFI.tpTaskbar.Initialize(IA.TabPages.ImageMainPanel, IA, fi);

            try
            {
                if (loaded == true)
                {
                    IA.ReloadImages();
                }
            }
            catch { }
            //output
            return(true);
        }
Example #11
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();
                }
            }
        }
Example #12
0
        private void PlugIn_Load(string path)
        {
            TifFileInfo oldFI = null;

            try
            {
                oldFI = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
            }
            catch { }


            CellToolDK.TifFileInfo fi = FItoCellToolDK(oldFI);

            var DLL = Assembly.LoadFile(path);

            foreach (Type type in DLL.GetExportedTypes())
            {
                try
                {
                    Transmiter e = new Transmiter();

                    e.Changed += new TransmiterEventHandler(delegate(object o, TransmiterEventArgs a)
                    {
                        try
                        {
                            if (fi != null && oldFI != null)
                            {
                                if (fi.sizeC != oldFI.sizeC)
                                {
                                    oldFI.sizeC = fi.sizeC;
                                    FI_reduseC(fi);
                                    FI_reduseC(oldFI);
                                }

                                CellToolDKtoFI(fi, oldFI);

                                if (oldFI.sizeZ > 1)
                                {
                                    IA.TabPages.zTrackBar.Refresh(oldFI.zValue + 1, 1, oldFI.sizeZ);
                                    IA.TabPages.zTrackBar.Panel.Visible = true;
                                }
                                else
                                {
                                    IA.TabPages.zTrackBar.Panel.Visible = false;
                                }

                                if (oldFI.sizeT > 1)
                                {
                                    IA.TabPages.tTrackBar.Refresh(oldFI.frame + 1, 1, oldFI.sizeT);
                                    IA.TabPages.tTrackBar.Panel.Visible = true;
                                }
                                else
                                {
                                    IA.TabPages.tTrackBar.Panel.Visible = false;
                                }
                            }
                        }
                        catch { MessageBox.Show("Error with reporting back!"); }

                        IA.ReloadImages();
                    });

                    var c = Activator.CreateInstance(type);

                    try
                    {
                        type.InvokeMember("Input", BindingFlags.InvokeMethod, null, c, new object[] { fi, e });
                    }
                    catch { MessageBox.Show("Input void is not avaliable!"); }
                    break;
                }
                catch { }
            }
        }