コード例 #1
0
        public void Save(ImageAnalyser IA)
        {
            TifFileInfo tifFI = this.tifFI;

            if (tifFI != null)
            {
                if (!tifFI.available)
                {
                    MessageBox.Show("Image is not avaliable!\nTry again later.");
                    return;
                }

                string dir = tifFI.Dir;
                //background worker
                var bgw = new BackgroundWorker();
                bgw.WorkerReportsProgress = true;
                //Add handlers to the backgroundworker
                //Reports when is finished

                bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
                {
                    FileEncoder.SaveTif(tifFI, dir, IA);
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                });

                bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
                {
                    if (a.ProgressPercentage == 0)
                    {
                        Saved = true;
                        if (tifFI != null)
                        {
                            tifFI.available = true;
                        }
                        IA.FileBrowser.StatusLabel.Text = "Ready";
                    }
                });

                //Start background worker
                tifFI.available = false;
                IA.FileBrowser.StatusLabel.Text = "Saving Tif Image...";

                IA.EnabletrackBars(false);
                bgw.RunWorkerAsync();
                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }

                IA.EnabletrackBars(true);
            }
            else if (ResultsExtractor != null)
            {
                var bgw = ResultsExtractor.FileSaver.SaveCTDataFile(
                    (Cell_Tool_3.ResultsExtractor.MyForm)
                    this.ResultsExtractor.myPanel, dir);

                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }
            }
        }
コード例 #2
0
        private string calculateCTTagValue(TifFileInfo fi, ImageAnalyser IA)
        {
            List <string> vals = new List <string>();

            string val = titleTB.Text + "\t" +
                         FiltersCB.Checked.ToString() + "\t" +
                         SegmentationCB.Checked.ToString() + "\t" +
                         SpotDetCB.Checked.ToString() + "\t" +
                         TrackingCB.Checked.ToString() + "\t" +
                         fi.sizeC + "\t" +
                         ChartAxisCB.Checked.ToString() + "\t" +
                         TimeStepCB.Checked.ToString();

            vals.Add(val);

            if (FiltersCB.Checked)
            {
                vals.Add("tracking_MaxSize->" + FileEncoder.TagValueToString(fi.tracking_MaxSize));
                vals.Add("tracking_MinSize->" + FileEncoder.TagValueToString(fi.tracking_MinSize));
                vals.Add("tracking_Speed->" + FileEncoder.TagValueToString(fi.tracking_Speed));
            }

            if (SegmentationCB.Checked)
            {
                vals.Add("SegmentationProtocol->" + FileEncoder.TagValueToString(fi.SegmentationProtocol));
                vals.Add("SegmentationCBoxIndex->" + FileEncoder.TagValueToString(fi.SegmentationCBoxIndex));
                vals.Add("thresholdsCBoxIndex->" + FileEncoder.TagValueToString(fi.thresholdsCBoxIndex));
                vals.Add("RefSpotColor->" + FileEncoder.TagValueToString(fi.RefSpotColor));
                vals.Add("sumHistogramChecked->" + FileEncoder.TagValueToString(fi.sumHistogramChecked));
                vals.Add("thresholdColors->" + FileEncoder.TagValueToString(fi.thresholdColors));
                vals.Add("RefThresholdColors->" + FileEncoder.TagValueToString(fi.RefThresholdColors));
                vals.Add("thresholdValues->" + FileEncoder.TagValueToString(fi.thresholdValues));
                vals.Add("thresholds->" + FileEncoder.TagValueToString(fi.thresholds));
            }

            if (SpotDetCB.Checked)
            {
                vals.Add("SelectedSpotThresh->" + FileEncoder.TagValueToString(fi.SelectedSpotThresh));
                vals.Add("typeSpotThresh->" + FileEncoder.TagValueToString(fi.typeSpotThresh));
                vals.Add("SpotThresh->" + FileEncoder.TagValueToString(fi.SpotThresh));
                vals.Add("spotSensitivity->" + FileEncoder.TagValueToString(fi.spotSensitivity));
                vals.Add("SpotColor->" + FileEncoder.TagValueToString(fi.SpotColor));
                vals.Add("SpotTailType->" + string.Join("\t", fi.SpotTailType));
            }

            if (FiltersCB.Checked)
            {
                if (fi.newFilterHistory != null)
                {
                    vals.Add("newFilters->" + FileEncoder.TagValueToString(fi.newFilterHistory));
                }

                //vals.Add("FilterHistory->" + FileEncoder.TagValueToString(fi.FilterHistory.ToArray()));

                // if (fi.watershedList.Count!=0)
                //vals.Add("watershed->" + string.Join("\n", fi.watershedList));
            }

            if (ChartAxisCB.Checked)
            {
                vals.Add("xAxisTB->" + fi.xAxisTB.ToString());
                vals.Add("yAxisTB->" + fi.yAxisTB.ToString());
            }

            if (TimeStepCB.Checked)
            {
                vals.Add("TimeSteps->" + FileEncoder.TagValueToString(fi.TimeSteps));
            }

            return(string.Join(";\n", vals));
        }
コード例 #3
0
        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!");
            }
        }
コード例 #4
0
        private static string calculateCTTagValue(TifFileInfo fi, ImageAnalyser IA)
        {
            List <string> vals = new List <string>();

            vals.Add("seriesCount->" + fi.seriesCount.ToString());
            vals.Add("imageCount->" + fi.imageCount.ToString());
            vals.Add("sizeX->" + fi.sizeX.ToString());
            vals.Add("sizeY->" + fi.sizeY.ToString());
            vals.Add("sizeC->" + fi.sizeC.ToString());
            vals.Add("sizeZ->" + fi.sizeZ.ToString());
            vals.Add("sizeT->" + fi.sizeT.ToString());
            vals.Add("umXY->" + fi.umXY.ToString());
            vals.Add("umZ->" + fi.umZ.ToString());
            vals.Add("bitsPerPixel->" + fi.bitsPerPixel.ToString());
            vals.Add("dimensionOrder->" + fi.dimensionOrder);
            vals.Add("pixelType->" + fi.pixelType.ToString());
            vals.Add("FalseColored->" + fi.FalseColored.ToString());
            vals.Add("isIndexed->" + fi.isIndexed.ToString());
            vals.Add("MetadataComplete->" + fi.MetadataComplete.ToString());
            vals.Add("DatasetStructureDescription->" + fi.DatasetStructureDescription);
            vals.Add("Micropoint->" + fi.Micropoint.ToString());
            vals.Add("autoDetectBandC->" + fi.autoDetectBandC.ToString());
            vals.Add("applyToAllBandC->" + fi.applyToAllBandC.ToString());
            vals.Add("xCompensation->" + fi.xCompensation.ToString());
            vals.Add("yCompensation->" + fi.yCompensation.ToString());
            vals.Add("DataSourceInd->" + fi.DataSourceInd.ToString());
            vals.Add("LutList->" + TagValueToString(fi.LutList));
            vals.Add("TimeSteps->" + TagValueToString(fi.TimeSteps));
            vals.Add("MinBrightness->" + TagValueToString(fi.MinBrightness));
            vals.Add("MaxBrightness->" + TagValueToString(fi.MaxBrightness));
            vals.Add("tracking_MaxSize->" + TagValueToString(fi.tracking_MaxSize));
            vals.Add("tracking_MinSize->" + TagValueToString(fi.tracking_MinSize));
            vals.Add("tracking_Speed->" + TagValueToString(fi.tracking_Speed));
            vals.Add("SegmentationProtocol->" + TagValueToString(fi.SegmentationProtocol));
            vals.Add("SegmentationCBoxIndex->" + TagValueToString(fi.SegmentationCBoxIndex));
            vals.Add("thresholdsCBoxIndex->" + TagValueToString(fi.thresholdsCBoxIndex));
            vals.Add("SelectedSpotThresh->" + TagValueToString(fi.SelectedSpotThresh));
            vals.Add("typeSpotThresh->" + TagValueToString(fi.typeSpotThresh));
            vals.Add("SpotThresh->" + TagValueToString(fi.SpotThresh));
            vals.Add("spotSensitivity->" + TagValueToString(fi.spotSensitivity));
            vals.Add("thresholds->" + TagValueToString(fi.thresholds));
            vals.Add("SpotColor->" + TagValueToString(fi.SpotColor));
            vals.Add("RefSpotColor->" + TagValueToString(fi.RefSpotColor));
            vals.Add("sumHistogramChecked->" + TagValueToString(fi.sumHistogramChecked));
            vals.Add("SpotTailType->" + string.Join("\t", fi.SpotTailType));
            vals.Add("thresholdColors->" + TagValueToString(fi.thresholdColors));
            vals.Add("RefThresholdColors->" + TagValueToString(fi.RefThresholdColors));
            vals.Add("thresholdValues->" + TagValueToString(fi.thresholdValues));
            vals.Add("FileDescription->" + fi.FileDescription.Replace(";", ".").Replace("->", ": "));
            vals.Add("xAxisTB->" + fi.xAxisTB.ToString());
            vals.Add("yAxisTB->" + fi.yAxisTB.ToString());
            if (fi.yAxisTB >= 5)
            {
                vals.Add("yFormula->" + IA.chart.Properties.GetFunction(fi.yAxisTB).Replace(";", ""));
            }

            //Roi part
            int c = 0;

            foreach (List <ROI> roiList in fi.roiList)
            {
                if (roiList != null)
                {
                    foreach (ROI roi in roiList)
                    {
                        vals.Add("roi.new->" + IA.RoiMan.roi_new(c, roi));
                    }
                }
                c++;
            }

            //it is important FilterHistory to be the last
            //vals.Add("FilterHistory->" + TagValueToString(fi.FilterHistory.ToArray()));

            //if (fi.watershedList.Count != 0)
            //vals.Add("watershed->" + string.Join("\n", fi.watershedList));

            if (fi.newFilterHistory != null)
            {
                vals.Add("newFilters->" + TagValueToString(fi.newFilterHistory));
            }

            return(string.Join(";\n", vals));
        }
コード例 #5
0
        private static void SaveTif_8bitRawData(TifFileInfo fi, string fileName, ImageAnalyser IA)
        {
            // Register the extender callback
            m_parentExtender = Tiff.SetTagExtender(TagExtender);
            string value = calculateCTTagValue(fi, IA);

            int numberOfPages = fi.imageCount;

            int width           = fi.sizeX;
            int height          = fi.sizeY;
            int samplesPerPixel = 1;
            int bitsPerSample   = fi.bitsPerPixel;

            //check the size of the image and start the writer
            int writersCount = NumberOfTiffWriters(fi);

            if (writersCount == 1)
            {
                using (Tiff output = Tiff.Open(fileName, "w"))
                {
                    for (int page = 0; page < numberOfPages; page++)
                    {
                        byte[][] firstPageBuffer = fi.image8bit[page];
                        output.SetField(TiffTag.IMAGELENGTH, height);
                        output.SetField(TiffTag.IMAGEWIDTH, width);
                        output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                        output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                        output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                        output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                        output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                        output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                        output.SetField(TiffTag.COMPRESSION, Compression.NONE);
                        output.SetField(TiffTag.IMAGEDESCRIPTION, ImageDetails());
                        // specify that it's a page within the multipage file
                        output.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
                        // specify the page number
                        output.SetField(TiffTag.PAGENUMBER, page, numberOfPages);

                        if (page == numberOfPages - 1)
                        {
                            // set the custom tag
                            output.SetField(TIFFTAG_CellTool_METADATA, value);
                        }
                        for (int j = 0; j < height; ++j)
                        {
                            output.WriteScanline(firstPageBuffer[j], j);
                        }

                        output.WriteDirectory();
                    }
                }
            }
            else
            {
                string newFileName = CheckForFileChain(fileName);               //Remove time chain suffix
                newFileName = newFileName.Substring(0, newFileName.Length - 4); //remove .tif extension

                int pageMaxPerWriter = NumberOfFramesPerPart(fi);               //get maximal pages per writer

                fi.Dir = FileChain_GetName(0, newFileName);                     //set the filename to the first file from the chain

                Parallel.For(0, writersCount, (ind) =>
                {
                    int start = ind * pageMaxPerWriter;
                    int stop  = start + pageMaxPerWriter;
                    using (Tiff output = Tiff.Open(FileChain_GetName(ind, newFileName), "w"))
                    {
                        for (int page = 0; start < numberOfPages && start < stop; page++, start++)
                        {
                            byte[][] firstPageBuffer = fi.image8bit[start];
                            output.SetField(TiffTag.IMAGELENGTH, height);
                            output.SetField(TiffTag.IMAGEWIDTH, width);
                            output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                            output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                            output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                            output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                            output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                            output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                            output.SetField(TiffTag.COMPRESSION, Compression.NONE);
                            output.SetField(TiffTag.IMAGEDESCRIPTION, ImageDetails());
                            // specify that it's a page within the multipage file
                            output.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
                            // specify the page number
                            output.SetField(TiffTag.PAGENUMBER, page, pageMaxPerWriter);

                            if (start == numberOfPages - 1 || start == stop - 1)
                            {
                                // set the custom tag
                                output.SetField(TIFFTAG_CellTool_METADATA, value);
                            }
                            for (int j = 0; j < height; ++j)
                            {
                                output.WriteScanline(firstPageBuffer[j], j);
                            }

                            output.WriteDirectory();
                        }
                    }
                });
            }
            // restore previous tag extender
            Tiff.SetTagExtender(m_parentExtender);
        }
コード例 #6
0
        public static void ExportAllResults(TifFileInfo fi)
        {
            string dir = fi.Dir.Replace(".tif", "");

            //background worker

            //var bgw = new BackgroundWorker();
            //bgw.WorkerReportsProgress = true;
            fi.available = false;
            //Add event for projection here
            //bgw.DoWork += new DoWorkEventHandler(delegate (Object o, DoWorkEventArgs a)
            {
                for (int c = 0; c < fi.sizeC; c++)
                {
                    if (fi.roiList[c] != null && fi.roiList[c].Count != 0)
                    {
                        string dir1 = dir + "_Ch" + c + "_" +
                                      fi.LutList[c].ToString().Replace("Color [", "").Replace("]", "") +
                                      ".txt";
                        string dir2 = dir + "_Ch" + c + "_" +
                                      fi.LutList[c].ToString().Replace("Color [", "").Replace("]", "") +
                                      "_Results.txt";
                        //calculate the size of the result row
                        int resultSize = 0;
                        foreach (ROI roi in fi.roiList[c])
                        {
                            if (roi.Checked == true)
                            {
                                if (roi.Results == null)
                                {
                                    RoiMeasure.Measure(roi, fi, c);
                                }
                                if (roi.Shape == 0 || roi.Shape == 1)
                                {
                                    resultSize += roi.Results[c].Length;
                                }
                                else if (roi.Shape == 2 || roi.Shape == 3 || roi.Shape == 4 || roi.Shape == 5)
                                {
                                    resultSize += 4 + roi.Stack * 4;
                                }
                            }
                        }
                        //chart result
                        string val = GetResults(fi, c);
                        if (val != "")
                        {
                            try
                            {
                                File.WriteAllText(dir1, val);
                            }
                            catch
                            {
                                Console.Write("File is used by other program!");
                                //((BackgroundWorker)o).ReportProgress(1);
                            }
                        }
                        //standart results
                        if (resultSize == 0)
                        {
                            continue;
                        }

                        {
                            //create result matrix
                            double[] result;

                            int    t = 1;
                            int    z = 1;
                            int    position;
                            string str;

                            double time      = 0;
                            int    timeIndex = 0;
                            double timeT     = fi.TimeSteps[timeIndex];
                            try
                            {
                                if (File.Exists(dir2))
                                {
                                    File.Delete(dir2);
                                }
                            }
                            catch
                            {
                                //((BackgroundWorker)o).ReportProgress(1);
                                Console.Write("File is used by other program!");
                                continue;
                            }

                            using (StreamWriter write = new StreamWriter(dir2))
                            {
                                //titles part
                                List <string> titles = new List <string>();
                                titles.Add("ImageN");
                                if (fi.sizeT > 1)
                                {
                                    titles.Add("T");
                                }
                                if (fi.sizeT > 1)
                                {
                                    titles.Add("T(sec.)");
                                }
                                if (fi.sizeZ > 1)
                                {
                                    titles.Add("Z");
                                }

                                int roiN = 1;
                                foreach (ROI roi in fi.roiList[c])
                                {
                                    if (roi.Checked == true && roi.Results[c] != null)
                                    {
                                        string com = "";
                                        if (roi.Comment != "")
                                        {
                                            com = ": " + roi.Comment;
                                        }

                                        titles.Add("Area" + roiN.ToString() + com);
                                        titles.Add("Mean" + roiN.ToString() + com);
                                        titles.Add("Min" + roiN.ToString() + com);
                                        titles.Add("Max" + roiN.ToString() + com);
                                        if (roi.Stack > 0)
                                        {
                                            if (roi.Shape == 0 || roi.Shape == 1)
                                            {
                                                for (int n = 1; n <= roi.Stack; n++)
                                                {
                                                    titles.Add("Area" + roiN.ToString() + "." + n.ToString() + ".LeftUp" + com);
                                                    titles.Add("Mean" + roiN.ToString() + "." + n.ToString() + ".LeftUp" + com);
                                                    titles.Add("Min" + roiN.ToString() + "." + n.ToString() + ".LeftUp" + com);
                                                    titles.Add("Max" + roiN.ToString() + "." + n.ToString() + ".LeftUp" + com);

                                                    titles.Add("Area" + roiN.ToString() + "." + n.ToString() + ".RightUp" + com);
                                                    titles.Add("Mean" + roiN.ToString() + "." + n.ToString() + ".RightUp" + com);
                                                    titles.Add("Min" + roiN.ToString() + "." + n.ToString() + ".RightUp" + com);
                                                    titles.Add("Max" + roiN.ToString() + "." + n.ToString() + ".RightUp" + com);

                                                    titles.Add("Area" + roiN.ToString() + "." + n.ToString() + ".LeftDown" + com);
                                                    titles.Add("Mean" + roiN.ToString() + "." + n.ToString() + ".LeftDown" + com);
                                                    titles.Add("Min" + roiN.ToString() + "." + n.ToString() + ".LeftDown" + com);
                                                    titles.Add("Max" + roiN.ToString() + "." + n.ToString() + ".LeftDown" + com);

                                                    titles.Add("Area" + roiN.ToString() + "." + n.ToString() + ".RightDown" + com);
                                                    titles.Add("Mean" + roiN.ToString() + "." + n.ToString() + ".RightDown" + com);
                                                    titles.Add("Min" + roiN.ToString() + "." + n.ToString() + ".RightDown" + com);
                                                    titles.Add("Max" + roiN.ToString() + "." + n.ToString() + ".RightDown" + com);
                                                }
                                            }
                                            else if (roi.Shape == 2 || roi.Shape == 3 || roi.Shape == 4 || roi.Shape == 5)
                                            {
                                                for (int n = 1; n <= roi.Stack; n++)
                                                {
                                                    titles.Add("Area" + roiN.ToString() + "." + n.ToString() + com);
                                                    titles.Add("Mean" + roiN.ToString() + "." + n.ToString() + com);
                                                    titles.Add("Min" + roiN.ToString() + "." + n.ToString() + com);
                                                    titles.Add("Max" + roiN.ToString() + "." + n.ToString() + com);
                                                }
                                            }
                                        }
                                    }
                                    roiN++;
                                }
                                write.WriteLine(string.Join("\t", titles));
                                //calculations
                                for (int i = c; i < fi.imageCount; i += fi.sizeC)
                                {
                                    //extract row from rois
                                    position = 0;
                                    result   = new double[resultSize];
                                    foreach (ROI roi in fi.roiList[c])
                                    {
                                        if (roi.Checked == true)
                                        {
                                            if (roi.Shape == 0 || roi.Shape == 1)
                                            {
                                                if (roi.Results[i] != null &&
                                                    roi.FromT <= t && roi.ToT >= t &&
                                                    roi.FromZ <= z && roi.ToZ >= z)
                                                {
                                                    Array.Copy(roi.Results[i], 0, result, position, roi.Results[i].Length);
                                                }

                                                position += roi.Results[c].Length;
                                            }
                                            else if (roi.Shape == 2 || roi.Shape == 3 || roi.Shape == 4 || roi.Shape == 5)
                                            {
                                                if (roi.Results[i] != null &&
                                                    roi.FromT <= t && roi.ToT >= t &&
                                                    roi.FromZ <= z && roi.ToZ >= z)
                                                {
                                                    //main roi
                                                    Array.Copy(roi.Results[i], 0, result, position, 4);
                                                    position += 4;
                                                    //layers
                                                    for (int p = 4; p < roi.Results[i].Length; p += 16)
                                                    {
                                                        Array.Copy(roi.Results[i], p, result, position, 4);
                                                        position += 4;
                                                    }
                                                }
                                                else
                                                {
                                                    position += 4;
                                                    //layers
                                                    for (int p = 4; p < roi.Results[i].Length; p += 16)
                                                    {
                                                        position += 4;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    //write the line
                                    if (CheckArrayForValues(result))
                                    {
                                        str = string.Join("\t", result);

                                        if (fi.sizeZ > 1)
                                        {
                                            str = z.ToString() + "\t" + str;
                                        }
                                        if (fi.sizeT > 1)
                                        {
                                            str = t.ToString() + "\t" + time.ToString() + "\t" + str;
                                        }
                                        str = i.ToString() + "\t" + str;
                                        write.WriteLine(str);
                                    }
                                    //recalculate z and t

                                    z += 1;
                                    if (z > fi.sizeZ)
                                    {
                                        z  = 1;
                                        t += 1;

                                        if (t > fi.sizeT)
                                        {
                                            t = 1;
                                        }

                                        if (t <= timeT)
                                        {
                                            time += fi.TimeSteps[timeIndex + 1];
                                        }
                                        else
                                        {
                                            timeIndex += 2;

                                            if (timeIndex < fi.TimeSteps.Count)
                                            {
                                                timeT += fi.TimeSteps[timeIndex];
                                            }
                                            else
                                            {
                                                timeIndex -= 2;
                                                timeT     += fi.imageCount;
                                            }

                                            time += fi.TimeSteps[timeIndex + 1];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

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

            // bgw.ProgressChanged += new ProgressChangedEventHandler(delegate (Object o, ProgressChangedEventArgs a)
            {
                //if (a.ProgressPercentage == 0)
                {
                    fi.available = true;
                }
                //else
                //{
                //    MessageBox.Show("File is used by other program!");
                // }
            }//);
             //Start background worker
             //IA.FileBrowser.StatusLabel.Text = "Saving results...";
             //start bgw
             //bgw.RunWorkerAsync();

            fi.available = true;
        }
コード例 #7
0
 public void AddYAxisTBToHistory(TifFileInfo fi)
 {
     fi.History.Add("Chart.YAxisType(" + fi.yAxisTB.ToString() + ")");
 }
コード例 #8
0
        private void calculate16bitHistogram(float[] h, TifFileInfo fi, int width, int height)
        {
            if (fi.sumHistogramChecked[fi.cValue] == false)
            {
                //histogram of current frame
                FrameCalculator FC    = new FrameCalculator();
                int             frame = FC.FrameC(fi, fi.cValue);

                int   maxVal = ushort.MaxValue + 1;
                int[] lut    = new int[maxVal];
                //convert information to 8 bit
                int step = (int)(calculateMaxIntensity(fi, frame) / 256);
                GlobalStep16Bit = step;
                for (int i = 0, count = 0, val = 0; i < maxVal; i++, count++)
                {
                    if (count >= step)
                    {
                        count = 0;
                        if (val < 255)
                        {
                            val++;
                        }
                    }
                    lut[i] = val;
                }
                //calculate histogram
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        h[lut[fi.image16bitFilter[frame][y][x]]]++;
                    }
                }
            }
            else
            {
                //histogram of all images
                int[]     input = new int[(int)(fi.imageCount / fi.sizeC)];
                float[][] hList = new float[input.Length][];

                //check wich frames are from selected color
                for (int i = 0, val = fi.cValue; i < input.Length; i++, val += fi.sizeC)
                {
                    input[i] = val;
                }
                //Find absolute max intensity
                ushort[] maxVals = new ushort[input.Length];
                Parallel.For(0, input.Length, (i) =>
                {
                    maxVals[i] = calculateMaxIntensity(fi, input[i]);
                });

                ushort max = 0;
                foreach (ushort val in maxVals)
                {
                    if (val > max)
                    {
                        max = val;
                    }
                }

                int   maxVal = ushort.MaxValue + 1;
                int[] lut    = new int[maxVal];
                //convert information to 8 bit
                int step = (int)(max / 256);
                GlobalStep16Bit = step;
                for (int i = 0, count = 0, val = 0; i < maxVal; i++, count++)
                {
                    if (count >= step)
                    {
                        count = 0;
                        if (val < 255)
                        {
                            val++;
                        }
                    }
                    lut[i] = val;
                }
                //calculate histograms for all images
                Parallel.For(0, input.Length, (i) =>
                {
                    float[] h1 = new float[NGRAY];

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            h[lut[fi.image16bitFilter[input[i]][y][x]]]++;
                        }
                    }

                    hList[i] = h1;
                });
                //sum histograms to one
                for (int hInd = 0; hInd < hList.Length; hInd++)
                {
                    for (int i = 0; i < NGRAY; i++)
                    {
                        h[i] += hList[hInd][i];
                    }
                }
            }
        }
コード例 #9
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 { }
            }
        }
コード例 #10
0
        public void run(TifFileInfo fi, int MLEVEL)
        {
            fi.thresholds[fi.cValue] = MLEVEL - 1;
            if (MLEVEL < 2)
            {
                return;
            }
            //create arrays in fi
            fi.thresholdValues[fi.cValue] = new int[5];
            Color[] refCol = fi.RefThresholdColors[fi.cValue];
            switch (fi.thresholdsCBoxIndex[fi.cValue])
            {
            case 1:
                fi.thresholdColors[fi.cValue] = new Color[]
                { refCol[0], refCol[1], Color.Transparent, Color.Transparent, Color.Transparent };
                break;

            case 2:
                fi.thresholdColors[fi.cValue] = new Color[]
                { refCol[0], refCol[1], refCol[2], Color.Transparent, Color.Transparent };
                break;

            case 3:
                fi.thresholdColors[fi.cValue] = new Color[]
                { refCol[0], refCol[1], refCol[2], refCol[3], Color.Transparent };
                break;

            case 4:
                fi.thresholdColors[fi.cValue] = new Color[]
                { refCol[0], refCol[1], refCol[2], refCol[3], refCol[4] };
                break;

            default:
                fi.thresholdColors[fi.cValue] = new Color[]
                { Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent };
                break;
            }
            //create variables
            int[] threshold = new int[MLEVEL]; // threshold
            int   width     = fi.sizeX;
            int   height    = fi.sizeY;

            ////////////////////////////////////////////
            // Build Histogram
            ////////////////////////////////////////////
            float[] h = new float[NGRAY];
            buildHistogram(h, fi, width, height);
            /////////////////////////////////////////////
            // Build lookup tables from h
            ////////////////////////////////////////////
            float[][] P = new float[NGRAY][];
            float[][] S = new float[NGRAY][];
            float[][] H = new float[NGRAY][];
            buildLookupTables(P, S, H, h);
            ////////////////////////////////////////////////////////
            // now M level loop   MLEVEL dependent term
            ////////////////////////////////////////////////////////
            float maxSig = findMaxSigma(MLEVEL, H, threshold);

            //apply to LUT

            switch (fi.bitsPerPixel)
            {
            case 8:
                for (int i = 0; i < MLEVEL; i++)
                {
                    fi.thresholdValues[fi.cValue][i] = threshold[i];
                }
                break;

            case 16:
                for (int i = 0; i < MLEVEL; i++)
                {
                    fi.thresholdValues[fi.cValue][i] = threshold[i] * GlobalStep16Bit;
                }
                break;
            }
        }
コード例 #11
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
        }
コード例 #12
0
        public void loadThreshAndColorBtns(TifFileInfo fi)
        {
            //panel.SuspendLayout();
            int threshNum = fi.thresholds[fi.cValue];

            int[] vals1 = fi.thresholdValues[fi.cValue];
            int   min   = 0;
            int   max   = 0;

            switch (fi.bitsPerPixel)
            {
            case 8:
                max = 255;     // 2^8  - 1
                break;

            case 16:
                max = ushort.MaxValue;    //16383; //2^14 - 1
                break;
            }

            for (int i = 0; i < colorBtns.Length; i++)
            {
                //color btns
                if (i <= threshNum & colorBtns[i].Visible == false)
                {
                    colorBtns[i].Visible = true;
                    colorBtns[i].BringToFront();
                }
                else if (i > threshNum)
                {
                    colorBtns[i].Visible = false;
                }

                Color col = fi.thresholdColors[fi.cValue][i];

                if (col != Color.Transparent)
                {
                    colorBtns[i].BackColor = col;
                    colorBtns[i].Text      = "";
                }
                else
                {
                    colorBtns[i].BackColor = Color.White;
                    colorBtns[i].Text      = "NaN";
                }
                //trackBars
                if (i < threshNum & i < threshTrackBars.Length)
                {
                    if (threshTrackBars[i].Panel.Visible == false)
                    {
                        threshTrackBars[i].Panel.Visible = true;
                        threshTrackBars[i].Panel.BringToFront();
                    }
                    threshTrackBars[i].Refresh(vals1[i + 1], min, max);
                }
                else if (i >= threshNum & i < threshTrackBars.Length)
                {
                    threshTrackBars[i].Panel.Visible = false;
                }
            }
            //Resize Panel

            if (threshNum == 0)
            {
                panel.Height = 85;
            }
            else
            {
                panel.Height = 105 + 25 * (threshNum + 1);
            }

            panel.ResumeLayout();
        }
コード例 #13
0
        private void ColorBtn_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.thresholdColors[fi.cValue][(int)btn.Tag] == Color.Transparent)
                {
                    fi.thresholdColors[fi.cValue][(int)btn.Tag] =
                        fi.RefThresholdColors[fi.cValue][(int)btn.Tag];
                }
                else
                {
                    fi.thresholdColors[fi.cValue][(int)btn.Tag] = Color.Transparent;
                }

                #region apply to history
                Color val    = fi.RefThresholdColors[fi.cValue][(int)btn.Tag];
                Color oldVal = Color.Transparent;

                if (fi.thresholdColors[fi.cValue][(int)btn.Tag] == Color.Transparent)
                {
                    val = Color.Transparent; oldVal = fi.RefThresholdColors[fi.cValue][(int)btn.Tag];
                }

                fi.delHist         = true;
                IA.delHist         = true;
                IA.UnDoBtn.Enabled = true;
                IA.DeleteFromHistory(); fi.History.Add("segmentation.SetColor("
                                                       + fi.cValue.ToString() + "," +
                                                       ((int)btn.Tag).ToString() + "," +
                                                       ColorTranslator.ToHtml(oldVal) + ")");
                fi.History.Add("segmentation.SetColor("
                               + fi.cValue.ToString() + "," +
                               ((int)btn.Tag).ToString() + "," +
                               ColorTranslator.ToHtml(val) + ")");
                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.RefThresholdColors[fi.cValue][(int)btn.Tag];
                //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
                    fi.delHist         = true;
                    IA.delHist         = true;
                    IA.UnDoBtn.Enabled = true;
                    IA.DeleteFromHistory(); fi.History.Add("segmentation.SetColor("
                                                           + fi.cValue + "," + ((int)btn.Tag).ToString() + ","
                                                           + ColorTranslator.ToHtml(fi.thresholdColors[fi.cValue][(int)btn.Tag]) + ")");
                    fi.History.Add("segmentation.SetColor("
                                   + fi.cValue + "," + ((int)btn.Tag).ToString() + ","
                                   + ColorTranslator.ToHtml(colorDialog1.Color) + ")");
                    IA.UpdateUndoBtns();
                    IA.MarkAsNotSaved();
                    #endregion apply to history
                    fi.RefThresholdColors[fi.cValue][(int)btn.Tag] = colorDialog1.Color;
                    fi.thresholdColors[fi.cValue][(int)btn.Tag]    = colorDialog1.Color;
                    IA.ReloadImages();
                }
            }
        }
コード例 #14
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();
            }
        }
コード例 #15
0
        private void Chart1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            TifFileInfo fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;

            Form OptionForm = new Form();

            OptionForm.FormBorderStyle = FormBorderStyle.FixedDialog;
            OptionForm.Width           = 200;
            OptionForm.Height          = 180;
            OptionForm.Text            = "LUT";
            OptionForm.StartPosition   = FormStartPosition.CenterScreen;
            OptionForm.WindowState     = FormWindowState.Normal;
            OptionForm.BackColor       = PropPanel.Body.BackColor;
            //Add hot keys to main form
            OptionForm.KeyPreview = true;
            OptionForm.KeyDown   += new KeyEventHandler(OptionForm_KeyPress);
            {
                Label l = new Label();
                l.Text      = "Color:";
                l.Width     = TextRenderer.MeasureText(l.Text, l.Font).Width;
                l.ForeColor = Color.White;
                l.Location  = new Point(15, 15);
                OptionForm.Controls.Add(l);

                Button btn = new Button();
                btn.FlatAppearance.BorderSize = 0;
                btn.FlatStyle = FlatStyle.Flat;
                btn.Click    += new EventHandler(changeLUT);
                btn.BackColor = fi.LutList[fi.cValue];
                btn.Location  = new Point(85, 10);
                btn.Width     = 75;
                btn.Height    = 20;
                btn.KeyDown  += new KeyEventHandler(OptionForm_KeyPress);
                OptionForm.Controls.Add(btn);

                btn.BringToFront();
            }
            TextBox tbMin = new TextBox();
            {
                Label l = new Label();
                l.Text      = "Minimum:";
                l.Width     = TextRenderer.MeasureText(l.Text, l.Font).Width;
                l.ForeColor = Color.White;
                l.Location  = new Point(15, 45);
                OptionForm.Controls.Add(l);

                tbMin.Location = new Point(85, 40);
                tbMin.Width    = 75;
                tbMin.Height   = 20;
                tbMin.Text     = fi.MinBrightness[fi.cValue].ToString();
                OptionForm.Controls.Add(tbMin);
                tbMin.BringToFront();
            }
            TextBox tbMax = new TextBox();
            {
                Label l = new Label();
                l.Text      = "Maximum:";
                l.Width     = TextRenderer.MeasureText(l.Text, l.Font).Width;
                l.ForeColor = Color.White;
                l.Location  = new Point(15, 75);
                OptionForm.Controls.Add(l);

                tbMax.Location = new Point(85, 70);
                tbMax.Width    = 75;
                tbMax.Height   = 20;
                tbMax.Text     = fi.MaxBrightness[fi.cValue].ToString();
                OptionForm.Controls.Add(tbMax);
                tbMax.BringToFront();
            }
            Button OkBtn = new Button();

            OptionForm.Tag  = OkBtn;
            OkBtn.Text      = "Apply";
            OkBtn.Width     = 80;
            OkBtn.BackColor = SystemColors.ButtonFace;
            OkBtn.Location  = new Point(50, 105);
            OptionForm.Controls.Add(OkBtn);
            OkBtn.Click += new EventHandler(delegate(object o, EventArgs a)
            {
                int min = 0;
                int max = 0;
                try { min = int.Parse(tbMin.Text); }
                catch
                {
                    MessageBox.Show("Incorrect minimum value!");
                    tbMin.Focus();
                    return;
                }

                if (min < 0)
                {
                    min = 0;
                }

                try { max = int.Parse(tbMax.Text); }
                catch
                {
                    MessageBox.Show("Incorrect maximum value!");
                    tbMax.Focus();
                    return;
                }
                if (max >= fi.histogramArray[fi.cValue].Length)
                {
                    max = fi.histogramArray[fi.cValue].Length - 1;
                    //IA.MarkAsNotSaved();
                }

                if (min > max)
                {
                    MessageBox.Show("Minimum must be lower then the maximum!");
                    return;
                }
                if (min != fi.MinBrightness[fi.cValue] | max != fi.MaxBrightness[fi.cValue])
                {
                    //turn of auto
                    if (autoDetect.Checked != false)
                    {
                        autoDetect.Checked = false;
                        fi.autoDetectBandC = false;
                        applyToAll.Visible = true;
                    }
                    //adjust brightness
                    MinPrew = fi.MinBrightness[fi.cValue];
                    MaxPrew = fi.MaxBrightness[fi.cValue];

                    adjustBrightness(min, max, fi, -1);

                    applyToHistory(fi.cValue, min, max);

                    //IA.MarkAsNotSaved();
                    //Load array to Chart
                    loadHistogramArray(fi);
                }
                OptionForm.Close();
            });
            OptionForm.ShowDialog();
            foreach (Button btn in fi.tpTaskbar.ColorBtnList)
            {
                btn.Focus();
            }
        }
コード例 #16
0
        private void FI_reduseC(TifFileInfo fi)
        {
            List <Color> l = new List <Color>();

            for (int i = 0; i < fi.sizeC; i++)
            {
                if (i < fi.LutList.Count)
                {
                    l.Add(fi.LutList[i]);
                }
                else
                {
                    l.Add(System.Drawing.Color.White);
                }
            }

            fi.LutList = l;

            fi.cValue = 0;

            #region Segmentation variables
            fi.histogramArray        = null;
            fi.adjustedLUT           = null;
            fi.MaxBrightness         = null;
            fi.MinBrightness         = null;
            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

            fi.tpTaskbar.AddColorBtn();
            fi.tpTaskbar.VisualizeColorBtns();
        }
コード例 #17
0
        private void Chart1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                TifFileInfo oldFI = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
                if (oldFI.histogramArray == null)
                {
                    return;
                }
                if (moveMin == true)
                {
                    //higher then max
                    int MineX = e.X;
                    int maxeX = Convert.ToInt32(Chart1.CA.ValueToPixelPosition(oldFI.MaxBrightness[oldFI.cValue]) - 1);
                    if (e.X > maxeX)
                    {
                        MineX = maxeX;
                    }
                    //lower then min
                    if (MineX < 0)
                    {
                        MineX = 0;
                    }
                    int newMin = Convert.ToInt32(Chart1.CA.PixelPositionToValue(MineX));
                    //calculate
                    if (newMin != oldFI.MinBrightness[oldFI.cValue] & newMin < oldFI.MaxBrightness[oldFI.cValue] & newMin >= 0)
                    {
                        if (autoDetect.Checked != false)
                        {
                            autoDetect.Checked    = false;
                            oldFI.autoDetectBandC = false;
                            applyToAll.Visible    = true;
                        }

                        oldFI.MinBrightness[oldFI.cValue] = newMin;

                        // IA.MarkAsNotSaved();
                        Chart1_MouseMoveImageReload();
                    }
                }
                else if (moveMax == true)
                {
                    //calculate abs max
                    int absMax = 254;

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

                    if (fi.bitsPerPixel != 8)
                    {
                        absMax = ushort.MaxValue;
                    }
                    //bigger then max
                    int maxeX = Convert.ToInt32(Chart1.CA.Width);
                    if (e.X < maxeX)
                    {
                        maxeX = e.X;
                    }
                    //lower then min
                    int mineX = Convert.ToInt32(Chart1.CA.ValueToPixelPosition(oldFI.MinBrightness[oldFI.cValue])) + 1;
                    if (e.X < mineX)
                    {
                        maxeX = mineX;
                    }
                    int newMax = Convert.ToInt32(Chart1.CA.PixelPositionToValue(maxeX));

                    //calculate max
                    if (newMax != oldFI.MaxBrightness[oldFI.cValue] & newMax > oldFI.MinBrightness[oldFI.cValue] & newMax <= absMax)
                    {
                        if (autoDetect.Checked != false)
                        {
                            autoDetect.Checked    = false;
                            oldFI.autoDetectBandC = false;
                            applyToAll.Visible    = true;
                        }

                        oldFI.MaxBrightness[oldFI.cValue] = newMax;

                        Chart1_MouseMoveImageReload();
                    }
                }
                else
                {
                    double min = Chart1.CA.ValueToPixelPosition(lastMin);
                    double max = Chart1.CA.ValueToPixelPosition(lastMax);
                    if ((e.X > min - 2 & e.X < min + 2) | (e.X > max - 2 & e.X < max + 2))
                    {
                        Chart1.Cursor = Cursors.SizeWE;
                    }
                    else
                    {
                        Chart1.Cursor = Cursors.Default;
                    }
                }
            }
            catch { }
        }
コード例 #18
0
        private void CellToolDKtoFI(CellToolDK.TifFileInfo fi, TifFileInfo oldFI)
        {
            if (fi == null)
            {
                oldFI = null;
                return;
            }

            TifFileInfo newFI = oldFI;

            newFI.zoom      = fi.zoom;
            newFI.Xposition = fi.Xposition;
            newFI.Yposition = fi.Yposition;
            //Chart
            newFI.xAxisTB = fi.xAxisTB;
            newFI.yAxisTB = fi.yAxisTB;

            //Tracking
            newFI.tracking_MaxSize = fi.tracking_MaxSize;
            newFI.tracking_MinSize = fi.tracking_MinSize;
            newFI.tracking_Speed   = fi.tracking_Speed;
            /// <summary>
            /// Segmentation
            /// </summary>
            //filter history
            newFI.FilterHistory = fi.FilterHistory;
            //controls
            newFI.DataSourceInd         = fi.DataSourceInd;
            newFI.SegmentationProtocol  = fi.SegmentationProtocol;
            newFI.SegmentationCBoxIndex = fi.SegmentationCBoxIndex;
            newFI.thresholdsCBoxIndex   = fi.thresholdsCBoxIndex;
            newFI.sumHistogramChecked   = fi.sumHistogramChecked;
            //spotdetector controls
            newFI.SpotThresh         = fi.SpotThresh;
            newFI.SpotColor          = fi.SpotColor;
            newFI.RefSpotColor       = fi.RefSpotColor;
            newFI.SelectedSpotThresh = fi.SelectedSpotThresh;
            newFI.typeSpotThresh     = fi.typeSpotThresh;
            newFI.SpotTailType       = fi.SpotTailType;
            newFI.spotSensitivity    = fi.spotSensitivity;
            //specific values
            newFI.thresholds         = fi.thresholds;
            newFI.thresholdValues    = fi.thresholdValues;
            newFI.thresholdColors    = fi.thresholdColors;
            newFI.RefThresholdColors = fi.RefThresholdColors;
            //BandC
            newFI.autoDetectBandC = fi.autoDetectBandC;
            newFI.applyToAllBandC = fi.applyToAllBandC;
            //
            newFI.selectedPictureBoxColumn = fi.selectedPictureBoxColumn;
            //History
            newFI.History      = fi.History;
            newFI.HistoryPlace = fi.HistoryPlace;
            newFI.undo         = fi.undo;
            newFI.redo         = fi.redo;
            newFI.delHist      = fi.delHist;
            //info var
            newFI.frame    = fi.frame;
            newFI.zValue   = fi.zValue;
            newFI.cValue   = fi.cValue;
            newFI.original = fi.original;
            //Not available
            newFI.loaded       = fi.loaded;
            newFI.available    = fi.available;
            newFI.selected     = fi.selected;
            newFI.openedImages = fi.openedImages;
            //tif image
            newFI.image8bit        = fi.image8bit;
            newFI.image16bit       = fi.image16bit;
            newFI.image8bitFilter  = fi.image8bitFilter;
            newFI.image16bitFilter = fi.image16bitFilter;
            //tif tags
            newFI.Dir                         = fi.Dir;
            newFI.seriesCount                 = fi.seriesCount;
            newFI.imageCount                  = fi.imageCount;
            newFI.sizeX                       = fi.sizeX;
            newFI.sizeY                       = fi.sizeY;
            newFI.sizeZ                       = fi.sizeZ;
            newFI.umZ                         = fi.umZ;
            newFI.umXY                        = fi.umXY;
            newFI.sizeC                       = fi.sizeC;
            newFI.sizeT                       = fi.sizeT;
            newFI.bitsPerPixel                = fi.bitsPerPixel;
            newFI.dimensionOrder              = fi.dimensionOrder;
            newFI.pixelType                   = fi.pixelType;
            newFI.FalseColored                = fi.FalseColored;
            newFI.isIndexed                   = fi.isIndexed;
            newFI.MetadataComplete            = fi.MetadataComplete;
            newFI.DatasetStructureDescription = fi.DatasetStructureDescription;
            newFI.LutList                     = fi.LutList;
            newFI.TimeSteps                   = fi.TimeSteps;
            newFI.Micropoint                  = fi.Micropoint;
            //Metadata protocol info
            newFI.FileDescription = fi.FileDescription;
            newFI.xCompensation   = fi.xCompensation;
            newFI.yCompensation   = fi.yCompensation;
            //properties
            newFI.histogramArray = fi.histogramArray;
            newFI.MinBrightness  = fi.MinBrightness;
            newFI.MaxBrightness  = fi.MaxBrightness;
            newFI.adjustedLUT    = fi.adjustedLUT;
            //RoiManager
            newFI.roiList = new List <ROI> [fi.roiList.Length];
            for (int c = 0; c < fi.roiList.Length; c++)
            {
                if (fi.roiList[c] != null)
                {
                    newFI.roiList[c] = new List <ROI>();
                    foreach (CellToolDK.ROI roi in fi.roiList[c])
                    {
                        ROI newROI = CellToolDKtoROI(roi);
                        newFI.roiList[c].Add(newROI);
                        RoiMeasure.Measure(newROI, newFI, c, IA);
                    }
                }
            }

            newFI.ROICounter = fi.ROICounter;
        }
コード例 #19
0
        public static string GetResults(TifFileInfo fi, int c)
        {
            string          val  = "";
            List <double[]> data = new List <double[]>();

            #region Calculate Original Data Set

            int ind, row, fromT, toT, fromZ, toZ,
                t, z, position, stack, boolStart;
            double[]      mainRoi;
            List <string> RoiNames = new List <string>()
            {
                "Time(s)"
            };
            List <string> Comments = new List <string>()
            {
                "Comments"
            };

            ROI roi;

            List <int> factorsT = new List <int>();
            List <int> factorsZ = new List <int>();

            if (data == null)
            {
                data = new List <double[]>();
            }

            if (fi.roiList[c] != null)
            {
                data.Clear();

                for (ind = 0; ind < fi.roiList[c].Count; ind++)
                {
                    roi = fi.roiList[c][ind];
                    if (roi.Results == null || roi.Checked == false)
                    {
                        continue;
                    }

                    fromT = roi.FromT;
                    toT   = roi.ToT;
                    fromZ = roi.FromZ;
                    toZ   = roi.ToZ;
                    //main roi part

                    t = 1;
                    z = 1;

                    if (true)
                    {
                        mainRoi = new double[roi.Results.Length];

                        for (row = c; row < roi.Results.Length; row += fi.sizeC)
                        {
                            if (roi.Results[row] != null &&
                                t >= fromT && t <= toT && z >= fromZ && z <= toZ)
                            {
                                if (fi.yAxisTB == 4)
                                {
                                    mainRoi[row] = roi.Results[row][0] * roi.Results[row][1];
                                }
                                else
                                {
                                    mainRoi[row] = roi.Results[row][fi.yAxisTB];
                                }
                            }
                            //apply change t and z

                            z++;
                            if (z > fi.sizeZ)
                            {
                                z = 1;
                                t++;
                                if (t > fi.sizeT)
                                {
                                    t = 1;
                                }
                            }
                        }
                        factorsT.Add(toT - fromT + 1);
                        factorsZ.Add(toZ - fromZ + 1);
                        data.Add(mainRoi);
                        RoiNames.Add(" Mean_ROI" + (ind + 1).ToString());
                        Comments.Add(roi.Comment);
                    }

                    //layers
                    if (roi.Stack == 0)
                    {
                        continue;
                    }

                    if (fi.yAxisTB > 4)
                    {
                        continue;
                    }
                    position = 4;

                    for (stack = 0; stack < roi.Stack; stack++)
                    {
                        t = 1;
                        z = 1;

                        mainRoi = new double[roi.Results.Length];

                        int factor = 0;
                        if (roi.Shape == 0 || roi.Shape == 1)
                        {
                            for (boolStart = 1 + stack * 4; boolStart < 5 + stack * 4; boolStart++, position += 4)
                            {
                                if (roi.ChartUseIndex[boolStart] == true)
                                {
                                    for (row = c; row < roi.Results.Length; row += fi.sizeC)
                                    {
                                        if (roi.Results[row] != null &&
                                            t >= fromT && t <= toT && z >= fromZ && z <= toZ)
                                        {
                                            if (fi.yAxisTB == 4)
                                            {
                                                mainRoi[row] += roi.Results[row][position] * roi.Results[row][position + 1];
                                            }
                                            else if (fi.yAxisTB < 2)
                                            {
                                                mainRoi[row] += roi.Results[row][position + fi.yAxisTB];
                                            }
                                            else if (fi.yAxisTB == 2 && (mainRoi[row] == 0 || mainRoi[row] > roi.Results[row][position + fi.yAxisTB]))
                                            {
                                                mainRoi[row] = roi.Results[row][position + fi.yAxisTB];
                                            }
                                            else if (fi.yAxisTB == 3 && mainRoi[row] < roi.Results[row][position + fi.yAxisTB])
                                            {
                                                mainRoi[row] = roi.Results[row][position + fi.yAxisTB];
                                            }
                                        }
                                        //apply change t and z

                                        z++;
                                        if (z > fi.sizeZ)
                                        {
                                            z = 1;
                                            t++;
                                            if (t > fi.sizeT)
                                            {
                                                t = 1;
                                            }
                                        }
                                    }

                                    factor++;
                                }
                            }
                        }
                        else
                        {
                            boolStart = 1 + stack * 4;

                            if (roi.ChartUseIndex[boolStart] == true)
                            {
                                for (row = c; row < roi.Results.Length; row += fi.sizeC)
                                {
                                    if (roi.Results[row] != null &&
                                        t >= fromT && t <= toT && z >= fromZ && z <= toZ)
                                    {
                                        if (fi.yAxisTB == 4)
                                        {
                                            mainRoi[row] = roi.Results[row][position] * roi.Results[row][position + 1];
                                        }
                                        else if (fi.yAxisTB < 2)
                                        {
                                            mainRoi[row] = roi.Results[row][position + fi.yAxisTB];
                                        }
                                        else if (fi.yAxisTB == 2)
                                        {
                                            mainRoi[row] = roi.Results[row][position + fi.yAxisTB];
                                        }
                                        else if (fi.yAxisTB == 3)
                                        {
                                            mainRoi[row] = roi.Results[row][position + fi.yAxisTB];
                                        }
                                    }
                                    //apply change t and z

                                    z++;
                                    if (z > fi.sizeZ)
                                    {
                                        z = 1;
                                        t++;
                                        if (t > fi.sizeT)
                                        {
                                            t = 1;
                                        }
                                    }
                                }

                                factor++;
                            }

                            position += 16;
                        }

                        if (fi.yAxisTB == 1)
                        {
                            for (int i = 0; i < mainRoi.Length; i++)
                            {
                                if (mainRoi[i] != 0)
                                {
                                    mainRoi[i] /= factor;
                                }
                            }
                        }

                        factorsT.Add(toT - fromT + 1);
                        factorsZ.Add(toZ - fromZ + 1);
                        data.Add(mainRoi);
                        RoiNames.Add(" Mean_ROI" + (ind + 1).ToString() + ".Layer" + (stack + 1).ToString());
                        Comments.Add(roi.Comment);
                    }
                }


                var XaxisData = new double[fi.imageCount];
                t = 1;
                z = 1;

                double time      = 0;
                int    timeIndex = 0;
                double timeT     = fi.TimeSteps[timeIndex];

                for (row = c; row < fi.imageCount; row += fi.sizeC)
                {
                    switch (fi.xAxisTB)
                    {
                    case 0:
                        //T slice
                        XaxisData[row] = t;
                        break;

                    case 1:
                        //T sec
                        XaxisData[row] = time;
                        break;

                    case 2:
                        //Z slice
                        XaxisData[row] = z;
                        break;

                    case 3:
                        //T sec
                        XaxisData[row] = time / 60;
                        break;

                    case 4:
                        //T sec
                        XaxisData[row] = time / 3600;
                        break;
                    }
                    //apply change t and z

                    z++;
                    if (z > fi.sizeZ)
                    {
                        z = 1;
                        t++;
                        if (t > fi.sizeT)
                        {
                            t = 1;
                        }

                        if (t <= timeT)
                        {
                            time += fi.TimeSteps[timeIndex + 1];
                        }
                        else
                        {
                            timeIndex += 2;

                            if (timeIndex < fi.TimeSteps.Count)
                            {
                                timeT += fi.TimeSteps[timeIndex];
                            }
                            else
                            {
                                timeIndex -= 2;
                                timeT     += fi.imageCount;
                            }

                            time += fi.TimeSteps[timeIndex + 1];
                        }
                    }
                }
                #endregion Calculate Original Data Set

                #region recalculate original data set
                if (fi.xAxisTB < 2 || fi.xAxisTB == 3 || fi.xAxisTB == 4)
                {
                    double[] res;
                    int      counter;

                    for (ind = 0; ind < data.Count; ind++)
                    {
                        res     = new double[fi.sizeT];
                        counter = 0;

                        t = 1;
                        z = 1;

                        for (row = c; row < fi.imageCount; row += fi.sizeC)
                        {
                            z++;
                            if (fi.yAxisTB < 2)
                            {
                                res[counter] += data[ind][row];
                            }
                            else if (fi.yAxisTB == 2 && (res[counter] > data[ind][row] || res[counter] == 0))
                            {
                                res[counter] = data[ind][row];
                            }
                            else if (fi.yAxisTB == 3 && res[counter] < data[ind][row])
                            {
                                res[counter] = data[ind][row];
                            }
                            else
                            {
                                res[counter] += data[ind][row];
                            }

                            if (z > fi.sizeZ)
                            {
                                z = 1;
                                t++;
                                if (fi.yAxisTB == 1)
                                {
                                    res[counter] /= factorsZ[ind];
                                }
                                counter++;
                            }
                        }

                        data[ind] = res;
                    }
                    //x axis
                    res     = new double[fi.sizeT];
                    counter = 0;
                    t       = 1;
                    z       = 1;

                    for (row = c; row < fi.imageCount; row += fi.sizeC)
                    {
                        z++;
                        if (z > fi.sizeZ)
                        {
                            z = 1;
                            t++;
                            res[counter] = XaxisData[row];
                            counter++;
                        }
                    }

                    XaxisData = res;
                }
                else if (fi.xAxisTB == 2)
                {
                    double[] res;
                    int      counter;

                    for (ind = 0; ind < data.Count; ind++)
                    {
                        res     = new double[fi.sizeZ];
                        counter = 0;

                        t = 1;
                        z = 1;

                        for (row = c; row < fi.imageCount; row += fi.sizeC)
                        {
                            z++;

                            if (fi.yAxisTB < 2)
                            {
                                res[counter] += data[ind][row];
                            }
                            else if (fi.yAxisTB == 2 && (res[counter] > data[ind][row] || res[counter] == 0))
                            {
                                res[counter] = data[ind][row];
                            }
                            else if (fi.yAxisTB == 3 && res[counter] < data[ind][row])
                            {
                                res[counter] = data[ind][row];
                            }
                            else
                            {
                                res[counter] += data[ind][row];
                            }

                            counter++;

                            if (z > fi.sizeZ)
                            {
                                z       = 1;
                                counter = 0;
                                t++;
                            }
                        }
                        //popravi tuk s faktor list w gornata chast
                        if (fi.yAxisTB == 1)
                        {
                            for (int i = 0; i < res.Length; i++)
                            {
                                res[i] /= factorsT[ind];
                            }
                        }

                        data[ind] = res;
                    }

                    //x axis
                    res     = new double[fi.sizeZ];
                    counter = 0;
                    t       = 1;
                    z       = 1;

                    for (row = c; row < fi.imageCount; row += fi.sizeC)
                    {
                        res[counter] = XaxisData[row];
                        counter++;

                        z++;
                        if (z > fi.sizeZ)
                        {
                            break;
                        }
                    }

                    XaxisData = res;
                }
                #endregion recalculate original data set
                //System.IO.File.WriteAllText(fi.Dir.Replace(".tif", "_c" + c + ".text"),MeargeResult());
                #region Prepare string
                string[] resList = new string[XaxisData.Length + 3];
                //system description row
                string[] temp = new string[RoiNames.Count];
                temp[0]    = "CTResults:  Mean";
                temp[1]    = fi.Dir;
                resList[0] = string.Join("\t", temp);
                temp       = null;
                //comments
                resList[1] = string.Join("\t", Comments);
                Comments   = null;
                //titles
                resList[2] = string.Join("\t", RoiNames);
                RoiNames   = null;
                for (int i = 0; i < XaxisData.Length; i++)
                {
                    val = XaxisData[i].ToString();
                    foreach (double[] dList in data)
                    {
                        val += "\t" + dList[i];
                    }
                    resList[i + 3] = val;
                }
                XaxisData = null;
                data      = null;

                val     = string.Join("\n", resList);
                resList = null;
                #endregion Prepare string
            }

            return(val);
        }
コード例 #20
0
        private void ErrorCheck(object sender, EventArgs e)
        {
            TifFileInfo fi = null;

            try
            {
                fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;
            }
            catch { }
            if (fi == null)
            {
                MessageBox.Show("There is no opened image!");
                return;
            }

            if (fi.loaded == false)
            {
                return;
            }
            if (fi.roiList == null)
            {
                return;
            }
            if (nameCBox.Items.Count == 0)
            {
                return;
            }
            try
            {
                int           c, ind;
                ROI           roi;
                List <string> res = new List <string>();

                IA.chart.Properties.Ncalc.LoadFunction(fi, nameCBox.SelectedIndex);

                for (c = 0; c < fi.sizeC; c++)
                {
                    if (fi.tpTaskbar.ColorBtnList[c].ImageIndex == 0 && fi.roiList[c] != null)
                    {
                        for (ind = 0; ind < fi.roiList[c].Count; ind++)
                        {
                            roi = fi.roiList[c][ind];
                            if (roi.Results == null || roi.Checked == false)
                            {
                                continue;
                            }

                            if (roi.ChartUseIndex[0] == true)
                            {
                                string val = IA.chart.Properties.Ncalc.ErrorCheck(c, roi, fi.roiList[c], fi);
                                if (val != "")
                                {
                                    res.Add(val);
                                }
                            }
                        }
                    }
                }
                res.Add("Check finished!");
                MessageBox.Show(string.Join("\n", res));
            }
            catch (Exception)
            {
                throw;
            }
        }