Ejemplo n.º 1
0
        private void button_SaveResults_Click(object sender, EventArgs e)
        {
            try
            {
                //get names
                string str  = "";
                string dir  = fi.Dir;
                string name = "(1)";
                dir  = dir.Substring(0, dir.LastIndexOf("."));
                name = dir.Substring(dir.LastIndexOf("\\") + 1, dir.Length - dir.LastIndexOf("\\") - 1);

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //export settings
                str  = "File:\t" + dir;
                str += "\nCh1:\t" + imgDrawer.colIndexes[0];
                str += "\nCh2:\t" + imgDrawer.colIndexes[1];
                str += "\nLock frames:\t" + checkBox_LockFrames.Checked;
                str += "\nTime Frame Ch1:\t" + trackBar_TimeCh1.Value;
                str += "\nTime Frame Ch2:\t" + trackBar_TimeCh2.Value;
                str += "\nUse thresholds:\t" + checkBox_UseBinary.Checked;
                str += "\nThreshold Ch1:\t" + trackBar_ThreshCh1.Value;
                str += "\nThreshold Ch2:\t" + trackBar_ThreshCh2.Value;
                str += "\nUse ROIs:\t" + checkBox_UseROIs.Checked;
                str += "\n\nResults:\n";

                //export dataTable
                using (StreamWriter write = new StreamWriter(File.Create(dir + @"\" + name + "_DataTable.txt")))
                {
                    int row  = dataGridView1.Rows.Count;
                    int cell = dataGridView1.Rows[1].Cells.Count;

                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        str += dataGridView1.Columns[i].Name + "\t";
                    }

                    write.WriteLine(str);

                    for (int i = 0; i < row; i++)
                    {
                        str = "";
                        for (int j = 0; j < cell; j++)
                        {
                            if (dataGridView1.Rows[i].Cells[j].Value == null)
                            {
                                dataGridView1.Rows[i].Cells[j].Value = "null";
                            }
                            str += dataGridView1.Rows[i].Cells[j].Value.ToString() + "\t";
                        }
                        write.WriteLine(str);
                    }

                    write.Close();
                    write.Dispose();
                }
                //Export plots
                Point[]      values     = null;
                List <Point> points     = new List <Point>();
                List <Point> pointsFilt = new List <Point>();
                List <Point> valuesFilt = new List <Point>();

                Cell_Tool_3.FrameCalculator frameCalc = new Cell_Tool_3.FrameCalculator();

                int[] curFrames = new int[2];
                fi.frame = imgDrawer.frames[0];
                int roiFrame = frameCalc.FrameC(fi, 0);
                curFrames[0] = frameCalc.FrameC(fi, imgDrawer.colIndexes[0]);
                fi.frame     = imgDrawer.frames[1];
                curFrames[1] = frameCalc.FrameC(fi, imgDrawer.colIndexes[1]);

                {
                    //Whole image
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        values = Operations.PairImages(fi.image8bit[curFrames[0]], fi.image8bit[curFrames[1]]);
                        break;

                    case 16:
                        values = Operations.PairImages(fi.image16bit[curFrames[0]], fi.image16bit[curFrames[1]]);
                        break;
                    }

                    for (int y = 0, i = 0; y < fi.sizeY; y++)
                    {
                        for (int x = 0; x < fi.sizeX; x++, i++)
                        {
                            points.Add(new Point(x, y));
                            if (values[i].X >= imgDrawer.thresholds[0] || values[i].Y >= imgDrawer.thresholds[1])
                            {
                                pointsFilt.Add(points[i]);
                                valuesFilt.Add(values[i]);
                            }
                        }
                    }

                    ExportScaterPlot(dir, name + "_All", values, points.ToArray());
                    if (checkBox_UseBinary.Checked)
                    {
                        ExportScaterPlot(dir, name + "_All_noBG", valuesFilt.ToArray(), pointsFilt.ToArray());
                    }

                    points.Clear();
                    pointsFilt.Clear();
                    valuesFilt.Clear();
                }
                if (checkBox_UseROIs.Checked && fi.roiList != null && fi.roiList.Length > 0 && fi.roiList[0] != null)
                {
                    for (int n = 0; n < fi.roiList[0].Count; n++)
                    {
                        ROI roi = fi.roiList[0][n];
                        points = ROIManager.GetROIPoints(roiFrame, roi, fi);
                        points = CheckArePointsInTheImage(points.ToArray(), fi.sizeX, fi.sizeY).ToList();
                        //Whole image
                        switch (fi.bitsPerPixel)
                        {
                        case 8:
                            values = Operations.PairImages(fi.image8bit[curFrames[0]], fi.image8bit[curFrames[1]], points.ToArray());
                            break;

                        case 16:
                            values = Operations.PairImages(fi.image16bit[curFrames[0]], fi.image16bit[curFrames[1]], points.ToArray());
                            break;
                        }

                        for (int i = 0; i < points.Count; i++)
                        {
                            if (values[i].X >= imgDrawer.thresholds[0] || values[i].Y >= imgDrawer.thresholds[1])
                            {
                                pointsFilt.Add(points[i]);
                                valuesFilt.Add(values[i]);
                            }
                        }

                        ExportScaterPlot(dir, name + "_ROI" + (n + 1), values, points.ToArray());
                        if (checkBox_UseBinary.Checked)
                        {
                            ExportScaterPlot(dir, name + "_ROI" + (n + 1) + "_noBG", valuesFilt.ToArray(), pointsFilt.ToArray());
                        }

                        points.Clear();
                        pointsFilt.Clear();
                        valuesFilt.Clear();
                    }
                }
                //exit
                MessageBox.Show("Files saved!");
            }
            catch
            {
                MessageBox.Show("Error: Files NOT saved!");
            }
        }
Ejemplo n.º 2
0
        private void GetStatisticsROIs()
        {
            if (imgDrawer == null || imgDrawer.frames == null || fi == null)
            {
                return;
            }
            //Generate data table
            DataTable tbl = new DataTable();

            tbl.Columns.Add(new DataColumn("Coefficient", typeof(string)));

            DataRow row = tbl.NewRow();

            row["Coefficient"] = "PCC";

            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["Coefficient"] = "Rsquared";
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["Coefficient"] = "MOC";
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["Coefficient"] = "MCC 1";
            tbl.Rows.Add(row);
            row = tbl.NewRow();
            row["Coefficient"] = "MCC 2";
            tbl.Rows.Add(row);

            //Points list
            Point[] points = null;
            ROI     roi    = null;

            Cell_Tool_3.FrameCalculator frameCalc = new Cell_Tool_3.FrameCalculator();
            int[] curFrames = new int[2];

            fi.frame = imgDrawer.frames[0];
            int roiFrame = frameCalc.FrameC(fi, 0);

            curFrames[0] = frameCalc.FrameC(fi, imgDrawer.colIndexes[0]);
            fi.frame     = imgDrawer.frames[1];
            curFrames[1] = frameCalc.FrameC(fi, imgDrawer.colIndexes[1]);

            if (fi.roiList != null && fi.roiList.Length > 0 && fi.roiList[0] != null)
            {
                for (int i = 0; i < fi.roiList[0].Count; i++)
                {
                    roi    = fi.roiList[0][i];
                    points = ROIManager.GetROIPoints(roiFrame, roi, fi).ToArray();
                    if (points == null || points.Length < 2)
                    {
                        return;
                    }

                    points = CheckArePointsInTheImage(points, fi.sizeX, fi.sizeY);
                    if (points == null || points.Length < 2)
                    {
                        return;
                    }

                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        points = Operations.PairImages(fi.image8bit[curFrames[0]], fi.image8bit[curFrames[1]], points);
                        break;

                    case 16:
                        points = Operations.PairImages(fi.image16bit[curFrames[0]], fi.image16bit[curFrames[1]], points);
                        break;
                    }

                    if (points == null || points.Length < 2)
                    {
                        return;
                    }

                    double[] MCC = null;
                    //Filter By thresholds
                    if (imgDrawer.showBinary)
                    {
                        points = Operations.FilterPointsByThresholds(points, imgDrawer.thresholds[0], imgDrawer.thresholds[1]);
                        // MessageBox.Show(points.Length.ToString());
                        MCC = Operations.MCC(points, imgDrawer.thresholds[0], imgDrawer.thresholds[1]);
                    }
                    else
                    {
                        MCC = Operations.MCC(points, 1, 1);
                    }

                    //processing
                    double PCC     = Operations.PCC(points);
                    double Rsquare = Math.Pow(PCC, 2.0);
                    double MOC     = Operations.MOC(points);

                    tbl.Columns.Add(new DataColumn("ROI " + (i + 1), typeof(double)));

                    row = tbl.Rows[0];
                    row["ROI " + (i + 1)] = PCC;
                    row = tbl.Rows[1];
                    row["ROI " + (i + 1)] = Rsquare;
                    row = tbl.Rows[2];
                    row["ROI " + (i + 1)] = MOC;
                    row = tbl.Rows[3];
                    row["ROI " + (i + 1)] = MCC[0];
                    row = tbl.Rows[4];
                    row["ROI " + (i + 1)] = MCC[1];
                }
            }

            dataGridView1.DataSource = tbl;
        }