public BlobResult(Image<Gray, byte> image, int threshold, IntPtr maskImage,
			bool borderColor, bool findMoments)
		{
			detectedBlobs = GetBlobs(image, threshold, maskImage, borderColor, findMoments);
			numBlobs = detectedBlobs.Length;


		}
		public BlobResult(Image<Gray, byte> image, int threshold, bool findMoments)
		{
			if (image.IsROISet)
			{
				Image<Gray, byte> roiImage = new Image<Gray, byte>(image.ROI.Size);
				roiImage = image.Copy(image.ROI);
				detectedBlobs = GetBlobs(roiImage, threshold, IntPtr.Zero, false, findMoments);
			}
			else
				detectedBlobs = GetBlobs(image, threshold, IntPtr.Zero, false, findMoments);
			numBlobs = detectedBlobs.Length;
		}
		public void FilterByArea(int minArea, int maxArea)
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
				{
					detectedBlobs[i].Clear();
				}
				
				
			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}
		public void FilterByEccentricity(double maxEccentricity)
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Eccentricity < maxEccentricity)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Eccentricity < maxEccentricity)
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
					detectedBlobs[i].Clear();
			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}
		public void FilterByDistance(GTPoint initialLocation, int N)
		{
			if(N > numBlobs)
				return;

			BlobObject[] finalBlobs = new BlobObject[N];

			double[] distances = new double[numBlobs];
			int[] keys = new int[numBlobs];
			//Matrix<double> distances = new Matrix<double>(numBlobs, 1);
			GTPoint center;

			for (int i = 0; i < numBlobs; i++)
			{
				center = new GTPoint(detectedBlobs[i].CentroidX, detectedBlobs[i].CentroidY);
				distances[i] = Operations.Distance(center, new GTPoint(initialLocation));
				keys[i] = i;
			}

			Array.Sort(distances, keys);

			for (int i = 0; i < numBlobs; i++)
			{
				if (i < N)
					finalBlobs[i] = detectedBlobs[keys[i]];
				else
					detectedBlobs[keys[i]].Clear();
			}

			detectedBlobs = finalBlobs;
			numBlobs = N;

	
		}
		/// <summary>
		/// This methods eliminates the blobs that are exterior, i.e. those blobs
		/// that have pixels on the edge of the image
		/// </summary>
		public void EliminateExteriorBlobs()
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Exterior == 0)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Exterior == 0) 
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
				{
					detectedBlobs[i].Clear();
				}


			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}