private ZArrayDescriptor GenerateWedge(int mValue, int width, int imageHeight, int imageWidth, double?mRatio = null)
        {
            ZArrayDescriptor arrayDescriptor = new ZArrayDescriptor(imageWidth + BLACK_SIDE_WIDTH, imageHeight);

            double maxIntensity = WEDGE_MAX_INTENSITY_VALUE;

            if (mRatio.HasValue)
            {
                maxIntensity = mRatio.Value * (WEDGE_MAX_INTENSITY_VALUE - WEDGE_MIN_INTENSITY_VALUE) + WEDGE_MIN_INTENSITY_VALUE;
            }

            Interval <double> interval1 = new Interval <double>(0, mValue - 1);
            Interval <double> interval2 = new Interval <double>(WEDGE_MIN_INTENSITY_VALUE, maxIntensity);

            RealIntervalTransform intervalTransform = new RealIntervalTransform(interval1, interval2);

            int[] array        = new int[width];
            int   currentValue = 0;

            //Create wedge 0..m
            for (int j = 0; j < width; j++)
            {
                if (currentValue >= mValue - 1)
                {
                    currentValue = 0;
                }
                array[j] = currentValue;
                currentValue++;
            }

            CorrectBr correctBr = new CorrectBr();

            double[] interpolatedClin = correctBr.InterpolateClin(clin);

            int qq = Convert.ToInt32(maxIntensity);

            //Stretch wedge to image width
            int k = imageWidth / (array.Length) + 1;

            for (int x = 0; x < imageWidth - 1; x++)
            {
                int i = x / k;
                for (int y = 0; y < imageHeight - 1; y++)
                {
                    double value = intervalTransform.TransformToFinishIntervalValue(array[i]);
                    //double correctedValue = CorrectBr.CorrectValueByClin(value, interpolatedClin, qq);
                    double correctedValue = value;
                    arrayDescriptor.array[x, y] = correctedValue;
                }
            }

            return(arrayDescriptor);
        }
        private void CalcWedgeIntensityDistribution()
        {
            ZArrayDescriptor arrayDescriptor1 = Form1.zArrayDescriptor[0];
            ZArrayDescriptor arrayDescriptor2 = Form1.zArrayDescriptor[1];

            Interval <double> intervalInt = new Interval <double>(0, 225);
            Interval <double> intervalM1  = new Interval <double>(0, WEDGE_M1);
            Interval <double> intervalM2  = new Interval <double>(0, WEDGE_M2);

            RealIntervalTransform intervalTransformM1 = new RealIntervalTransform(intervalInt, intervalM1);
            RealIntervalTransform intervalTransformM2 = new RealIntervalTransform(intervalInt, intervalM2);

            int width = arrayDescriptor1.width;

            int startY = 0;
            int height = 2;

            List <Point2D> pointsList = new List <Point2D>();

            for (int x = 0; x < width - 1; x++)
            {
                for (int y = startY; y < height - 1; y++)
                {
                    double intensity1 = arrayDescriptor1.array[x, y];
                    double intensity2 = arrayDescriptor2.array[x, y];

                    intensity1 = intervalTransformM1.TransformToFinishIntervalValue(intensity1);
                    intensity2 = intervalTransformM2.TransformToFinishIntervalValue(intensity2);

                    int b1 = Convert.ToInt32(intensity1);
                    int b2 = Convert.ToInt32(intensity2);

                    pointsList.Add(new Point2D(b1, b2));
                }
            }

            RangeExtensionModelForm decisionTableForm = new RangeExtensionModelForm();

            IList <Point2D> decisionTablePointsList = decisionTableForm.BuildTable(WEDGE_M1, WEDGE_M2, WEDGE_WIDTH);

            GraphInfo idealGraphInfo =
                new GraphInfo("Ideal graph", System.Windows.Media.Colors.Green, decisionTablePointsList.ToArray(), true, false);

            GraphInfo         graph           = new GraphInfo("Graphic", System.Windows.Media.Colors.Red, pointsList.ToArray(), false, true);
            IList <GraphInfo> graphCollection = new List <GraphInfo>()
            {
                idealGraphInfo, graph
            };

            ShowGraphic(graphCollection);
        }
Beispiel #3
0
        private void btnIntensityIncrease_Click(object sender, EventArgs e)
        {
            int    count = 1000;
            double step  = GetStep();

            List <double> valuesList = new List <double>();

            double x = 0;

            for (int k = 0; k < count; k++)
            {
                double value = Math.Cos(x);
                valuesList.Add(value);
                x += step;
            }

            List <ChartPoint> points = new List <ChartPoint>();

            for (int k = 0; k < count; k++)
            {
                ChartPoint p = new ChartPoint(k, valuesList[k]);
                points.Add(p);
            }

            Chart chart1 = new Chart()
            {
                SeriesCollection = new List <ChartSeries>()
                {
                    new ChartSeries()
                    {
                        Name            = "Graph",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                        ColorDescriptor = new ColorDescriptor(255, 0, 0),
                        Points          = points
                    }
                }
            };

            MemoryWriter.Write <Chart>(chart1, new ChartSerialization());
            ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

            Thread.Sleep(2000);

            Interval <double>     startInterval  = new Interval <double>(-1, 1);
            Interval <double>     finishInterval = new Interval <double>(0, MAX_RANGE_VALUE);
            RealIntervalTransform transform      = new RealIntervalTransform(startInterval, finishInterval);
            List <ChartPoint>     points2        = new List <ChartPoint>();

            for (int k = 0; k < count; k++)
            {
                double     newValue = transform.TransformToFinishIntervalValue(valuesList[k]);
                ChartPoint p        = new ChartPoint(k, newValue);
                points2.Add(p);
            }

            List <ChartPoint> points3 = new List <ChartPoint>();

            for (int k = 0; k < points2.Count; k++)
            {
                ChartPoint p        = points2[k];
                double     v        = p.Y % M1;
                ChartPoint newPoint = new ChartPoint(p.X, v);
                points3.Add(newPoint);
            }

            List <ChartPoint> points4 = new List <ChartPoint>();

            for (int k = 0; k < points2.Count; k++)
            {
                ChartPoint p        = points2[k];
                double     v        = p.Y % M2;
                ChartPoint newPoint = new ChartPoint(p.X, v);
                points4.Add(newPoint);
            }

            Chart chart2 = new Chart()
            {
                SeriesCollection = new List <ChartSeries>()
                {
                    new ChartSeries()
                    {
                        Name            = "Graph",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                        ColorDescriptor = new ColorDescriptor(0, 0, 0),
                        Points          = points2
                    },
                    new ChartSeries()
                    {
                        Name            = "M1",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                        ColorDescriptor = new ColorDescriptor(0, 255, 0),
                        Points          = points3
                    },
                    new ChartSeries()
                    {
                        Name            = "M2",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                        ColorDescriptor = new ColorDescriptor(255, 0, 0),
                        Points          = points4
                    }
                }
            };

            MemoryWriter.Write <Chart>(chart2, new ChartSerialization());
            ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

            Thread.Sleep(2000);

            List <ChartPoint> points5 = new List <ChartPoint>();

            for (int k = 0; k < points3.Count; k++)
            {
                ChartPoint m1Point = points3[k];
                ChartPoint m2Point = points4[k];

                ChartPoint point = new ChartPoint(m1Point.Y, m2Point.Y);
                //ChartPoint point = new ChartPoint(m1Point.Y - M1, M2 - m2Point.Y);
                points5.Add(point);
            }

            List <Point2D> pointsDiagonal = ModularArithmeticHelper.BuildTable(M1, M2, MAX_RANGE_VALUE);

            List <ChartPoint> points6 = new List <ChartPoint>();

            for (int k = 0; k < pointsDiagonal.Count; k++)
            {
                Point2D    p  = pointsDiagonal[k];
                ChartPoint p1 = new ChartPoint(p.X, p.Y);
                //ChartPoint p1 = new ChartPoint(p.X - M1, M2 - p.Y);
                points6.Add(p1);
            }

            Chart chart5 = new Chart()
            {
                //InvertAxisX = true,
                //InvertAxisY = true,
                SeriesCollection = new List <ChartSeries>()
                {
                    new ChartSeries()
                    {
                        Name            = "Diagonal",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                        ColorDescriptor = new ColorDescriptor(0, 255, 0),
                        Points          = points6
                    },

                    new ChartSeries()
                    {
                        Name            = "Points",
                        Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Bubble,
                        ColorDescriptor = new ColorDescriptor(0, 0, 0),
                        Points          = points5
                    }
                }
            };

            MemoryWriter.Write <Chart>(chart5, new ChartSerialization());
            ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

            Thread.Sleep(2000);
        }
Beispiel #4
0
        private void btnGraphFromImages_Click(object sender, EventArgs e)
        {
            string directoryPath = @"D:\Images\!";

            int x = 2690;
            int y = 1990;

            if (Directory.Exists(directoryPath))
            {
                string[]             files       = Directory.GetFiles(directoryPath);
                IEnumerable <string> sortedFiles = files.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f)));

                int n = 0;

                int minIntensity         = 255;
                int maxIntensity         = 0;
                List <ChartPoint> points = new List <ChartPoint>();

                foreach (string file in sortedFiles)
                {
                    using (Bitmap bitmap = new Bitmap(file))
                    {
                        System.Drawing.Color color = bitmap.GetPixel(x, y);
                        int intensity = ColorWrapper.GetGrayIntensity(color);
                        if (intensity < minIntensity)
                        {
                            minIntensity = intensity;
                        }
                        if (intensity > maxIntensity)
                        {
                            maxIntensity = intensity;
                        }

                        ChartPoint chartPoint = new ChartPoint(n, intensity);
                        points.Add(chartPoint);
                        n++;
                    }
                }

                Chart chart1 = new Chart()
                {
                    SeriesCollection = new List <ChartSeries>()
                    {
                        new ChartSeries()
                        {
                            Name            = "Grpah",
                            Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                            ColorDescriptor = new ColorDescriptor(255, 0, 0),
                            Points          = points
                        }
                    }
                };

                MemoryWriter.Write <Chart>(chart1, new ChartSerialization());
                ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

                Thread.Sleep(2000);

                Interval <double>     startInterval  = new Interval <double>(minIntensity, maxIntensity);
                Interval <double>     finishInterval = new Interval <double>(-1, 1);
                RealIntervalTransform transform      = new RealIntervalTransform(startInterval, finishInterval);
                List <ChartPoint>     points2        = new List <ChartPoint>();
                foreach (ChartPoint p in points)
                {
                    double     newValue = transform.TransformToFinishIntervalValue(p.Y);
                    ChartPoint point    = new ChartPoint(p.X, newValue);
                    points2.Add(point);
                }

                Chart chart2 = new Chart()
                {
                    SeriesCollection = new List <ChartSeries>()
                    {
                        new ChartSeries()
                        {
                            Name            = "Grpah2",
                            Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                            ColorDescriptor = new ColorDescriptor(0, 255, 0),
                            Points          = points2
                        }
                    }
                };

                MemoryWriter.Write <Chart>(chart2, new ChartSerialization());
                ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

                Thread.Sleep(2000);

                List <ChartPoint> points3 = new List <ChartPoint>();
                foreach (ChartPoint p in points2)
                {
                    double     newValue = Math.Acos(p.Y);
                    ChartPoint point    = new ChartPoint(p.X, newValue);
                    points3.Add(point);
                }

                Chart chart3 = new Chart()
                {
                    SeriesCollection = new List <ChartSeries>()
                    {
                        new ChartSeries()
                        {
                            Name            = "Grpah3",
                            Type            = HoloCommon.Enumeration.Charting.ChartSeriesType.Linear,
                            ColorDescriptor = new ColorDescriptor(0, 0, 0),
                            Points          = points3
                        }
                    }
                };

                MemoryWriter.Write <Chart>(chart3, new ChartSerialization());
                ProcessManager.RunProcess(@"D:\Projects\HoloApplication\Modules\ChartApp\ChartApp\bin\Release\ChartApp.exe", null, false, false);

                Thread.Sleep(2000);
            }
        }