Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just send your 'Image' to BuildPixelArray function and then call the FindRegions. After that the 'colors' variable will be holding your colors list and pixel coordinates in every list member.</p> <p>I've copied the source from one of my projects, there may be some undefined variables or syntax erors.</p> <pre><code> public class ImageProcessing{ private int[,] pixelArray; private int imageWidth; private int imageHeight; List&lt;MyColor&gt; colors; public void BuildPixelArray(ref Image myImage) { imageHeight = myImage.Height; imageWidth = myImage.Width; pixelArray = new int[imageWidth, imageHeight]; Rectangle rect = new Rectangle(0, 0, myImage.Width, myImage.Height); Bitmap temp = new Bitmap(myImage); BitmapData bmpData = temp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int remain = bmpData.Stride - bmpData.Width * 3; unsafe { byte* ptr = (byte*)bmpData.Scan0; for (int j = 15; j &lt; bmpData.Height; j++) { for (int i = 0; i &lt; bmpData.Width; i++) { pixelArray[i, j] = ptr[0] + ptr[1] * 256 + ptr[2] * 256 * 256; ptr += 3; } ptr += remain; } } temp.UnlockBits(bmpData); } public void FindRegions() { colors = new List&lt;MyColor&gt;(); for (int i = 0; i &lt; imageWidth; i++) { for (int j = 0; j &lt; imageHeight; j++) { int tmpColorValue = pixelArray[i, j]; MyColor tmp = new MyColor(tmpColorValue); if (colors.Contains(tmp)) { MyColor tmpColor = (from p in colors where p.colorValue == tmpColorValue select p).First(); tmpColor.pointList.Add(new MyPoint(i, j)); } else { tmp.pointList.Add(new MyPoint(i, j)); colors.Add(tmp); } } } } } public class MyColor : IEquatable&lt;MyColor&gt; { public int colorValue { get; set; } public List&lt;MyPoint&gt; pointList = new List&lt;MyPoint&gt;(); public MyColor(int _colorValue) { colorValue = _colorValue; } public bool Equals(MyColor other) { if (this.colorValue == other.colorValue) { return true; } return false; } } public class MyPoint { public int xCoord { get; set; } public int yCoord { get; set; } public MyPoint(int _xCoord, int _yCoord) { xCoord = _xCoord; yCoord = _yCoord; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload