當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。