コード例 #1
0
ファイル: YuvPacked.cs プロジェクト: imintsystems/Kean
		public override float Distance(Draw.Image other)
		{
			float result = 0;
			if (other.IsNull())
				result = float.MaxValue;
			else if (!(other is YuvPacked))
				using (YuvPacked o = other.Convert<YuvPacked>())
					result = this.Distance(o);
			else if (this.Size != other.Size)
				using (YuvPacked o = other.ResizeTo(this.Size) as YuvPacked)
					result = this.Distance(o);
			else
			{
				for (int y = 0; y < this.Size.Height; y++)
					for (int x = 0; x < this.Size.Width; x++)
					{
						Color.Yuv c = this[x, y];
						Color.Yuv o = (other as YuvPacked)[x, y];
						if (c.Distance(o) > 0)
						{
							Color.Yuv maximum = o;
							Color.Yuv minimum = o;
							for (int otherY = Integer.Maximum(0, y - this.DistanceRadius); otherY < Integer.Minimum(y + 1 + this.DistanceRadius, this.Size.Height); otherY++)
								for (int otherX = Integer.Maximum(0, x - this.DistanceRadius); otherX < Integer.Minimum(x + 1 + this.DistanceRadius, this.Size.Width); otherX++)
									if (otherX != x || otherY != y)
									{
										Color.Yuv pixel = (other as YuvPacked)[otherX, otherY];
										if (maximum.Y < pixel.Y)
											maximum.Y = pixel.Y;
										else if (minimum.Y > pixel.Y)
											minimum.Y = pixel.Y;
										if (maximum.U < pixel.U)
											maximum.U = pixel.U;
										else if (minimum.U > pixel.U)
											minimum.U = pixel.U;
										if (maximum.V < pixel.V)
											maximum.V = pixel.V;
										else if (minimum.V > pixel.V)
											minimum.V = pixel.V;
									}
							float distance = 0;
							if (c.Y < minimum.Y)
								distance += Single.Squared(minimum.Y - c.Y);
							else if (c.Y > maximum.Y)
								distance += Single.Squared(c.Y - maximum.Y);
							if (c.U < minimum.U)
								distance += Single.Squared(minimum.U - c.U);
							else if (c.U > maximum.U)
								distance += Single.Squared(c.U - maximum.U);
							if (c.V < minimum.V)
								distance += Single.Squared(minimum.V - c.V);
							else if (c.V > maximum.V)
								distance += Single.Squared(c.V - maximum.V);
							result += Single.SquareRoot(distance) / 3;
						}
					}
				result /= this.Size.Length;
			}
			return result;
		}
コード例 #2
0
ファイル: Bgr.cs プロジェクト: imintsystems/Kean
		public override float Distance(Draw.Image other)
		{
			float result = 0;
			if (other.IsNull())
				result = float.MaxValue;
			else if (!(other is Bgr))
				using (Bgr o = other.Convert<Bgr>())
					result = this.Distance(o);
			else if (this.Size != other.Size)
				using (Bgr o = other.ResizeTo(this.Size) as Bgr)
					result = this.Distance(o);
			else
			{
				for (int y = 0; y < this.Size.Height; y++)
					for (int x = 0; x < this.Size.Width; x++)
					{
						Color.Bgr c = this[x, y];
						Color.Bgr o = (other as Bgr)[x, y];
						if (c.Distance(o) > 0)
						{
							Color.Bgr maximum = o;
							Color.Bgr minimum = o;
							for (int otherY = Integer.Maximum(0, y - this.DistanceRadius); otherY < Integer.Minimum(y + 1 + this.DistanceRadius, this.Size.Height); otherY++)
								for (int otherX = Integer.Maximum(0, x - this.DistanceRadius); otherX < Integer.Minimum(x + 1 + this.DistanceRadius, this.Size.Width); otherX++)
									if (otherX != x || otherY != y)
									{
										Color.Bgr pixel = (other as Bgr)[otherX, otherY];
										if (maximum.Blue < pixel.Blue)
											maximum.Blue = pixel.Blue;
										else if (minimum.Blue > pixel.Blue)
											minimum.Blue = pixel.Blue;
										if (maximum.Green < pixel.Green)
											maximum.Green = pixel.Green;
										else if (minimum.Green > pixel.Green)
											minimum.Green = pixel.Green;
										if (maximum.Red < pixel.Red)
											maximum.Red = pixel.Red;
										else if (minimum.Red > pixel.Red)
											minimum.Red = pixel.Red;
									}
							float distance = 0;
							if (c.Blue < minimum.Blue)
								distance += Single.Squared(minimum.Blue - c.Blue);
							else if (c.Blue > maximum.Blue)
								distance += Single.Squared(c.Blue - maximum.Blue);
							if (c.Green < minimum.Green)
								distance += Single.Squared(minimum.Green - c.Green);
							else if (c.Green > maximum.Green)
								distance += Single.Squared(c.Green - maximum.Green);
							if (c.Red < minimum.Red)
								distance += Single.Squared(minimum.Red - c.Red);
							else if (c.Red > maximum.Red)
								distance += Single.Squared(c.Red - maximum.Red);
							result += Single.SquareRoot(distance) / 3;
						}
					}
				result /= this.Size.Length;
			}
			return result;
		}
コード例 #3
0
ファイル: Monochrome.cs プロジェクト: imintsystems/Kean
		public override float Distance(Draw.Image other)
		{
			float result = 0;
			if (other.IsNull())
				result = float.MaxValue;
			else if (!(other is Monochrome))
				using (Monochrome o = other.Convert<Monochrome>())
					result = this.Distance(o);
			else if (this.Size != other.Size)
				using (Monochrome o = other.ResizeTo(this.Size) as Monochrome)
					result = this.Distance(o);
			else
			{
				for (int y = 0; y < this.Size.Height; y++)
					for (int x = 0; x < this.Size.Width; x++)
					{
						Color.Monochrome c = this[x, y];
						Color.Monochrome o = (other as Monochrome)[x, y];
						if (c.Distance(o) > 0)
						{
							Color.Monochrome maximum = o;
							Color.Monochrome minimum = o;
							for (int otherY = Integer.Maximum(0, y - 2); otherY < Integer.Minimum(y + 3, this.Size.Height); otherY++)
								for (int otherX = Integer.Maximum(0, x - 2); otherX < Integer.Minimum(x + 3, this.Size.Width); otherX++)
									if (otherX != x || otherY != y)
									{
										Color.Monochrome pixel = (other as Monochrome)[otherX, otherY];
										if (maximum.Y < pixel.Y)
											maximum.Y = pixel.Y;
										else if (minimum.Y > pixel.Y)
											minimum.Y = pixel.Y;
									}
							float distance = 0;
							if (c.Y < minimum.Y)
								distance += Single.Squared(minimum.Y - c.Y);
							else if (c.Y > maximum.Y)
								distance += Single.Squared(c.Y - maximum.Y);
							result += Single.SquareRoot(distance);
						}
					}
				result /= this.Size.Length;
			}
			return result;
		}