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


C# Image.GetPixels方法代码示例

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


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

示例1: Apply

        public static Image Apply(Image original, Image toBeReconstructedImage)
        {
            if (original.Size.Width != toBeReconstructedImage.Size.Width || original.Size.Height != toBeReconstructedImage.Size.Height) throw new Exception("Images dont match in size..");

            int[,] currentPixelsImg1 = original.GetPixels();
            int[,] currentPixelsImg2 = toBeReconstructedImage.GetPixels();

            int[,] newPixels = new int[original.Size.Width, original.Size.Height];

            //initialise image
            for (int x = 0; x < original.Size.Width; x++)
            {
                for (int y = 0; y < original.Size.Height; y++)
                {
                    newPixels[x, y] = Image.White;
                }
            }

            //Loop through the image
            for (int x = 0; x < toBeReconstructedImage.Size.Width; x++)
            {
                for (int y = 0; y < toBeReconstructedImage.Size.Height; y++)
                {
                    //if there is a pixel marked on the 'toBeReconstructedImage', reconstruct that object based on the original image's pixels:
                    if (currentPixelsImg2[x,y] == Image.Black)
                        ColorNeightbours(x, y, original.Size, ref currentPixelsImg1, ref newPixels);

                }
            }

            return new Image(newPixels, original.Size);
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:32,代码来源:Reconstruction.cs

示例2: ApplyDilation

        /// <summary>
        /// Apply specific dialation with a structure
        /// </summary>
        /// <param name="image">target image</param>
        /// <param name="structure">used structure</param>
        public void ApplyDilation(Image image, Structure structure)
        {
            int[,] currentPixels = image.GetPixels();
            int[,] newPixels = new int[image.Size.Width, image.Size.Height];

            //initialise image
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {

                    newPixels[x, y] = Image.White;//Default White value
                }
            }

            //structure information
            int structureWidth = structure.StructureSize.Width;
            int structureHeight = structure.StructureSize.Height;
            int middelPixelIndexWidth = structureWidth / 2;
            int middelPixelIndexHeight = structureHeight / 2;

            //Loop through the image
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {

                    if (image.GetPixelColor(x, y) == Image.White) continue;

                    //Determin structure's position, based on current pixel
                    int structureStartPositionX = x - middelPixelIndexWidth;
                    int structureStartPositionY = y - middelPixelIndexHeight;

                    //Loop through the structure
                    for (int k = 0; k < structureWidth; k++)
                    {
                        for (int l = 0; l < structureHeight; l++)
                        {
                            bool structureValue = structure.GetValue(k, l);
                            if (!structureValue) continue;

                            int posX = structureStartPositionX + k;
                            int posY = structureStartPositionY + l;

                            if (posX >= 0 && posX < image.Size.Width && posY >= 0 && posY < image.Size.Height) //check for out of bounce
                                 newPixels[posX, posY] = Image.Black;

                        }
                    }

                }
            }

            image.SetPixels(newPixels);
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:60,代码来源:Dilation.cs

示例3: ApplyBlackWhite

 /// <summary>
 /// Subtract the values from the second image from the first image. This method is used for black/white images.
 /// So all the black values from the second image will be subtracted from the first one.
 /// Read: Black = 1, White = 0; (This doesn't correspond with the actual values)
 /// </summary>
 /// <param name="Image"></param>
 /// <param name="Image2"></param>
 /// <returns></returns>
 public static Image ApplyBlackWhite(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             if (Image2.GetPixelColor(x, y) == Image.Black) newImg.SetPixelColor(x, y, Image.White);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:20,代码来源:Subtraction.cs

示例4: Apply

 /// <summary>
 /// Merge two images together
 /// </summary>
 /// <param name="Image">Input image 1</param>
 /// <param name="Image2">Input image 2</param>
 /// <returns>New image, which contains the two input images merged</returns>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             int additive_value = (Image.GetPixelColor(x, y)+ Image2.GetPixelColor(x, y));
             additive_value = (int)((additive_value) / 2.0f);//This line will re-balance the values from [ 0 , 510 ], to [ 0 , 255 ]
             newImg.SetPixelColor(x, y, additive_value);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:20,代码来源:Addition.cs

示例5: Apply

        public override void Apply(Image Image)
        {
            Image original = new Image(Image.GetPixels(), Image.Size);

            int intensity = 1;

            //Apply Dilation
            for(int i = 0; i < intensity; i++)
            Image.Apply(Operation.Operations.Dilation);

            //Apply Erosion
            for (int i = 0; i < intensity; i++)
                Image.Apply(Operation.Operations.Erosion);
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:14,代码来源:Closing.cs

示例6: Apply

 /// <summary>
 /// Applies XOR, returning a new image that only contains black pixels that are in both images
 /// </summary>
 /// <param name="Image">target image 1</param>
 /// <param name="Image2">target image 2</param>
 /// <returns>new image that contains the black pixels that are in both images</returns>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size);
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             bool img1 = (Image.GetPixelColor(x, y) == Image.Black);//if image 1 has a black pixel on this position
             bool img2 = (Image2.GetPixelColor(x, y) == Image.Black);//if image 2 has a black pixel on this position
             int result = (img1 || img2) ? Image.Black : Image.White;//if either one of the two booleans is true, draw black. Else draw white.
             newImg.SetPixelColor(x, y, result);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:21,代码来源:OR.cs

示例7: Apply

        /// <summary>
        /// Apply opening to the given image
        /// </summary>
        /// <param name="image"></param>
        public override void Apply(Image image)
        {
            Image original = new Image(image.GetPixels(), image.Size);

            int intensity = 4;

            //Apply Erosion
            for (int i = 0; i < intensity; i++)
                image.Apply(Operation.Operations.Erosion);

            //Reconstruct image
            int[,] newPixels = Reconstruction.Apply(original, image).GetPixels();

            //Update image with new pixels:
            image.SetPixels(newPixels);
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:20,代码来源:Opening.cs

示例8: Apply

 /// <summary>
 /// Subtract the values of the second image from the first image. Normalise the image afterwards.
 /// </summary>
 public static Image Apply(Image Image, Image Image2)
 {
     Image newImg = new Image(Image.GetPixels(), Image.Size); //Todo: Shouln't we just make a new pixel array here, instead of copying the first image?
     for (int x = 0; x < Image.Size.Width; x++)
     {
         for (int y = 0; y < Image.Size.Height; y++)
         {
             int additive_value = (Image.GetPixelColor(x, y)- Image2.GetPixelColor(x, y));
             //if (additive_value < 0) additive_value = Image.Black;
             int highestValue = Image.White;
             additive_value = (int)((additive_value + highestValue) / 2.0f);//This line will re-balance the values from [ -225, 255 ], to [ 0 , 255 ]
             newImg.SetPixelColor(x, y, additive_value);
         }
     }
     return newImg;
 }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:19,代码来源:Subtraction.cs

示例9: Apply

        public void Apply()
        {
            Image copy = new Image(originalImage.GetPixels(), originalImage.Size);

            int[,] copyPixels = copy.GetPixels();

            //Loop through the image
            for (int x = 0; x < copy.Size.Width; x++)
            {
                for (int y = 0; y < copy.Size.Height; y++)
                {
                    //if there is a pixel marked on the 'toBeReconstructedImage', reconstruct that object based on the original image's pixels:
                    if (copyPixels[x, y] == Image.Black)
                        ExtractObjectFromImage(x, y, ref copyPixels);

                }
            }
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:18,代码来源:ObjectDetection.cs

示例10: Apply

        /// <summary>
        /// Calculate Difference and return a new image that represents the differences
        /// </summary>
        /// <param name="img1">first image</param>
        /// <param name="img2">second image</param>
        /// <returns>a new images that represents the difference between the input images</returns>
        public static Image Apply(Image img1, Image img2)
        {
            Image newImg = new Image(img1.GetPixels(), img1.Size);

            for (int x = 0; x < newImg.Size.Width; x++)
            {
                for (int y = 0; y < newImg.Size.Height; y++)
                {
                    if (img1.GetPixelColor(x, y) == img2.GetPixelColor(x, y)) //If pixels are the same
                    {
                        newImg.SetPixelColor(x, y, Image.Black); //set a black pixel
                    }
                    else
                    {
                        newImg.SetPixelColor(x, y, Image.White); //else, set a white pixel
                    }
                }
            }
            return newImg;
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:26,代码来源:Difference.cs

示例11: Generate

        public static Image Generate(Image image)
        {
            Image skeleton = new Image(image.GetPixels(), image.Size);

            DoubleStructure2D L1 = new DoubleStructure2D(
                                    new Structure2D(0, 0, 0,
                                                    0, 1, 0,
                                                    1, 1, 1),
                                    new Structure2D(1, 1, 1,
                                                    0, 0, 0,
                                                    0, 0, 0));

            DoubleStructure2D L2 = new DoubleStructure2D(
                                    new Structure2D(0, 0, 0,
                                                    1, 1, 0,
                                                    1, 1, 0),
                                    new Structure2D(0, 1, 0,
                                                    0, 0, 1,
                                                    0, 0, 0));

            DoubleStructure2D L3 = new DoubleStructure2D(
                                    new Structure2D(1, 0, 0,
                                                    1, 1, 0,
                                                    1, 0, 0),
                                    new Structure2D(0, 0, 1,
                                                    0, 0, 1,
                                                    0, 0, 1));

            DoubleStructure2D L4 = new DoubleStructure2D(
                                    new Structure2D(1, 1, 0,
                                                    1, 1, 0,
                                                    0, 0, 0),
                                    new Structure2D(0, 0, 0,
                                                    0, 0, 1,
                                                    0, 1, 0));

            DoubleStructure2D L5 = new DoubleStructure2D(
                                    new Structure2D(1, 1, 1,
                                                    0, 1, 0,
                                                    0, 0, 0),
                                    new Structure2D(0, 0, 0,
                                                    0, 0, 0,
                                                    1, 1, 1));

            DoubleStructure2D L6 = new DoubleStructure2D(
                                    new Structure2D(0, 1, 1,
                                                    0, 1, 1,
                                                    0, 0, 0),
                                    new Structure2D(0, 0, 0,
                                                    1, 0, 0,
                                                    0, 1, 0));

            DoubleStructure2D L7 = new DoubleStructure2D(
                                    new Structure2D(0, 0, 1,
                                                    0, 1, 1,
                                                    0, 0, 1),
                                    new Structure2D(1, 0, 0,
                                                    1, 0, 0,
                                                    1, 0, 0));

            DoubleStructure2D L8 = new DoubleStructure2D(
                                    new Structure2D(0, 0, 0,
                                                    0, 1, 1,
                                                    0, 1, 1),
                                    new Structure2D(0, 1, 0,
                                                    1, 0, 0,
                                                    0, 0, 0));

            int[,] currentImage;
            while (true)
            {
                currentImage = (int[,])skeleton.GetPixels().Clone();
                ApplyDoubleStructure(skeleton, L1);
                ApplyDoubleStructure(skeleton, L2);
                ApplyDoubleStructure(skeleton, L3);
                ApplyDoubleStructure(skeleton, L4);
                ApplyDoubleStructure(skeleton, L5);
                ApplyDoubleStructure(skeleton, L6);
                ApplyDoubleStructure(skeleton, L7);
                ApplyDoubleStructure(skeleton, L8);
                if (Toolbox.EqualPixels(currentImage, skeleton.GetPixels(), skeleton.Size)) break;
            }

            return skeleton;
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:85,代码来源:SkeletonByThinning.cs

示例12: ApplyDoubleStructure

        /// <summary>
        /// Apply the double structure. (Thinning)
        /// </summary>
        /// <param name="image"></param>
        /// <param name="structure"></param>
        private static void ApplyDoubleStructure(Image image, DoubleStructure2D structure)
        {
            int[,] currentPixels = image.GetPixels();
            int[,] newPixels = new int[image.Size.Width, image.Size.Height];

            //structure information
            int structureWidth = structure.StructureSize.Width;
            int structureHeight = structure.StructureSize.Height;
            int middelPixelIndexWidth = structureWidth / 2;
            int middelPixelIndexHeight = structureHeight / 2;

            //Loop through the image
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {

                    //Determin structure's position, based on current pixel
                    int structureStartPositionX = x - middelPixelIndexWidth;
                    int structureStartPositionY = y - middelPixelIndexHeight;

                    //variable to store the new values that are being calculated
                    bool pixelEnabled = true;

                    //checks if the structure isn't out of bounce
                    if ((structureStartPositionX < 0 || structureStartPositionY < 0) ||
                     (structureStartPositionX + structureWidth > image.Size.Width || structureStartPositionY + structureHeight > image.Size.Height))
                    {
                        newPixels[x, y] = Image.White;
                        continue;
                    }

                    //Loop through the structure
                    for (int k = 0; k < structureWidth; k++)
                    {
                        for (int l = 0; l < structureHeight; l++)
                        {
                            int pixelColor = image.GetPixelColor(structureStartPositionX + k, structureStartPositionY + l);

                            bool ForeGroundValue = structure.Foreground.GetValue(k, l);
                            bool BackGroundValue = structure.Background.GetValue(k, l);

                            if (ForeGroundValue && pixelColor == Image.Black) continue;
                            if (BackGroundValue && pixelColor == Image.White) continue;
                            if (!ForeGroundValue && !BackGroundValue) continue;

                            pixelEnabled = false;
                            break;

                        }
                    }
                    if(pixelEnabled)
                    {
                        pixelEnabled = true;
                    }
                    newPixels[x, y] = (pixelEnabled) ? Image.Black : Image.White; //sets new value

                }
            }

            Image newImage = Subtraction.ApplyBlackWhite(image, new Image(newPixels, image.Size));
            image.SetPixels(newImage.GetPixels());
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:68,代码来源:SkeletonByThinning.cs


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