protected void Count_Pixels_On_A_Line_Change_It_To_Red(int j, Line line) { for (int i = line.FirstPixel; i <= line.LastPixel; i++) { if (CompareColors(image.GetPixel(i, j), Color.Black)) { //To count black pixel, then set it to red SizeOfShape++; image.SetPixel(i, j, Color.Red); //To find out if a black pixel on top of red one, then store it to BlackPixelList if (j > 0 && CompareColors(image.GetPixel(i, j - 1), Color.Black)) { var cell = new BlackPixel(i, j - 1); BlackPixelList.Add(cell); } if (BlackPixelList.Count > 0) { //To find out if this pixel is in BlackPixelList, then remove it var cell = new BlackPixel(i, j); if (BlackPixelList.Contains(cell)) { BlackPixelList.Remove(cell); } } } //End when it is while pixel else if (CompareColors(image.GetPixel(i, j), Color.White)) { break; } } }
//The size of a shape is the number of pixels in a shape //To find out the maximum size of shape in a bitmap - Shape0.bmp public int GetMaxSizeOfShape() { LoadImage(); var sizeList = new MicrosoftResearch.Infer.Collections.SortedSet <int>(); int size = 0; var pict = image.Size; int shapeNumber = 1; for (int j = 0; j < pict.Height; j++) { for (int i = 0; i < pict.Width; i++) { int currShapeSize = FindShapeSize(i, j); if (currShapeSize > 0 && !sizeList.Contains(currShapeSize)) { sizeList.Add(currShapeSize); string filename = String.Format("{0}_{1}_{2}.{3}", FileName, shapeNumber, currShapeSize, FileExt); shapeNumber++; Save(filename); } } } if (sizeList.Count > 0) { size = sizeList[sizeList.Count - 1]; } return(size); }
//The size of a shape is the number of pixels in a shape //To find out the maximum size of shape in a bitmap - Shape0.bmp public int GetMaxSizeOfShape() { LoadImage(); //To store size of shapes var sizeList = new MicrosoftResearch.Infer.Collections.SortedSet <int>(); //To store black pixels on top of red lines BlackPixelList = new MicrosoftResearch.Infer.Collections.SortedSet <BlackPixel>(new SortedByBlackPixel()); int size = 0; var pict = image.Size; int shapeNumber = 1; int i = 0; int j = 0; bool bFound = false; do { bFound = Fine_A_Black_Pixel(ref i, ref j); if (bFound) { int currShapeSize = FindShapeSize(i, j); if (currShapeSize > 0 && !sizeList.Contains(currShapeSize)) { sizeList.Add(currShapeSize); string filename = String.Format("{0}_{1}_{2}.{3}", FileName, shapeNumber, currShapeSize, FileExt); shapeNumber++; Save(filename); } } } while (bFound); if (sizeList.Count > 0) { size = sizeList[sizeList.Count - 1]; } return(size); }