예제 #1
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;
        }
예제 #2
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;
        }