当前位置: 首页>>代码示例>>C#>>正文


C# Mat.GetData方法代码示例

本文整理汇总了C#中Mat.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.GetData方法的具体用法?C# Mat.GetData怎么用?C# Mat.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat.GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateWithMat

    public static void UpdateWithMat(this Texture2D texture, Mat image)
    {
        int channels = image.NumberOfChannels;
        byte[] pixels = image.GetData(new int[]{});
        int pixelCount = pixels.Length / channels;

        Color[] textureColors = new Color[pixelCount];

        Parallel.For(0, pixelCount,  i =>
                     {
            int pixelIndex = i * channels;
            Color col;

            byte bb = pixels[pixelIndex];
            float b = (float)bb / 255.0f;

            if(channels == 1)
            {
                col = new Color(b,b,b);
            }
            else if(channels == 3)
            {
                byte gb = pixels[pixelIndex+1];
                float g = (float)gb / 255.0f;

                byte rb = pixels[pixelIndex+2];
                float r = (float)rb / 255.0f;

                col = new Color(r,g,b);
            }
            else col = Color.magenta;

            textureColors[i] = col;
        });

        texture.SetPixels(textureColors);
        texture.Apply();
    }
开发者ID:AndyGates,项目名称:TrackMyBalls,代码行数:38,代码来源:CVTextureUtility.cs

示例2: extractPointColor

        // forced static
        private static Bgr extractPointColor(Point p, Mat input)
        {
            HashSet<Bgr> nearbyColors = new HashSet<Bgr>();

            for (int i = p.X - Constants.AREA_SHIFT; i <= p.X + Constants.AREA_SHIFT; i++)
            {
                for (int j = p.Y - Constants.AREA_SHIFT; j <= p.Y + Constants.AREA_SHIFT; j++)
                {
                    if (i >= 0 && i < input.Width)
                    {
                        if (j >= 0 && j < input.Height)
                        {

                            nearbyColors.Add(new Bgr(input.GetData(j, i)[0], input.GetData(j, i)[1], input.GetData(j, i)[2]));
                        }
                    }
                }
            }

            // check the whiteness of nearby pixels, use the less whiteness pixel as edge color
            double maxWhiteness = 0; // check max
            int index = 0;
            int maxIndex = 0;
            foreach (Bgr c in nearbyColors)
            {
                double whiteness = Metrics.Whiteness(c);
                if (whiteness > maxWhiteness)
                {
                    maxWhiteness = whiteness;
                    maxIndex = index;
                }
                index++;
            }

            //Color ccolor = Color.FromArgb((int)color.Red, (int)color.Green, (int)color.Blue);

            return nearbyColors.ElementAt(maxIndex);
        }
开发者ID:gw-sd-2016,项目名称:TornRepair,代码行数:39,代码来源:ColorfulContourMap.cs

示例3: CaptureOnImageGrabbed

        private void CaptureOnImageGrabbed(object sender, EventArgs eventArgs)
        {
            var capture = (Capture) sender;

            var frame = new Mat();
            capture.Retrieve(frame);

            // 1. get key points
            var keyPoints = new VectorOfKeyPoint(_detector.Detect(frame));
            _tempCloudPoints.SetKeyFeatures(_selectedFrameIndex, keyPoints);

            // 2. get descripters
            var descripters = new Mat();
            _descripter.Compute(frame, keyPoints, descripters);

            // draw keypoints
            var imageFrame = new Mat();
            Features2DToolbox.DrawKeypoints(frame, keyPoints, imageFrame, new Bgr(Color.DarkBlue),
                Features2DToolbox.KeypointDrawType.NotDrawSinglePoints);

            if (_selectedFrameIndex != 0)
            {
                var previousKeyPoints = _tempCloudPoints.GetKeyFeatures(_selectedFrameIndex - 1);
                var previousKeyDescripters = _previousDescripters;

                const int k = 2;
                const double uniquenessThreshold = 0.8;

                // 3. compute all matches with previous frame
                var matches = new VectorOfVectorOfDMatch();
                var matcher = GetNativeMatcher(SelectedMatcher);
                matcher.Add(previousKeyDescripters);

                matcher.KnnMatch(descripters, matches, k, null);

                var mask = new Mat(matches.Size, 1, DepthType.Cv8U, 1);
                mask.SetTo(new MCvScalar(255));
                Features2DToolbox.VoteForUniqueness(matches, uniquenessThreshold, mask);
                Features2DToolbox.VoteForSizeAndOrientation(previousKeyPoints, keyPoints,
                       matches, mask, 1.5, 20);
                Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(previousKeyPoints,
                            keyPoints, matches, mask, 2);

                var managedMask = mask.GetData();

                // 4. separate good matches
                var currentKeys = keyPoints;

                for (int i = 0; i < matches.Size; i++)
                {
                    var match = matches[i][0];
                    // filter wrong matches
                    if (managedMask[i] == 1)
                    {
                        var previousIndex = match.TrainIdx;
                        var currentIndex = match.QueryIdx;

                        var previousPoint = previousKeyPoints[previousIndex].Point;
                        var currentPoint = currentKeys[currentIndex].Point;

                        _tempCloudPoints.Unite(_selectedFrameIndex - 1, previousIndex,
                            _selectedFrameIndex, currentIndex);

                        CvInvoke.Line(imageFrame,
                            Point.Round(previousPoint),
                            Point.Round(currentPoint),
                            new Bgr(Color.Red).MCvScalar,
                            2);
                    }
                }
            }

            _previousDescripters = descripters;

            PreviewImageSource = imageFrame;

            _selectedFrameIndex++;
            RaisePropertyChanged("Progress");
            RaisePropertyChanged("ProgressText");
            if (_selectedFrameIndex == _framesCount)
            {
                GeneratingStates = FeatureGeneratingStates.Finished;
            }
        }
开发者ID:amdandrew,项目名称:ComputerVision,代码行数:84,代码来源:CreateProjectViewModel.cs

示例4: TestDenseHistogram4

 public void TestDenseHistogram4()
 {
    Mat img = new Mat(400, 400, DepthType.Cv8U, 3);
    CvInvoke.Randu(img, new MCvScalar(), new MCvScalar(255, 255, 255));
    Mat hist = new Mat();
    using (VectorOfMat vms = new VectorOfMat(img))
    {
       CvInvoke.CalcHist(vms, new int[] { 0, 1, 2 }, null, hist, new int[] { 20, 20, 20 },
          new float[] { 0, 255, 0, 255, 0, 255 }, true);
       byte[] bytes = hist.GetData();
    }
 }
开发者ID:Delaley,项目名称:emgucv,代码行数:12,代码来源:AutoTestVarious.cs

示例5: ComputeManhattanColorDistances

        public static int[] ComputeManhattanColorDistances(Mat rChannel, Mat gChannel, Mat bChannel, Point centralPixel, double p)
        {
            Point[] neighbours = GetNeighbours(centralPixel);

              var redCenterByte = rChannel.GetData(centralPixel.X, centralPixel.Y);
              var greenCenterByte = bChannel.GetData(centralPixel.X, centralPixel.Y);
              var blueCenterByte = bChannel.GetData(centralPixel.X, centralPixel.Y);

              var redCenter = Convert.ToInt32(redCenterByte[0]);
              var greenCenter = Convert.ToInt32(greenCenterByte[0]);
              var blueCenter = Convert.ToInt32(blueCenterByte[0]);

              var coefficients = new double[8];

              for(int dIndex = 0; dIndex < 8; dIndex++)
              {
              var point = neighbours[dIndex];
              var redByte = rChannel.GetData(point.X, point.Y);
              var greenByte = bChannel.GetData(point.X, point.Y);
              var blueByte = bChannel.GetData(point.X, point.Y);

              var red = Convert.ToInt32(redByte[0]);
              var green = Convert.ToInt32(greenByte[0]);
              var blue = Convert.ToInt32(blueByte[0]);

              var d = (double)(Math.Abs(redCenter - red) + Math.Abs(greenCenter - green) + Math.Abs(blueCenter - blue)) / (3 * 255);

              //Debug.WriteLine("d: " + d);

              var c = Math.Pow((1 - d), p);

              coefficients[dIndex] = c;
              //distances.[0]
              }

              var sumCoefficients = coefficients.Sum();

              int newRed = 0;
              int newGreen = 0;
              int newBlue = 0;

              for (int dIndex = 0; dIndex < 8; dIndex++)
              {
              var point = neighbours[dIndex];
              var redByte = rChannel.GetData(point.X, point.Y);
              var greenByte = bChannel.GetData(point.X, point.Y);
              var blueByte = bChannel.GetData(point.X, point.Y);

              var red = Convert.ToInt32(redByte[0]);
              var green = Convert.ToInt32(greenByte[0]);
              var blue = Convert.ToInt32(blueByte[0]);

              newRed += (int)Math.Round(coefficients[dIndex] * (1 / sumCoefficients) * red);
              newGreen += (int)Math.Round(coefficients[dIndex] * (1 / sumCoefficients) * green);
              newBlue += (int)Math.Round(coefficients[dIndex] * (1 / sumCoefficients) * blue);
              }

              if(newRed > 255)
              {
              newRed = 255;
              }

              if (newGreen > 255)
              {
              newGreen = 255;
              }

              if (newBlue > 255)
              {
              newBlue = 255;
              }

              return new int[] { newRed, newGreen,  newBlue };
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:74,代码来源:Program.cs

示例6: BinaryImage

        async Task BinaryImage(Mat gray, int number, Mat canny = null, Mat color = null)
        {
            var image = gray;
            var imageData = EdgePreservingSmoothingBW(gray, 5);

            using (Matrix<byte> edgeSmoothingImage = new Matrix<byte>(imageData))
            //using (Mat image2 = new Mat(@"IMG_0041-Gray.jpg", LoadImageType.Grayscale))
            using (Mat cannyImage = new Mat())
            {
                await Dispatcher.BeginInvoke(_addImageToTheList,
                    edgeSmoothingImage.Mat);

                edgeSmoothingImage.Save("edgeSmoothingImage" + number + ".jpg");

                await Dispatcher.BeginInvoke(_addImageToTheList,
                    image);
                //await Dispatcher.BeginInvoke(_addImageToTheList,
                //    image2);

                var increasedContrasstArray = ChangeContrast(image, 80);

                using (var changedContrastImg = new Image<Gray, byte>(increasedContrasstArray))
                {
                    await Dispatcher.BeginInvoke(_addImageToTheList,
                    changedContrastImg.Mat);

                    changedContrastImg.Save("changedContrastImg" + number + ".jpg");

                    //CvInvoke.Threshold(changedContrastImg, cannyImage, 200, 255, ThresholdType.Binary);

                    //using(Mat sobel = new Mat())
                    //{

                    //}

                    Matrix<byte> sobelMatrix = new Matrix<byte>(image.Size);

                    var sobelX = new Mat(changedContrastImg.Size, DepthType.Cv8U, 1);
                    var sobelY = new Mat(changedContrastImg.Size, DepthType.Cv8U, 1);

                    CvInvoke.Sobel(changedContrastImg, sobelX, DepthType.Cv8U, 1, 0);
                    CvInvoke.Sobel(changedContrastImg, sobelY, DepthType.Cv8U, 0, 1);



                    for (int rowIndex = 0; rowIndex < changedContrastImg.Rows; rowIndex++)
                    {
                        for (int columnIndex = 0; columnIndex < changedContrastImg.Cols; columnIndex++)
                        {
                            var rX = sobelX.GetData(rowIndex, columnIndex)[0];
                            var rY = sobelY.GetData(rowIndex, columnIndex)[0];
                            sobelMatrix[rowIndex, columnIndex] = ToByte(Math.Sqrt(rX * rX + rY * rY));
                        }
                    }

                    //CvInvoke.Threshold(sobelMatrix, sobelMatrix, 170, 255, ThresholdType.Binary);

                    await Dispatcher.BeginInvoke(_addImageToTheList,
                            sobelMatrix.Mat);

                    sobelMatrix.Save("sobelMatrix" + number + ".bmp");

                    CvInvoke.Laplacian(image, sobelMatrix, DepthType.Cv8U, 3, 1, 0, BorderType.Default);

                    sobelMatrix.Save("laplacian" + number + ".bmp");

                    //CvInvoke.Threshold(sobelMatrix, sobelMatrix, 170, 255, ThresholdType.Binary);//170-190
                    //CvInvoke.AdaptiveThreshold(sobelMatrix, sobelMatrix, 255, AdaptiveThresholdType.MeanC, ThresholdType.Binary, 11, 2);

                    var edgeSmoothBWAray = EdgePreservingSmoothingBW(sobelMatrix.Mat, 5);

                    var edgeMatrix = new Matrix<byte>(edgeSmoothBWAray);

                    edgeMatrix.Save("laplacian-edgeMatrix" + number + ".bmp");

                    var thresholdEdge = CustomThreshold(edgeMatrix, 13);



                    Matrix<byte> thresholdEdgeMatrix = new Matrix<byte>(thresholdEdge);

                    thresholdEdgeMatrix.Save("laplacian-threshold-2-" + number + ".bmp");

                    sobelMatrix.Save("laplacian-threshold" + number + ".bmp");

                    CvInvoke.Canny(changedContrastImg, cannyImage, 150, 224, 3, false);
                    await Dispatcher.BeginInvoke(_addImageToTheList,
                        cannyImage);


                    Matrix<byte> mask = new Matrix<byte>(image.Size);

                    int dilSize = 2;
                    Mat se1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new System.Drawing.Size(2 * dilSize + 1, 2 * dilSize + 1), new System.Drawing.Point(dilSize, dilSize));
                    dilSize = 1;
                    Mat se2 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new System.Drawing.Size(2 * dilSize + 1, 2 * dilSize + 1), new System.Drawing.Point(dilSize, dilSize));
                    //CvInvoke.MorphologyEx(sobelMatrix, mask, MorphOp.Close, se1, new System.Drawing.Point(0, 0), 1, BorderType.Default, new MCvScalar(255, 0, 0, 255));

                    //await Dispatcher.BeginInvoke(_addImageToTheList,
                    //            mask.Mat);
//.........这里部分代码省略.........
开发者ID:chovik,项目名称:master-thesis,代码行数:101,代码来源:MainWindow.xaml.cs

示例7: SubSampling

        public static Mat SubSampling(Mat img)
        {
            ImageViewer.Show(img, String.Format(
                                                 "Canny Gray"));
               //img = new Mat("diplomka.png", LoadImageType.Color);
            var colorChannels = img.Split();

            var rSobelX =  new Mat(img.Size, DepthType.Cv8U, 1);
            var rSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelY = new Mat(img.Size, DepthType.Cv8U, 1);

            CvInvoke.Sobel(colorChannels[2], rSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[2], rSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[1], gSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[1], gSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[0], bSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[0], bSobelY, DepthType.Cv8U, 0, 1);

            int cols = img.Cols;
            int rows = img.Rows;

            var edgeValues = new double[rows, cols];

            for(int rowIndex = 0; rowIndex < rows; rowIndex++)
            {
                for(int columnIndex = 0; columnIndex < cols; columnIndex++)
                {
                    var rX = rSobelX.GetData(rowIndex, columnIndex)[0];
                    var rY = rSobelY.GetData(rowIndex, columnIndex)[0];
                    var gX = gSobelX.GetData(rowIndex, columnIndex)[0];
                    var gY = gSobelY.GetData(rowIndex, columnIndex)[0];
                    var bX = bSobelX.GetData(rowIndex, columnIndex)[0];
                    var bY = bSobelY.GetData(rowIndex, columnIndex)[0];

                    var edgeRed = Math.Sqrt(rX*rX + rY*rY);
                    var edgeGreen = Math.Sqrt(gX*gX + gY*gY);
                    var edgeBlue = Math.Sqrt(bX*bX + bY*bY);

                    var edgeValue = (new double[]{edgeRed, edgeGreen, edgeBlue}).Max();
                    edgeValues[rowIndex, columnIndex] = edgeValue;
                }
            }

               var samples = new byte[rows, cols, 3];

               var samplesList = new List<RGBSample>();
               var samplesHistogram = new RGBSample[256, 256, 256];

            for (int rowIndex = 0; rowIndex < rows; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < cols; columnIndex++)
                {
                    var isLocalMinima = false;

                    if (rowIndex > 0
                        && rowIndex < rows - 1
                        && columnIndex > 0
                        && columnIndex < cols - 1 )
                    {
                        isLocalMinima = IsLocalMinima(new Point(rowIndex, columnIndex), edgeValues);
                    }

                    if(!isLocalMinima)
                    {
                        samples[rowIndex, columnIndex, 2] = 255;
                        samples[rowIndex, columnIndex, 1] = 255;
                        samples[rowIndex, columnIndex, 0] = 255;
                    }
                    else
                    {
                        var bytes = img.GetData(rowIndex, columnIndex);

                        var r = bytes[2];
                        var g = bytes[1];
                        var b = bytes[0];

                        samples[rowIndex, columnIndex, 2] = r;
                        samples[rowIndex, columnIndex, 1] = g;
                        samples[rowIndex, columnIndex, 0] = b;

                        if(samplesHistogram[r , g, b] == null)
                        {
                            var sample =  new RGBSample() { Red = r, Green = g, Blue = b};
                            samplesHistogram[r, g, b] = sample;
                            samplesList.Add(sample);
                        }

                        samplesHistogram[r, g, b].Points.Add(new Point(rowIndex, columnIndex));
                    }
                }
            }

               Image<Bgr, byte> img4 = new Image<Bgr, byte>(samples);
            ImageViewer.Show(img4, String.Format(
                                                 "44 Gray"));
//.........这里部分代码省略.........
开发者ID:chovik,项目名称:master-thesis,代码行数:101,代码来源:Program.cs

示例8: ChangeContrast

        public byte[, ,] ChangeContrast(Mat img, double a, double b = 128)
        {
            //a = 50;
            byte[, ,] data = new byte[img.Rows, img.Cols, img.NumberOfChannels];

            var factor = (259 * (a + 255)) / (255 * (259 - a));


            //if (img.NumberOfChannels == 3)
            //{
            for (int row = 0; row < img.Rows; row++)
            {
                for (int column = 0; column < img.Cols; column++)
                {
                    for (int channel = 0; channel < img.NumberOfChannels; channel++)
                    {
                        var oldValue = img.GetData(row, column)[channel];
                        var val = factor * (oldValue - b) + b;
                        var newValue = Math.Truncate(val);

                        if (newValue > 256)
                        {
                            newValue = 255;
                        }
                        else if (newValue < 0)
                        {
                            newValue = 0;
                        }

                        data[row, column, channel] = (byte)newValue;
                    }
                }
                //}
            }

            return data;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:37,代码来源:MainWindow.xaml.cs

示例9: FindBlobs

        VectorOfVectorOfPoint FindBlobs(Mat binary, int index)
        {
            VectorOfVectorOfPoint blobs = new VectorOfVectorOfPoint();

            // Fill the label_image with the blobs
            // 0  - background
            // 1  - unlabelled foreground
            // 2+ - labelled foreground

            Mat label_image = new Mat();
            binary.ConvertTo(label_image, DepthType.Cv8U);

            int label_count = 2; // starts at 2 because 0,1 are used already

            for (int y = 0; y < label_image.Rows; y++)
            {

                for (int x = 0; x < label_image.Cols; x++)
                {
                    var val = label_image.GetData(y, x)[0];

                    if (val != 255)
                    {
                        continue;
                    }
 
                    System.Drawing.Rectangle rect;
                    CvInvoke.FloodFill(label_image, new Mat(), new System.Drawing.Point(x, y), new MCvScalar(label_count), out rect, new MCvScalar(0), new MCvScalar(0), Connectivity.FourConnected, FloodFillType.Default);
                    //cv::floodFill(label_image, cv::Point(x,y), label_count, &rect, 0, 0, 4);

                    VectorOfPoint blob = new VectorOfPoint();

                    for (int i = rect.Y; i < (rect.Y + rect.Height); i++)
                    {

                        for (int j = rect.X; j < (rect.X + rect.Width); j++)
                        {
                            var val2 = label_image.GetData(y, x)[0];
                            if (val2 != label_count)
                            {
                                continue;
                            }

                            blob.Push(new System.Drawing.Point[] { new System.Drawing.Point(j, i) });
                        }
                    }

                    blobs.Push(blob);

                    label_count++;
                }
            }

            label_image.Save("labeled" + index + ".bmp");

            return blobs;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:57,代码来源:MainWindow.xaml.cs

示例10: EdgePreservingSmoothingBW

        public static byte[,] EdgePreservingSmoothingBW(Mat img, int numberOfCycles = 5)
        {
            byte[,] resultValues = new byte[img.Rows, img.Cols];

            for (int i = 0; i < 1; i++)
            {

                int cols = img.Cols;
                int rows = img.Rows;

                //result image will be smaller because the pixels on the border have less then 8 neighbours. 
                //we are going to ignore them
                Mat result = new Mat(img.Rows - 2, img.Cols - 2, img.Depth, 1);


                for (int rowIndex = 0; rowIndex < rows; rowIndex++)
                {
                    for (int columnIndex = 0; columnIndex < cols; columnIndex++)
                    {
                        if (rowIndex == 0
                            || rowIndex == rows - 1
                            || columnIndex == 0
                            || columnIndex == cols - 1)
                        {
                            //pixel is on the border
                            resultValues[rowIndex, columnIndex] = 0;
                            continue;
                        }
                        var oldValue = img.GetData(rowIndex, columnIndex)[0];
                        if (oldValue == 0)
                        {
                            //var newValue = ComputeManhattanColorDistancesBW(img, new System.Drawing.Point(rowIndex, columnIndex), 10);
                            resultValues[rowIndex, columnIndex] = Convert.ToByte(oldValue);
                        }
                        else
                        {
                            var newValue = ComputeManhattanColorDistancesBW(img, new System.Drawing.Point(rowIndex, columnIndex), 10);
                            resultValues[rowIndex, columnIndex] = Convert.ToByte(newValue);
                        }

                    }
                }

                //Image<Gray, byte> img2 = new Image<Gray, byte>(resultValues);
                //img = img2.Mat;
            }





            //ImageViewer.Show(img2, String.Format(
            //                                      "Img Gray"));

            return resultValues;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:56,代码来源:MainWindow.xaml.cs

示例11: ComputeManhattanColorDistancesBW

        public static int ComputeManhattanColorDistancesBW(Mat gray, System.Drawing.Point centralPixel, double p)
        {
            System.Drawing.Point[] neighbours = GetNeighbours(centralPixel);

            var centerByte = gray.GetData(centralPixel.X, centralPixel.Y);

            var center = (byte)Convert.ToInt32(centerByte[0]);

            var coefficients = new double[8];

            for (int dIndex = 0; dIndex < 8; dIndex++)
            {
                var point = neighbours[dIndex];
                var byteVal = gray.GetData(point.X, point.Y);

                var val = (byte)Convert.ToInt32(byteVal[0]);



                var d = (double)(Math.Abs(center - val) / 255);
                //var delta2000 = deltaE2000(new byte[] { blue, green, red }, new byte[] { blueCenter, greenCenter, redCenter });
                //Debug.WriteLine("d: " + d);
                //var deltaPercentage = delta2000/100.0;
                //Debug.Assert(deltaPercentage <= 1);

                var c = Math.Pow((1 - d), p);

                coefficients[dIndex] = c;
                //distances.[0]
            }

            var sumCoefficients = coefficients.Sum();

            int newVal = 0;

            for (int dIndex = 0; dIndex < 8; dIndex++)
            {
                var point = neighbours[dIndex];
                var valByte = gray.GetData(point.X, point.Y);

                var val = Convert.ToInt32(valByte[0]);

                newVal += (int)Math.Round(coefficients[dIndex] * (1 / sumCoefficients) * val);
            }

            if (newVal > 255)
            {
                newVal = 255;
            }

            return newVal;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:52,代码来源:MainWindow.xaml.cs

示例12: GetRgb

        public static Rgb GetRgb(System.Drawing.Point point, Mat img)
        {
            Rgb rgb = new Rgb();

            rgb.Red = img.GetData(point.Y, point.X)[2];
            rgb.Green = img.GetData(point.Y, point.X)[1];
            rgb.Blue = img.GetData(point.Y, point.X)[0];

            return rgb;

        }
开发者ID:chovik,项目名称:master-thesis,代码行数:11,代码来源:MainWindow.xaml.cs

示例13: PostProcessing

        public static byte[, ,] PostProcessing(Mat img)
        {
            var edgeData = ComputeEdgeMagnitudes(img);
            int rows = img.Rows;
            int cols = img.Cols;
            var colors = img.NumberOfChannels;
            byte[, ,] newData = new byte[rows, cols, colors];

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    if (row == 0
                            || row == rows - 1
                            || col == 0
                            || col == cols - 1)
                    {
                        newData[row, col, 2] = img.GetData(row, col)[2];
                        newData[row, col, 1] = img.GetData(row, col)[1];
                        newData[row, col, 0] = img.GetData(row, col)[0];
                    }
                    else
                    {
                        Rgb newValue = PostProcessPixel(new System.Drawing.Point(col, row), img, edgeData);
                        newData[row, col, 2] = ToByte(newValue.Red);
                        newData[row, col, 1] = ToByte(newValue.Green);
                        newData[row, col, 0] = ToByte(newValue.Blue);
                    }


                }
            }

            return newData;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:35,代码来源:MainWindow.xaml.cs

示例14: ComputeEdgeMagnitudes

        public static double[, ,] ComputeEdgeMagnitudes(Mat img)
        {
            var colorChannels = img.Split();

            var rSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var rSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelY = new Mat(img.Size, DepthType.Cv8U, 1);

            CvInvoke.Sobel(colorChannels[2], rSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[2], rSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[1], gSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[1], gSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[0], bSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[0], bSobelY, DepthType.Cv8U, 0, 1);


            int cols = img.Cols;
            int rows = img.Rows;

            var edgeValues = new double[rows, cols, 1];

            for (int rowIndex = 0; rowIndex < rows; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < cols; columnIndex++)
                {
                    var rX = rSobelX.GetData(rowIndex, columnIndex)[0];
                    var rY = rSobelY.GetData(rowIndex, columnIndex)[0];
                    var gX = gSobelX.GetData(rowIndex, columnIndex)[0];
                    var gY = gSobelY.GetData(rowIndex, columnIndex)[0];
                    var bX = bSobelX.GetData(rowIndex, columnIndex)[0];
                    var bY = bSobelY.GetData(rowIndex, columnIndex)[0];

                    var edgeRed = Math.Sqrt(rX * rX + rY * rY);
                    var edgeGreen = Math.Sqrt(gX * gX + gY * gY);
                    var edgeBlue = Math.Sqrt(bX * bX + bY * bY);

                    var edgeValue = (new double[] { edgeRed, edgeGreen, edgeBlue }).Max();
                    edgeValues[rowIndex, columnIndex, 0] = edgeValue;
                }
            }

            return edgeValues;
        }
开发者ID:chovik,项目名称:master-thesis,代码行数:48,代码来源:MainWindow.xaml.cs

示例15: SubSampling

        public async Task<byte[, ,]> SubSampling(Mat img, VectorOfPoint points)
        {
            //ProcessingImageWorkflow.Add(ToBitmapSource(img));
            //img = new Mat("diplomka.png", LoadImageType.Color);
            var colorChannels = img.Split();

            var rSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var rSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var gSobelY = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelX = new Mat(img.Size, DepthType.Cv8U, 1);
            var bSobelY = new Mat(img.Size, DepthType.Cv8U, 1);

            CvInvoke.Sobel(colorChannels[2], rSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[2], rSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[1], gSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[1], gSobelY, DepthType.Cv8U, 0, 1);

            CvInvoke.Sobel(colorChannels[0], bSobelX, DepthType.Cv8U, 1, 0);
            CvInvoke.Sobel(colorChannels[0], bSobelY, DepthType.Cv8U, 0, 1);


            int cols = img.Cols;
            int rows = img.Rows;

            var edgeValues = new double[rows, cols];
            var edgeValuesTest = new byte[rows, cols, 1];

            for (int pointIndex = 0; pointIndex < points.Size; pointIndex++)
            {
                var point = points[pointIndex];

                var rX = rSobelX.GetData(point.Y, point.X)[0];
                var rY = rSobelY.GetData(point.Y, point.X)[0];
                var gX = gSobelX.GetData(point.Y, point.X)[0];
                var gY = gSobelY.GetData(point.Y, point.X)[0];
                var bX = bSobelX.GetData(point.Y, point.X)[0];
                var bY = bSobelY.GetData(point.Y, point.X)[0];

                var edgeRed = Math.Sqrt(rX * rX + rY * rY);
                var edgeGreen = Math.Sqrt(gX * gX + gY * gY);
                var edgeBlue = Math.Sqrt(bX * bX + bY * bY);

                var edgeValue = (new double[] { edgeRed, edgeGreen, edgeBlue }).Max();
                edgeValuesTest[point.Y, point.X, 0] = ToByte(edgeValue);
                edgeValues[point.Y, point.X] = edgeValue;
            }

            Image<Gray, byte> edGE = new Image<Gray, byte>(edgeValuesTest);

            await Dispatcher.BeginInvoke(_addImageToTheList,
                                    edGE.Mat);

            var samples = new byte[rows, cols, 3];

            var samplesList = new List<RGBSample>();
            var samplesHistogram = new RGBSample[256, 256, 256];

            for (int pointIndex = 0; pointIndex < points.Size; pointIndex++)
            {
                var point = points[pointIndex];

                var isLocalMinima = false;

                if (point.Y > 0
                    && point.Y < rows - 1
                    && point.X > 0
                    && point.X < cols - 1)
                {
                    isLocalMinima = IsLocalMinima(new System.Drawing.Point(point.Y, point.X), edgeValues);
                }

                if (!isLocalMinima)
                {
                    samples[point.Y, point.X, 2] = 255;
                    samples[point.Y, point.X, 1] = 255;
                    samples[point.Y, point.X, 0] = 255;
                }
                else
                {
                    var bytes = img.GetData(point.Y, point.X);

                    var r = bytes[2];
                    var g = bytes[1];
                    var b = bytes[0];

                    samples[point.Y, point.X, 2] = r;
                    samples[point.Y, point.X, 1] = g;
                    samples[point.Y, point.X, 0] = b;

                    if (samplesHistogram[r, g, b] == null)
                    {
                        var sample = new RGBSample() { Red = r, Green = g, Blue = b };
                        samplesHistogram[r, g, b] = sample;
                        samplesList.Add(sample);
                    }

                    samplesHistogram[r, g, b].Points.Add(new Point(point.Y, point.X));
                }
//.........这里部分代码省略.........
开发者ID:chovik,项目名称:master-thesis,代码行数:101,代码来源:MainWindow.xaml.cs


注:本文中的Mat.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。