Exemple #1
0
        private void DoMeasurements(object state)
        {
            try
            {
                m_SigmaDict = new Dictionary <int, double>();

                Rectangle testRect = new Rectangle(
                    (m_ImageProvider.Width / 2) - 16,
                    (m_ImageProvider.Height / 2) - 16,
                    32, 32);

                int framesToMeasure = 65;

                int firstFrame = Math.Max(0, StartFrameId);
                int lastFrame  = Math.Min(m_ImageProvider.LastFrame, StartFrameId + framesToMeasure);

                RaiseOnBeginProgress(firstFrame, lastFrame - 1);

                int[,] pixels1 = null;
                int[,] pixels2 = null;

                for (int i = firstFrame; i < lastFrame - 1; i++)
                {
                    m_SigmaDict.Add(i, double.NaN);
                }

                PotentialIntegrationFit foundIntegration = null;

                for (int k = 0; k < 4; k++)
                {
                    if (!m_IsRunning)
                    {
                        break;
                    }

                    for (int i = firstFrame; i < lastFrame - 1; i++)
                    {
                        if (!m_IsRunning)
                        {
                            break;
                        }

                        RaiseOnProgress(i);

                        List <AverageCalculator> calcList = new List <AverageCalculator>();

                        for (int x = 0; x < 32; x++)
                        {
                            for (int y = 0; y < 32; y++)
                            {
                                calcList.Add(new AverageCalculator());
                            }
                        }

                        if (pixels1 == null)
                        {
                            pixels1 = m_ImageProvider.GetPixelArray(i, testRect);
                            RaiseOnFramePixels(i, pixels1);
                        }
                        else
                        {
                            for (int x = 0; x < 32; x++)
                            {
                                for (int y = 0; y < 32; y++)
                                {
                                    pixels1[x, y] = pixels2[x, y];
                                }
                            }
                        }

                        pixels2 = m_ImageProvider.GetPixelArray(i + 1, testRect);
                        RaiseOnFramePixels(i + 1, pixels1);

                        double sigmaSum = 0;
                        for (int x = 0; x < 32; x++)
                        {
                            for (int y = 0; y < 32; y++)
                            {
                                int value  = pixels1[x, y];
                                int value2 = pixels2[x, y];

                                calcList[32 * y + x].AddDataPoint(value);
                                calcList[32 * y + x].AddDataPoint(value2);

                                sigmaSum += Math.Abs(value - value2) / 2.0;
                            }
                        }

                        calcList.ForEach(c => c.Compute());
                        m_SigmaDict[i] = sigmaSum / 1024;

                        RaiseOnFrameData(calcList, m_SigmaDict);

                        m_AverageCalculatorsPerFrame.Add(calcList);
                    }

                    foundIntegration = ComputeIntegration();

                    if (foundIntegration != null)
                    {
                        if (k == 0)
                        {
                            if (foundIntegration.Interval < 32 && foundIntegration.Certainty > 1)
                            {
                                break;
                            }
                        }
                        else if (k == 1)
                        {
                            if (foundIntegration.Interval < 64 && foundIntegration.Certainty > 1)
                            {
                                break;
                            }
                        }
                        else if (k == 2)
                        {
                            if (foundIntegration.Interval < 128 && foundIntegration.Certainty > 1)
                            {
                                break;
                            }
                        }
                    }

                    if (k < 3)
                    {
                        if (k < 2)
                        {
                            framesToMeasure += 65;
                        }
                        else
                        {
                            framesToMeasure += 129;
                        }

                        firstFrame = lastFrame - 1;
                        lastFrame  = Math.Min(m_ImageProvider.LastFrame, StartFrameId + framesToMeasure);

                        RaiseOnProgress(lastFrame - 1);

                        int currSize = m_SigmaDict.Count;
                        for (int i = currSize + StartFrameId; i < lastFrame - 1; i++)
                        {
                            m_SigmaDict.Add(i, double.NaN);
                        }
                    }
                }

                if (m_IsRunning)
                {
                    RaiseOnPotentialIntegration(foundIntegration);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.GetFullStackTrace());
            }
            finally
            {
                m_IsRunning = false;
            }
        }
Exemple #2
0
        private void DoMeasurements()
        {
            m_SigmaDict = new Dictionary <int, double>();

            Rectangle testRect = new Rectangle(
                (m_ImageProvider.Width / 2) - 16,
                (m_ImageProvider.Height / 2) - 16,
                32, 32);

            int framesToMeasure = 65;

            int firstFrame = m_StartFrameId;
            int lastFrame  = Math.Min(m_ImageProvider.LastFrame, m_StartFrameId + framesToMeasure);

            progressBar1.Minimum = firstFrame;
            progressBar1.Maximum = lastFrame - 1;
            progressBar1.Style   = ProgressBarStyle.Marquee;

            int[,] pixels1 = null;
            int[,] pixels2 = null;

            for (int i = firstFrame; i < lastFrame - 1; i++)
            {
                m_SigmaDict.Add(i, double.NaN);
            }

            PotentialIntegrationFit foundIntegration = null;

            for (int k = 0; k < 4; k++)
            {
                for (int i = firstFrame; i < lastFrame - 1; i++)
                {
                    progressBar1.Value = i;
                    progressBar1.Refresh();

                    List <AverageCalculator> calcList = new List <AverageCalculator>();

                    for (int x = 0; x < 32; x++)
                    {
                        for (int y = 0; y < 32; y++)
                        {
                            calcList.Add(new AverageCalculator());
                        }
                    }

                    if (pixels1 == null)
                    {
                        pixels1 = m_ImageProvider.GetPixelArray(i, testRect);
                    }
                    else
                    {
                        for (int x = 0; x < 32; x++)
                        {
                            for (int y = 0; y < 32; y++)
                            {
                                pixels1[x, y] = pixels2[x, y];
                            }
                        }
                    }

                    pixels2 = m_ImageProvider.GetPixelArray(i + 1, testRect);

                    double sigmaSum = 0;
                    for (int x = 0; x < 32; x++)
                    {
                        for (int y = 0; y < 32; y++)
                        {
                            int value  = pixels1[x, y];
                            int value2 = pixels2[x, y];

                            calcList[32 * y + x].AddDataPoint(value);
                            calcList[32 * y + x].AddDataPoint(value2);

                            sigmaSum += Math.Abs(value - value2) / 2.0;
                        }
                    }

                    calcList.ForEach(c => c.Compute());
                    m_SigmaDict[i] = sigmaSum / 1024;

                    Plot(calcList);
                    PlotSigmas(m_SigmaDict);

                    Refresh();

                    m_AverageCalculatorsPerFrame.Add(calcList);
                }

                foundIntegration = ComputeIntegration();

                if (foundIntegration != null)
                {
                    if (k == 0)
                    {
                        if (foundIntegration.Interval < 32 && foundIntegration.Certainty > 1)
                        {
                            break;
                        }
                    }
                    else if (k == 1)
                    {
                        if (foundIntegration.Interval < 64 && foundIntegration.Certainty > 1)
                        {
                            break;
                        }
                    }
                    else if (k == 2)
                    {
                        if (foundIntegration.Interval < 128 && foundIntegration.Certainty > 1)
                        {
                            break;
                        }
                    }
                }

                if (k < 3)
                {
                    if (k < 2)
                    {
                        framesToMeasure += 65;
                    }
                    else
                    {
                        framesToMeasure += 129;
                    }

                    firstFrame = lastFrame - 1;
                    lastFrame  = Math.Min(m_ImageProvider.LastFrame, m_StartFrameId + framesToMeasure);

                    progressBar1.Maximum = lastFrame - 1;

                    int currSize = m_SigmaDict.Count;
                    for (int i = currSize + m_StartFrameId; i < lastFrame - 1; i++)
                    {
                        m_SigmaDict.Add(i, double.NaN);
                    }
                }
            }

            progressBar1.Value = progressBar1.Maximum;
            progressBar1.Style = ProgressBarStyle.Continuous;
            progressBar1.Refresh();

            pnlResult.Visible = true;
            pnlResult.BringToFront();


            DisplayFoundIntegration(foundIntegration);
        }