private void CalculateCurvePoints(ref EcgModel model)
        {
            Bitmap bitmap = model.Curve;

            model.CalculatedCurve = new Bitmap(bitmap.Width, bitmap.Height);

            for (int x = 0; x < bitmap.Width; x++)
            {
                bool foundAPoint = false;
                for (int y = 0; y < bitmap.Width; y++)
                {
                    if (bitmap.GetPixel(x, y).ToArgb() == Color.Black.ToArgb())
                    {
                        model.CurvePoints[x] = y;

                        // If line was vertical we need to "complete" it
                        if (x > 0)
                        {
                            int previousY = model.CurvePoints[x - 1];
                            int currentY  = model.CurvePoints[x];
                            if (previousY > 0 && currentY > 0)
                            {
                                for (int gapY = Math.Min(previousY, currentY); gapY < Math.Max(previousY, currentY); gapY++)
                                {
                                    model.CalculatedCurve.SetPixel(x, gapY, Color.Green);
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
        private void CalculateTimeInterval(ref EcgModel ecgModel)
        {
            int SearchingIndex = 0;

            Bitmap meshBitmap = ecgModel.MeshBitmap;

            while (ecgModel.YInterval < 0)
            {
                SearchingIndex += 20;
                for (var y = 0; y < meshBitmap.Height; y++)
                {
                    Color pixelColor = meshBitmap.GetPixel(SearchingIndex, y);
                    if (pixelColor.ToArgb() == Color.Black.ToArgb())
                    {
                        if (ecgModel.YInterval == -1)
                        {
                            ecgModel.YInterval = y;
                            ecgModel.YStart    = y;
                        }
                        else
                        {
                            ecgModel.YInterval = y - ecgModel.YInterval;
                            break;
                        }
                    }
                }
            }

            // Calculate X intervals (Columns)
            SearchingIndex = 20;
            while (ecgModel.XInterval < 0)
            {
                SearchingIndex += 20;
                for (var x = 0; x < meshBitmap.Width; x++)
                {
                    Color pixelColor = meshBitmap.GetPixel(x, SearchingIndex);
                    if (pixelColor.ToArgb() == Color.Black.ToArgb())
                    {
                        if (ecgModel.XInterval == -1)
                        {
                            ecgModel.XInterval = x;
                            ecgModel.XStart    = x;
                            x += 5; //Skipping some lines in case the mesh is too width
                        }
                        else
                        {
                            ecgModel.XInterval = x - ecgModel.XInterval;
                            return;
                        }
                    }
                }
            }
            throw new Exception("Could not figure out the mesh");
        }
        private EcgModel InitializeEcgModel(Bitmap original)
        {
            EcgModel model = new EcgModel();

            model.YStart         = -1;
            model.YInterval      = -1;
            model.XStart         = -1;
            model.XInterval      = -1;
            model.OriginalBitmap = new Bitmap(original);
            model.CurvePoints    = new int[original.Width];
            return(model);
        }
        public EcgModel ProcessEcg()
        {
            Bitmap bitmap = new Bitmap(@"C:\Users\crgar\Desktop\ECG3.bmp");

            EcgModel model = InitializeEcgModel(bitmap);

            model.Curve      = GetEcgData(bitmap);
            model.MeshBitmap = CreateCleanMeshBitmap(bitmap);
            CalculateTimeInterval(ref model);
            CalculateCurvePoints(ref model);
            CreateBitmapsBasedOnIntervals(ref model);
            return(model);
        }
Beispiel #5
0
        private void Button1_Click(object sender, EventArgs e)
        {
            PictureBox[] pics = { picOriginal, picMeshWithModelLines };
            processor         = new EcgProcessor();
            model             = processor.ProcessEcg();
            trackBar1.Minimum = 5;
            trackBar1.Maximum = 3 * model.YInterval;
            trackBar1.Value   = model.YInterval;
            trackBar1.Enabled = true;

            trackBarX.Minimum = 5;
            trackBarX.Maximum = 3 * model.XInterval;
            trackBarX.Value   = model.XInterval;
            trackBarX.Enabled = true;

            PrintModel();
        }
        private Bitmap CreateIntervalLinesOnTopOfBaseImage(EcgModel model, Bitmap baseImage)
        {
            var bitmap = new Bitmap(baseImage);

            for (var y = model.YStart; y < bitmap.Height; y += model.YInterval)
            {
                for (var x = 0; x < bitmap.Width; x++)
                {
                    bitmap.SetPixel(x, y, Color.Blue);
                }
            }

            for (var x = model.XStart; x < bitmap.Width; x += model.XInterval)
            {
                for (var y = 0; y < bitmap.Height; y++)
                {
                    bitmap.SetPixel(x, y, Color.Blue);
                }
            }

            return(bitmap);
        }
 private void CreateCurveWithIntervalLines(ref EcgModel model)
 {
     model.CurveWithModelLines = CreateIntervalLinesOnTopOfBaseImage(model, model.Curve);
 }
 public void CreateBitmapsBasedOnIntervals(ref EcgModel model)
 {
     model.MeshWithModelLines      = CreateIntervalLinesOnTopOfBaseImage(model, model.MeshBitmap);
     model.CalculatedCurveWithMesh = CreateIntervalLinesOnTopOfBaseImage(model, model.CalculatedCurve);
     CreateCurveWithIntervalLines(ref model);
 }