Exemplo n.º 1
0
		public void TestHistogramNodeValue()
		{
			// Generates an array of 1 Frame with randomly filled Data
			YuvKA.VideoModel.Size testSize = new YuvKA.VideoModel.Size(5, 5);
			Frame[] inputs = { new Frame(testSize) };
			for (int x = 0; x < testSize.Width; x++) {
				for (int y = 0; y < testSize.Height; y++) {
					inputs[0][x, y] = new Rgb((byte)(x + y), (byte)(x + y), (byte)(x + y));
				}
			}

			// Generate Value HistogramNode once
			HistogramNode histNodeValue = new HistogramNode();
			histNodeValue.Type = HistogramType.Value;

			histNodeValue.Process(inputs, 0);

			// Calculate expected results independently from Histogram method.
			Color rgbValue;
			int value;
			int[] intData = new int[256];
			for (int x = 0; x < inputs[0].Size.Width; x++) {
				for (int y = 0; y < inputs[0].Size.Height; y++) {
					rgbValue = Color.FromArgb(inputs[0][x, y].R, inputs[0][x, y].G, inputs[0][x, y].B);
					value = (int)(rgbValue.GetBrightness() * 255);
					intData[value]++;
				}
			}
			int numberOfPixels = inputs[0].Size.Height * inputs[0].Size.Width;
			for (int i = 0; i < 256; i++) {
				Assert.Equal(histNodeValue.Data[i], (double)intData[i] / numberOfPixels);
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Creates a new HistogramViewMode with the given HistogramNode.
		/// </summary>
		public HistogramViewModel(HistogramNode nodeModel)
			: base(nodeModel, null)
		{
		}
Exemplo n.º 3
0
		public void TestHistogramNodeRGB()
		{
			// Generates an array of 1 Frame with randomly filled Data
			YuvKA.VideoModel.Size testSize = new YuvKA.VideoModel.Size(5, 5);
			Frame[] inputs = { new Frame(testSize) };
			for (int x = 0; x < testSize.Width; x++) {
				for (int y = 0; y < testSize.Height; y++) {
					inputs[0][x, y] = new Rgb((byte)(x + y), (byte)(x + y), (byte)(x + y));
				}
			}

			// Generate all RGB HistogramNode once
			HistogramNode histNodeR = new HistogramNode();
			histNodeR.Type = HistogramType.R;
			HistogramNode histNodeG = new HistogramNode();
			histNodeG.Type = HistogramType.G;
			HistogramNode histNodeB = new HistogramNode();
			histNodeB.Type = HistogramType.B;

			histNodeR.Process(inputs, 0);
			histNodeG.Process(inputs, 0);
			histNodeB.Process(inputs, 0);

			// Calculate expected results independently from Histogram methods.
			int[] value = new int[3];
			int[,] intData = new int[256, 3];
			for (int x = 0; x < inputs[0].Size.Width; x++) {
				for (int y = 0; y < inputs[0].Size.Height; y++) {
					value[0] = inputs[0][x, y].R;
					value[1] = inputs[0][x, y].G;
					value[2] = inputs[0][x, y].B;
					intData[value[0], 0]++;
					intData[value[1], 1]++;
					intData[value[2], 2]++;
				}
			}
			int numberOfPixels = inputs[0].Size.Height * inputs[0].Size.Width;
			for (int i = 0; i < 256; i++) {
				Assert.Equal(histNodeR.Data[i], (double)intData[i, 0] / numberOfPixels);
				Assert.Equal(histNodeG.Data[i], (double)intData[i, 1] / numberOfPixels);
				Assert.Equal(histNodeB.Data[i], (double)intData[i, 2] / numberOfPixels);
			}
		}