本文整理汇总了C#中Image.GetPixelColor方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetPixelColor方法的具体用法?C# Image.GetPixelColor怎么用?C# Image.GetPixelColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.GetPixelColor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public override void Apply(Image image)
{
int totalGrayValue = 0;//Start counter
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
totalGrayValue += image.GetPixelColor(x, y);
}
}
<<<<<<< HEAD
=======
int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (Image.Size.Width * Image.Size.Height) : 0;
>>>>>>> refs/remotes/origin/Koen-Edges
int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (image.Size.Width * image.Size.Height) : 0;
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
int pixelColor = image.GetPixelColor(x, y); // Get the pixel color at coordinate (x,y)
//int threshold = 186;
int updatedColor = (pixelColor > AverageGrayValue) ? Image.White : Image.Black; // black or white
image.SetPixelColor(x, y, updatedColor); // Set the new pixel color at coordinate (x,y)
}
}
}
示例2: Apply
public static Image Apply(Image Image, Image Image2)
{
for (int x = 0; x < Image.Size.Width; x++)
{
for (int y = 0; y < Image.Size.Height; y++)
{
if (Image.GetPixelColor(x, y) > Image2.GetPixelColor(x, y))
{
Image.SetPixelColor(x,y,Image2.GetPixelColor(x, y));
}
}
}
return Image;
}
示例3: Apply
/// <summary>
/// Creates a new image based on the min values of the two given images
/// </summary>
/// <param name="Image">first image</param>
/// <param name="Image2">second image</param>
/// <returns>image with lowest values of two input 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++)
{
if (Image.GetPixelColor(x, y) > Image2.GetPixelColor(x, y))
{
newImg.SetPixelColor(x,y,Image2.GetPixelColor(x, y));
}
}
}
return newImg;
}
示例4: Apply
/// <summary>
/// Turns the image into its negative
/// </summary>
/// <param name="image">Image that gets the operation applied to</param>
public override void Apply(Image image)
{
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
image.SetPixelColor(x, y, (Image.TotalGrayValues - 1) - (image.GetPixelColor(x, y))); //Inverse by subtracting the current pixel value of the max gray value
}
}
}
示例5: 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);
}
示例6: Calculate
/// <summary>
/// Calculate the Area of an item/object
/// - loop through each pixel and count if its a black pixel
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
public static int Calculate(Image image)
{
int counter = 0;
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
if (image.GetPixelColor(x, y) == Image.Black) counter++;
}
}
return counter;
}
示例7: 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;
}
示例8: Apply
public static Image Apply(Image Image, Image Image2)
{
int additive_value = 0;
for (int x = 0; x < Image.Size.Width; x++)
{
for (int y = 0; y < Image.Size.Height; y++)
{
additive_value = (Image.GetPixelColor(x, y)- Image2.GetPixelColor(x, y));
if (additive_value < 0) additive_value = 0;
Image.SetPixelColor(x, y, additive_value);
}
}
return Image;
}
示例9: 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;
}
示例10: Apply
/// <summary>
/// Apply this operation to the image
/// </summary>
/// <param name="image">Image that gets the operation applied to</param>
public override void Apply(Image image)
{
int totalGrayValue = 0;//Start counter
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
totalGrayValue += image.GetPixelColor(x, y);
}
}
int AverageGrayValue = (totalGrayValue > 0) ? totalGrayValue / (image.Size.Width * image.Size.Height) : 0;
for (int x = 0; x < image.Size.Width; x++)
{
for (int y = 0; y < image.Size.Height; y++)
{
int pixelColor = image.GetPixelColor(x, y); // Get the pixel color at coordinate (x,y)
//AverageGrayValue = 210;
int updatedColor = (pixelColor > AverageGrayValue) ? Image.White : Image.Black; // black or white
image.SetPixelColor(x, y, updatedColor); // Set the new pixel color at coordinate (x,y)
}
}
}
示例11: 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;
}
示例12: 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;
}
示例13: 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());
}