static int[] SobelPrewittConvolution(AdvancedConvolutionWindow window, FasterBitmap toCompute, int centerPositionX, int centerPositionY)
        {
            int[] values         = new int[2];
            int   xComputation   = 0;
            int   yComputation   = 0;
            int   yIndexFromZero = 0;

            for (int yIndex = centerPositionY - (window.windowDiameter / 2); yIndex < centerPositionY + (window.windowDiameter / 2) + 1; yIndex++)
            {
                int xIndexFromZero = 0;
                for (int xIndex = centerPositionX - (window.windowDiameter / 2); xIndex < centerPositionX + (window.windowDiameter / 2) + 1; xIndex++)
                {
                    if ((yIndex < 0) || (yIndex >= toCompute.Height) || (xIndex < 0) || (xIndex >= toCompute.Width))
                    {
                        continue;
                    }
                    else
                    {
                        xComputation = xComputation + (toCompute.GetPixel(xIndex, yIndex).B *window.horizontalValueMatrix[yIndexFromZero][xIndexFromZero]);
                        yComputation = yComputation + (toCompute.GetPixel(xIndex, yIndex).B *window.verticalValueMatrix[yIndexFromZero][xIndexFromZero]);
                    }
                    xIndexFromZero++;
                }
                yIndexFromZero++;
            }
            values[0] = xComputation;
            values[1] = yComputation;
            return(values);
        }
        static int[] RobertConvolution(AdvancedConvolutionWindow window, FasterBitmap toCompute, int centerPositionX, int centerPositionY)
        {
            int[] values       = new int[2];
            int   xComputation = 0;
            int   yComputation = 0;

            for (int yIndex = centerPositionY; yIndex < centerPositionY + 2; yIndex++)
            {
                for (int xIndex = centerPositionX; xIndex < centerPositionX + 2; xIndex++)
                {
                    if ((yIndex < 0) || (yIndex >= toCompute.Height) || (xIndex < 0) || (xIndex >= toCompute.Width))
                    {
                        continue;
                    }
                    else
                    {
                        xComputation = xComputation + (toCompute.GetPixel(xIndex, yIndex).B *window.horizontalValueMatrix[yIndex - centerPositionY][xIndex - centerPositionX]);
                        yComputation = yComputation + (toCompute.GetPixel(xIndex, yIndex).B *window.verticalValueMatrix[yIndex - centerPositionY][xIndex - centerPositionX]);
                    }
                }
            }
            values[0] = xComputation;
            values[1] = yComputation;
            return(values);
        }
Esempio n. 3
0
        private FasterBitmap CreateBitmap(string imagePath)   //Initialization of the Bitmap and FasterBitmap entities
        {
            try {
                this.bitmapImage = new Bitmap(imagePath);
            }
            catch (FileNotFoundException) {
                Console.WriteLine("File not found!");
                return(null);
            }
            catch (ArgumentException) {
                Console.WriteLine("The given argument is not a path!");
                return(null);
            }
            FasterBitmap imageFast = new FasterBitmap(bitmapImage);

            imageFast.LockBits();
            return(imageFast);
        }
Esempio n. 4
0
 public void ConvolutionWindowPixelsSumForColoredFilters(FasterBitmap toCompute, int centerPositionX, int centerPositionY)
 {
     for (int yIndex = centerPositionY - (this.windowDiameter - 1); yIndex < centerPositionY + (this.windowDiameter - 1); yIndex++)
     {
         for (int xIndex = centerPositionX - (this.windowDiameter - 1); xIndex < centerPositionX + (this.windowDiameter - 1); xIndex++)
         {
             if ((yIndex < 0) || (yIndex >= toCompute.Height) || (xIndex < 0) || (xIndex >= toCompute.Width))
             {
                 continue;
             }
             else
             {
                 this.sumColoredElements.Add(HSVColor.RGBtoHSV(toCompute.GetPixel(xIndex, yIndex)).value);
                 this.pixelsCounter++;
             }
         }
     }
     return;
 }
 static void StandardConvolution(AdvancedConvolutionWindow window, FasterBitmap toCompute, int centerPositionX, int centerPositionY)
 {
     for (int yIndex = centerPositionY - (window.windowDiameter / 2); yIndex < centerPositionY + (window.windowDiameter / 2) + 1; yIndex++)
     {
         for (int xIndex = centerPositionX - (window.windowDiameter / 2); xIndex < centerPositionX + (window.windowDiameter / 2) + 1; xIndex++)
         {
             if ((yIndex < 0) || (yIndex >= toCompute.Height) || (xIndex < 0) || (xIndex >= toCompute.Width))
             {
                 continue;
             }
             else
             {
                 int yValueIndex = yIndex - centerPositionY + (window.windowDiameter / 2);
                 int xValueIndex = xIndex - centerPositionX + (window.windowDiameter / 2);
                 window.sumElements.Add((toCompute.GetPixel(xIndex, yIndex).B) * (window.valueMatrix[yValueIndex][xValueIndex]));
             }
         }
     }
     return;
 }