Example #1
0
        private VectorPixel[][] InitilizeVectorPixels()
        {
            var          image         = Util.GetGreyScaleImage(@"D:\Image Resource\21.png");
            GaussianBlur gaussianBlur  = new GaussianBlur(image);
            var          sobelOperator = new SobelOperator(gaussianBlur.GaussianBlurredImage);

            VectorPixel.NormalizeIntensity(sobelOperator.VectorPixels);
            return(sobelOperator.VectorPixels);
        }
Example #2
0
        public void SobelTest()
        {
            var           image         = Util.GetGreyScaleImage(@"D:\Image Resource\7.png");
            GaussianBlur  gaussianBlur  = new GaussianBlur(image);
            SobelOperator sobelOperator = new SobelOperator(gaussianBlur.GaussianBlurredImage);

            VectorPixel.NormalizeIntensity(sobelOperator.VectorPixels);
            Util.SaveImage(@"D:\Sobel.png", VectorPixel.GetByteArray(sobelOperator.VectorPixels));
            CannyEdgeFilter cannyEdgeFilter = new CannyEdgeFilter(sobelOperator.VectorPixels, 20, 50);

            Util.SaveImage(@"D:\Canny.png", VectorPixel.GetByteArray(cannyEdgeFilter.VectorPixels));
            Process.Start(@"D:\Canny.png");
        }
 private void PopulateVectorPixels(byte[][] image)
 {
     for (int y = 1; y < image.Length - 1; y++)
     {
         VectorPixels[y - 1] = new VectorPixel[image[y].Length - 2];
         for (int x = 1; x < image[y].Length - 1; x++)
         {
             int xGradient = FindXGradient(image, x, y);
             int yGradient = FindYGradient(image, x, y);
             VectorPixels[y - 1][x - 1] = new VectorPixel(xGradient, yGradient);
         }
     }
 }
Example #4
0
        private VectorPixel[][] CopyVectorPixels(VectorPixel[][] vectorPixels)
        {
            var newVectorPixels = new VectorPixel[vectorPixels.Length][];

            for (int y = 0; y < vectorPixels.Length; y++)
            {
                newVectorPixels[y] = new VectorPixel[vectorPixels[y].Length];
                for (int x = 0; x < vectorPixels[y].Length; x++)
                {
                    newVectorPixels[y][x] = new VectorPixel(vectorPixels[y][x]);
                }
            }
            return(newVectorPixels);
        }
Example #5
0
        private void ApplyCannyEdgeFilter()
        {
            CannyEdgeFilter cannyEdgeFilter = new CannyEdgeFilter(_vectorPixels, LowerThreshold, UpperThreshold);
            string          imgLoc;

            if (!string.IsNullOrEmpty(Image) && Image.Equals(@"D:\Sobel1.png"))
            {
                imgLoc = @"D:\Sobel2.png";
            }
            else
            {
                imgLoc = @"D:\Sobel1.png";
            }
            Util.SaveImage(imgLoc, VectorPixel.GetByteArray(cannyEdgeFilter.VectorPixels));
            Image = imgLoc;
        }
Example #6
0
        private static void ProcessMiddleOddRows(RawPixel <ushort> raw, int Width, VectorPixel pix)
        {
            float maxValue = raw.MaxValue;

            // First left pixel
            pix.SetAndMoveNext(
                (raw.GetRel(1, 0) / maxValue),
                (raw.Value / maxValue),
                ((raw.GetRel(0, -1) + raw.GetRel(0, +1)) / maxValue / 2));
            raw.MoveNext();

            var lastX = Width - 1;

            for (var x = 1; x < lastX; x += 2)
            {
                var xy     = raw.Value;
                var x1y    = raw.GetRel(+1, 0);
                var x11y12 = raw.GetRel(+1, -1) + raw.GetRel(+1, +1);

                pix.SetAndMoveNext(
                    (xy / maxValue),
                    ((raw.GetRel(-1, 0) + x1y + raw.GetRel(0, -1) + raw.GetRel(0, +1)) / maxValue / 4),
                    ((raw.GetRel(-1, -1) + x11y12 + raw.GetRel(-1, +1)) / maxValue / 4));

                pix.SetAndMoveNext(
                    ((xy + raw.GetRel(+2, 0)) / maxValue / 2),
                    (x1y / maxValue),
                    (x11y12) / maxValue / 2);
                raw.MoveNext();
                raw.MoveNext();
            }

            // First right pixel
            pix.SetAndMoveNext(
                (raw.Value / maxValue),
                ((raw.GetRel(0, -1) + raw.GetRel(0, +1) + (raw.GetRel(-1, 0) << 1)) / maxValue / 4),
                ((raw.GetRel(-1, -1) + raw.GetRel(-1, +1)) / maxValue / 2));
            raw.MoveNext();
        }
Example #7
0
        private static void ProcessMiddleEvenRows(RawPixel <ushort> raw, int Width, VectorPixel pix)
        {
            float maxValue = raw.MaxValue;

            // Second left pixel
            pix.SetAndMoveNext(
                ((raw.GetRel(1, -1) + raw.GetRel(1, +1)) / maxValue / 2.0f),
                ((raw.GetRel(0, -1) + raw.GetRel(0, +1) + (raw.GetRel(1, 0) << 1)) / maxValue / 4.0f),
                raw.Value / maxValue);
            raw.MoveNext();

            var lastX = Width - 1;

            for (var x = 1; x < lastX; x += 2)
            {
                var xy   = raw.Value;
                var x1y  = raw.GetRel(+1, 0);
                var xy12 = raw.GetRel(0, -1) + raw.GetRel(0, +1);

                pix.SetAndMoveNext(
                    (xy12) / maxValue / 2.0f,
                    (xy) / maxValue,
                    ((raw.GetRel(-1, 0) + x1y)) / maxValue / 2.0f);

                pix.SetAndMoveNext(
                    ((xy12 + raw.GetRel(+2, -1) + raw.GetRel(+2, +1)) / maxValue / 4),
                    ((xy + raw.GetRel(+2, 0) + raw.GetRel(+1, -1) + raw.GetRel(+1, +1)) / maxValue / 4),
                    (x1y) / maxValue);
                raw.MoveNext();
                raw.MoveNext();
            }

            // Second right pixel
            pix.SetAndMoveNext(
                ((raw.GetRel(0, -1) + raw.GetRel(0, +1)) / maxValue / 2),
                (raw.Value) / maxValue,
                (raw.GetRel(-1, 0) / maxValue));
            raw.MoveNext();
        }
Example #8
0
 public void ProcessColor(VectorPixel input, Color <T> output)
 {
     ProcessColor(input.Map, input.Offset, output.Map, output.Offset);
 }
Example #9
0
 public void ProcessColor(Vector3 input, VectorPixel output)
 {
     ProcessColor(ref input, ref output.Map[output.Offset]);
 }
Example #10
0
 public void ProcessColor(Vector3[] input, int inputOffset, VectorPixel output)
 {
     ProcessColor(input, inputOffset, output.Map, output.Offset);
 }