public static Utils.RectData[] TwoPass(Bitmap labels, Bitmap srcBitmap, Tree root, int background)
		{
			DisjointSets linked = new DisjointSets(root.Width * root.Height);
			int bottom = root.Top + root.Height;
			int right = root.Left + root.Width;

			int numelements = IdentifyComponents(labels, srcBitmap, linked, root, root.GetHashCode(), bottom, right, background);

			//Run the second pass through the image to label each component
			//and create bounding rectangles
			LabelComponentsAndSetBoundingBoxes(labels, linked, root.Top, root.Left, bottom, right, background);


			return GetRectsFromLabeledImage(labels, srcBitmap, numelements, root.Top, root.Left, bottom, right, background);
		}
Example #2
0
		public void SetForeground(Tree node, Bitmap image, Bitmap foreground) {

			Ptype ptype = (Ptype)node["ptype"];
			Region interiorregion = ptype.Region("interior");

			foreground.WriteBlock(Utils.BACKGROUND, node);

			if (interiorregion != null)
			{
				IBoundingBox interior = GetInteriorBox(node, ptype);

				int top = interior.Top;
				int left = interior.Left;
				int leftdepth = ptype.Region("left").Bitmap.Width;

				int bottom = interior.Top + interior.Height;
				int right = interior.Left + interior.Width;

				for(int row = top; row < bottom; row++)
				{
					for (int col = left; col < right; col++)
					{
						int backgroundValue = interiorregion.Bitmap[(row - top) % interiorregion.Bitmap.Height,
							(col - node.Left - leftdepth) % interiorregion.Bitmap.Width];

						if (backgroundValue != image[row, col])
							foreground[row, col] = node.GetHashCode();
					}
				}

				//We looked at the features and might have counted them as foreground.
				EraseFeaturesFromforeground(foreground, node, ptype);
			}
		}