Exemplo n.º 1
0
		/// <summary>
		/// Computes the avarange grayscale value of a certain bitmap region.
		/// </summary>
		/// <param name="grayscaleBitmap">A grayscale bitmap.</param>
		/// <param name="rectangle">Defines a region.</param>
		/// <returns></returns>
		public static int GetAvarageGrayscale(Graphic grayscaleBitmap, System.Drawing.Rectangle rectangle)
		{
			int average=0;

			try
			{
				for(int y=rectangle.Y; y<rectangle.Bottom; y++)
					for(int x=rectangle.X; x<rectangle.Right; x++)
					{
						average+=grayscaleBitmap.GetPixel(x, y).R;
					}
			}
			catch(System.Exception ex)
			{
				return 128;
			}

			return average/(rectangle.Width*rectangle.Height);
		}
Exemplo n.º 2
0
		/////////////////////////////////////////////////////////////////
		// noch mehr Bildverarbeitung
		/////////////////////////////////////////////////////////////////
		public double Compare(Graphic ImageToCompare, uint Threshold)
		{
			if(ImageToCompare==null) throw new Exception("Image is null");
			if(Width!=ImageToCompare.Width) throw new Exception("Image have different sizes");
			if(Height!=ImageToCompare.Height) throw new Exception("Image have different sizes");
			if(channelFormat!=ImageToCompare.channelFormat) throw new Exception("Image have different formats");

			uint divergency=0;

			for(uint y=0; y<Width; y++)
			{
				for(uint x=0; x<Height; x++)
				{
					Color picA=GetPixel(x, y);
					Color picB=ImageToCompare.GetPixel(x, y);

					int dif=0;

                    dif+=System.Math.Abs(picA.R-picB.R);
                    dif+=System.Math.Abs(picA.G-picB.G);
                    dif+=System.Math.Abs(picA.B-picB.B);
					dif/=3;

					if(dif>Threshold) divergency++;
				}
			}

			//Gibt in % zurück wie stark die Bilder von einander abweichen
			//0 % == Bilder sind Identisch
			return (double)(100*(divergency/(double)(Width*Height)));
		}