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


C# Image.GetPixelColor方法代码示例

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


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

示例1: g

        /*

            "For image enhancement purposes, it is often useful to apply a remapping g(x) that
            makes the histogram “flat”, i.e., remaps the grey values so that each value occurs an
            equal number of times in the image. This is called histogram equalization. The idea behind
            it is that the available image contrast is used optimally."

                - Digital and medical Imgae Processing by Twan maintz, update 11/2005, page 59

        */
        /// <summary>
        /// Apply the histogram equalization
        /// </summary>
        /// <param name="image"></param>
        public override void Apply(Image image)
        {
            //h(v) = default pixel distribution
            int[] h = new int[Image.TotalGrayValues];
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    int pixelColor = image.GetPixelColor(x, y);
                    h[pixelColor] = h[pixelColor] + 1; //Add one to this bin
                }
            }

            //c(v) = added pixel distribution
            int[] c = new int[Image.TotalGrayValues];
            int counter = 0;
            for (int i = 0; i < Image.TotalGrayValues; i++)
            {
                //We are checking the amount of pixels of the current gray value, and add those to the total counter.
                counter += h[i];
                //We set the new value to the c(v) list
                c[i] = counter;
            }

            //We calculate the desired pixesl per bin:
            float totalPixels = image.Size.Width * image.Size.Height;
            float idealPixelsPerBin = totalPixels / ((float)Image.TotalGrayValues);

            //g(v) = the new mapping for the image's pixels. So this array holds the new positions.
            int[] g = new int[Image.TotalGrayValues];
            for (int i = 0; i < Image.TotalGrayValues; i++)
            {
                int result = (int)(c[i] / idealPixelsPerBin + 0.5f) - 1; //these two magic numbers are part of the formula
                g[i] = Math.Max(0, result); //Make all negative numbers zero
            }

            //Remap image:
            int[,] resultAfterRemap = new int[image.Size.Width, image.Size.Height];
            for (int x = 0; x < image.Size.Width; x++)
            {
                for (int y = 0; y < image.Size.Height; y++)
                {
                    int originalPixel = image.GetPixelColor(x, y); //Get pixel at coordinate
                    int remapPixel = g[originalPixel]; //Find in remap list, which pixel this value should get
                    resultAfterRemap[x,y] = remapPixel; //Place this new value pixel in the temporary list
                }
            }
            image.SetPixels(resultAfterRemap);//Overwrite image with new values
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:63,代码来源:HistogramEqualization.cs

示例2: CalculateEmptyRowsFromRight

 private int CalculateEmptyRowsFromRight(Image image)
 {
     //CalculateEmptyRowsFromRight:
     for (int x = image.Size.Width; x > 0; x--)
     {
         for (int y = 0; y < image.Size.Height; y++)
         {
             if (image.GetPixelColor(x - 1 /* -1 to get right index */, y) != Image.White)
             {
                 return image.Size.Width - x;
             }
         }
     }
     return 0;
 }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:15,代码来源:Object.cs

示例3: CalculateEmptyRowsFromLeft

 private int CalculateEmptyRowsFromLeft(Image image)
 {
     //CalculateEmptyRowsFromLeft:
     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)
             {
                 return x;
             }
         }
     }
     return image.Size.Width;
 }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:15,代码来源:Object.cs

示例4: CalculateEmptyRowsFromBottom

 private int CalculateEmptyRowsFromBottom(Image image)
 {
     //CalculateEmptyRowsFromBottom:
     for (int y = image.Size.Height; y > 0; y--)
     {
         for (int x = 0; x < image.Size.Width; x++)
         {
             if (image.GetPixelColor(x, y - 1 /* -1 to get right index */) != Image.White)
             {
                 return image.Size.Height - y;
             }
         }
     }
     return 0;
 }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:15,代码来源:Object.cs

示例5: Apply

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

            //int[,] currentPixelsImg1 = img1.GetPixels();
            //int[,] currentPixelsImg2 = img2.GetPixels();
            //int[,] newPixels = new int[img1.Size.Width, img1.Size.Height];

            for (int x = 0; x < img1.Size.Width; x++)
            {
                for (int y = 0; y < img1.Size.Height; y++)
                {
                    if (img1.GetPixelColor(x, y) == img2.GetPixelColor(x, y))
                    {
                        img1.SetPixelColor(x, y, 0);
                    }
                    else
                    {
                        img1.SetPixelColor(x, y, 255);
                    }
                }
            }
            return img1;
        }
开发者ID:jianjia93,项目名称:ImageProcessing,代码行数:24,代码来源:Difference.cs

示例6: Trim

        /// <summary>
        /// Trim image:
        /// Use the information while trimming to determine the x and y values on original canvas
        /// </summary>
        /// <param name="image"></param>
        private void Trim(Image image)
        {
            int amountOfEmptyRowsTop = Math.Max(CalculateEmptyRowsFromTop(image) - 1, 0); //Removing one, so we always keep 1 empty space around the images.
            int amountOfEmptyRowsBot = Math.Max(CalculateEmptyRowsFromBottom(image) - 1, 0);
            int amountOfEmptyRowsLeft = Math.Max(CalculateEmptyRowsFromLeft(image) - 1, 0);
            int amountOfEmptyRowsRight = Math.Max(CalculateEmptyRowsFromRight(image) - 1, 0);

            //Create new image:
            int newImageHeight = image.Size.Height - amountOfEmptyRowsTop - amountOfEmptyRowsBot;
            int newImageWidth = image.Size.Width - amountOfEmptyRowsLeft - amountOfEmptyRowsRight;
            int[,] newImage = new int[newImageWidth, newImageHeight];
            for (int y = 0; y < newImageHeight; y++)
            {
                for (int x = 0; x < newImageWidth; x++)
                {
                    newImage[x, y] = image.GetPixelColor(x + amountOfEmptyRowsLeft, y + amountOfEmptyRowsTop);
                }
            }
            Image image2 = new Image(newImage, new System.Drawing.Size(newImageWidth, newImageHeight));

            //Set local variables:
            this.image = image2;
            this.xOnOriginalImage = amountOfEmptyRowsLeft;
            this.yOnOriginalImage = amountOfEmptyRowsTop;
        }
开发者ID:basterbogt,项目名称:ImageProcessing,代码行数:30,代码来源:Item.cs


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