public void TestWeightedAveragedMerge() { YuvKA.VideoModel.Size testSize = new YuvKA.VideoModel.Size(5, 5); Frame[] inputs = { new Frame(testSize), new Frame(testSize), 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)); inputs[1][x, y] = new Rgb((byte)(x * y), (byte)(x * y), (byte)(x * y)); inputs[2][x, y] = new Rgb((byte)(x ^ y), (byte)(x ^ y), (byte)(x ^ y)); } } WeightedAveragedMergeNode node = new WeightedAveragedMergeNode(); Node.Input testInput = new Node.Input(); node.Inputs.Add(testInput); ObservableCollection <double> testGetWeights = node.Weights; // node.Weights is null -> create weights with default value 1.0 Assert.Contains(1.0, testGetWeights); node.Inputs.Add(testInput); node.Weights[0] = 0; node.Weights[1] = 0.25; node.Inputs.Add(testInput); testGetWeights = node.Weights; // node.Weights has not enough values -> fill up missing weights with 1.0 Assert.Contains(1.0, testGetWeights); Frame[] result = node.Process(inputs, 0); for (int x = 0; x < testSize.Width; x++) { for (int y = 0; y < testSize.Height; y++) { Assert.Equal((byte)((0.25 * inputs[1][x, y].R + inputs[2][x, y].R) / 1.25), result[0][x, y].R); Assert.Equal((byte)((0.25 * inputs[1][x, y].G + inputs[2][x, y].G) / 1.25), result[0][x, y].G); Assert.Equal((byte)((0.25 * inputs[1][x, y].B + inputs[2][x, y].B) / 1.25), result[0][x, y].B); } } WeightedAveragedMergeNode secondNode = new WeightedAveragedMergeNode { Weights = { 0.75, 0.75, 0.75 } }; node.Weights[0] = node.Weights[1] = node.Weights[2] = 0.5; result = node.Process(inputs, 0); Frame[] secondResult = secondNode.Process(inputs, 0); for (int x = 0; x < testSize.Width; x++) { for (int y = 0; y < testSize.Height; y++) { Assert.Equal(result[0][x, y].R, secondResult[0][x, y].R); Assert.Equal(result[0][x, y].G, secondResult[0][x, y].G); Assert.Equal(result[0][x, y].B, secondResult[0][x, y].B); } } }
public void RedrawOnTickSetBack() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.Process(inputs, 0); diaNode.Process(inputs, 1); Assert.Equal(diaNode.Graphs[0].Data.Count, 2); diaNode.Process(inputs, 0); Assert.Equal(diaNode.Graphs[0].Data.Count, 1); }
public void TestNoDrawingIfDiagramNodeNotEnabled() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.IsEnabled = false; diaNode.Process(inputs, 0); Assert.Empty(diaNode.Graphs[0].Data); }
public void ResetReferenceWithExistingGraphControls() { // Set the GraphTypes IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() }; // Get the parent PipelineVM and add DiagramNode var vm = MainViewModelTest.GetInstance().PipelineViewModel; var node = new NodeViewModel(new DiagramNode(), vm); vm.Nodes.Add(node); vm.Parent.Model.Graph.AddNode(node.Model); var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model); // Add Input Node for DiagramNode with 3 Outputs. var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); var inputs = sourceNode.Process(null, 0); // Add reference video to node. var reference = new Node.Input { Source = sourceNode.Outputs[0] }; DVM.NodeModel.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. var video = new Node.Input { Source = sourceNode.Outputs[1] }; DVM.NodeModel.Inputs.Add(video); var altRef = new Node.Input { Source = sourceNode.Outputs[2] }; DVM.NodeModel.Inputs.Add(altRef); DVM.Reference = DVM.Videos.ElementAt(0); DVM.ChosenVideo = DVM.Videos.ElementAt(1); DVM.AddGraph(); var dgvm = DVM.Graphs.Single(); // ChosenType = PixelDifference dgvm.CurrentType = dgvm.AvailableTypes.ElementAt(0); // porcess one frame with first reference DVM.NodeModel.ProcessCore(inputs, 0); DVM.Handle(null); DVM.Reference = DVM.Videos.ElementAt(2); // porcess one frame with second reference DVM.NodeModel.ProcessCore(inputs, 1); DVM.Handle(null); Assert.Equal(dgvm.AvailableTypes.ElementAt(0).Model.Process(inputs[1], inputs[0]), dgvm.Model.Data[0].Value); Assert.Equal(dgvm.AvailableTypes.ElementAt(0).Model.Process(inputs[1], inputs[2]), dgvm.Model.Data[1].Value); }
public void CanDeleteLine() { // Set the GraphTypes IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() }; // Get the parent PipelineVM and add DiagramNode var vm = MainViewModelTest.GetInstance().PipelineViewModel; var node = new NodeViewModel(new DiagramNode(), vm); vm.Nodes.Add(node); vm.Parent.Model.Graph.AddNode(node.Model); var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model); // Add Input Node for DiagramNode with 3 Outputs. var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); var inputs = sourceNode.Process(null, 0); // Add reference video to node. var reference = new Node.Input { Source = sourceNode.Outputs[0] }; DVM.NodeModel.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. var video = new Node.Input { Source = sourceNode.Outputs[1] }; DVM.NodeModel.Inputs.Add(video); var annVid = new Node.Input { Source = sourceNode.Outputs[2] }; DVM.NodeModel.Inputs.Add(annVid); DVM.Reference = DVM.Videos.ElementAt(0); DVM.ChosenVideo = DVM.Videos.ElementAt(1); DVM.AddGraph(); var dgvm = DVM.Graphs.Single(); // Set the ChosenType of the DiagramGraphViewModel to PixelDifference dgvm.CurrentType = dgvm.AvailableTypes.First(); Assert.NotEmpty(DVM.Lines); Assert.NotEmpty(DVM.NodeModel.Graphs); DVM.DeleteGraph(dgvm); Assert.Empty(DVM.Lines); Assert.Empty(DVM.NodeModel.Graphs); }
public Node.Input AddInput(Node.Output source) { var input = new Node.Input { Source = source }; Model.Inputs.Add(input); inputs.Add(new InOutputViewModel(input, this)); NotifyOfPropertyChange(() => Inputs); return(input); }
public void CannotAddDgvmWithoutChosenVid() { // Set the GraphTypes IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() }; // Get the parent PipelineVM and add DiagramNode var vm = MainViewModelTest.GetInstance().PipelineViewModel; var node = new NodeViewModel(new DiagramNode(), vm); vm.Nodes.Add(node); vm.Parent.Model.Graph.AddNode(node.Model); var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model); // Add Input Node for DiagramNode with 3 Outputs. var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); var inputs = sourceNode.Process(null, 0); // Add reference video to node. var reference = new Node.Input { Source = sourceNode.Outputs[0] }; DVM.NodeModel.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. var video = new Node.Input { Source = sourceNode.Outputs[1] }; DVM.NodeModel.Inputs.Add(video); var altRef = new Node.Input { Source = sourceNode.Outputs[2] }; DVM.NodeModel.Inputs.Add(altRef); DVM.Reference = DVM.Videos.ElementAt(0); // No video chosen. Assert.False(DVM.CanAddGraph); }
public void ShowOnlyAvailableTypes() { // Set the GraphTypes IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff(), new DecisionDiff(), new IntraBlockFrequency(), new PeakSignalNoiseRatio() }; // Get the parent PipelineVM and add DiagramNode var vm = MainViewModelTest.GetInstance().PipelineViewModel; var node = new NodeViewModel(new DiagramNode(), vm); vm.Nodes.Add(node); vm.Parent.Model.Graph.AddNode(node.Model); var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model); // Add Input Node for DiagramNode with 3 Outputs. var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); var inputs = sourceNode.Process(null, 0); // Add reference video to node. var reference = new Node.Input { Source = sourceNode.Outputs[0] }; DVM.NodeModel.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. var video = new Node.Input { Source = sourceNode.Outputs[1] }; DVM.NodeModel.Inputs.Add(video); var annVid = new Node.Input { Source = sourceNode.Outputs[2] }; DVM.NodeModel.Inputs.Add(annVid); DVM.ChosenVideo = DVM.Videos.ElementAt(1); DVM.AddGraph(); var dgvmNoRefNoLog = DVM.Graphs.Last(); Assert.False(dgvmNoRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference || type.Model.DependsOnLogfile)); sourceNode.SettableOutputHasLogfile = true; DVM.ChosenVideo = DVM.Videos.ElementAt(2); DVM.AddGraph(); Assert.NotNull(DVM.Graphs); var dgvmLogNoRef = DVM.Graphs.Last(); Assert.False(dgvmLogNoRef.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference)); Assert.True(dgvmLogNoRef.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile)); sourceNode.SettableOutputHasLogfile = false; DVM.Reference = DVM.Videos.ElementAt(0); DVM.ChosenVideo = DVM.Videos.ElementAt(1); DVM.AddGraph(); var dgvmLoggedRefNoLog = DVM.Graphs.Last(); Assert.True(dgvmLoggedRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference)); Assert.False(dgvmLoggedRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile)); sourceNode.SettableOutputHasLogfile = true; DVM.ChosenVideo = DVM.Videos.ElementAt(2); DVM.AddGraph(); var dgvmLoggedRefLog = DVM.Graphs.Last(); Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference)); Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile)); Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnAnnotatedReference)); }
public void TestDiagramNode() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); Node.Input annVid = new Node.Input(); annVid.Source = sourceNode.Outputs[2]; diaNode.Inputs.Add(annVid); // Generate and add all GraphTypes to DiagramGraph once. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); DiagramGraph pseudoNoiseRatio = new DiagramGraph(); pseudoNoiseRatio.Video = video; pseudoNoiseRatio.Type = new PeakSignalNoiseRatio(); DiagramGraph inBlFreq = new DiagramGraph(); inBlFreq.Video = annVid; inBlFreq.Type = new IntraBlockFrequency(); DiagramGraph decDiff = new DiagramGraph(); decDiff.Video = annVid; decDiff.Type = new DecisionDiff(); DiagramGraph art = new DiagramGraph(); art.Video = video; art.Type = new Artifacts(); diaNode.Graphs.Add(pixDiff); diaNode.Graphs.Add(pseudoNoiseRatio); diaNode.Graphs.Add(inBlFreq); diaNode.Graphs.Add(decDiff); diaNode.Graphs.Add(art); diaNode.Process(inputs, 0); // Calculate expected results independently from DiagramGraph methods. double mse = 0.0; double pixDifference = 0.0; double intrablocks = 0.0; double artifacts = 0.0; for (int x = 0; x < inputs[0].Size.Width; x++) { for (int y = 0; y < inputs[0].Size.Height; y++) { pixDifference += Math.Abs(inputs[0][x, y].R - inputs[1][x, y].R) + Math.Abs(inputs[0][x, y].G - inputs[1][x, y].G) + Math.Abs(inputs[0][x, y].B - inputs[1][x, y].B); mse += Math.Pow(((inputs[0][x, y].R + inputs[0][x, y].G + inputs[0][x, y].B) - (inputs[1][x, y].R + inputs[1][x, y].G + inputs[1][x, y].B)), 2); var difference = Math.Abs(inputs[0][x, y].R - inputs[1].GetPixelOrBlack(x, y).R); difference += Math.Abs(inputs[0][x, y].G - inputs[1].GetPixelOrBlack(x, y).G); difference += Math.Abs(inputs[0][x, y].B - inputs[1].GetPixelOrBlack(x, y).B); if (difference >= 40) { artifacts += 1; } } } foreach (MacroblockDecision d in ((AnnotatedFrame)inputs[2]).Decisions) { if (d.PartitioningDecision == MacroblockPartitioning.Intra16x16 | d.PartitioningDecision == MacroblockPartitioning.Intra4x4 | d.PartitioningDecision == MacroblockPartitioning.Intra8x8 | d.PartitioningDecision == MacroblockPartitioning.IntraPCM) { intrablocks++; } } double decDifference = 0.0; if (((AnnotatedFrame)inputs[0]) is AnnotatedFrame && ((AnnotatedFrame)inputs[2]) is AnnotatedFrame && ((AnnotatedFrame)inputs[0]).Size.Height == ((AnnotatedFrame)inputs[2]).Size.Height && ((AnnotatedFrame)inputs[0]).Size.Width == ((AnnotatedFrame)inputs[2]).Size.Width) { AnnotatedFrame annFrame = ((AnnotatedFrame)inputs[0]); AnnotatedFrame annRef = ((AnnotatedFrame)inputs[2]); for (int i = 0; i < annFrame.Decisions.GetLength(0); i++) { for (int j = 0; j < annFrame.Decisions.GetLength(1); j++) { if (annFrame.Decisions[i, j].PartitioningDecision == annRef.Decisions[i, j].PartitioningDecision) { decDifference++; } } } decDifference /= annFrame.Decisions.Length; decDifference *= 100; } intrablocks = 100 * intrablocks / ((AnnotatedFrame)inputs[2]).Decisions.Length; pixDifference = 100 * pixDifference / (765 * inputs[0].Size.Height * inputs[0].Size.Width); mse *= (double)1 / (3 * inputs[1].Size.Height * inputs[1].Size.Width); double psnr; if (mse == 0.0) { psnr = 0.0; } psnr = 10 * Math.Log10((Math.Pow((Math.Pow(2, 24) - 1), 2)) / mse); artifacts = 100 * artifacts / (inputs[0].Size.Height * inputs[0].Size.Width); Assert.Equal(pixDifference, diaNode.Graphs[0].Data[0].Value); Assert.Equal(psnr, diaNode.Graphs[1].Data[0].Value); Assert.Equal(intrablocks, diaNode.Graphs[2].Data[0].Value, 7); Assert.Equal(decDifference, diaNode.Graphs[3].Data[0].Value, 7); Assert.Equal(artifacts, diaNode.Graphs[4].Data[0].Value, 7); }
/// <summary> /// Generates the name of a Video by adding a number and its source node. /// </summary> public string GetVideoName(Node.Input input) { return("Input " + (NodeModel.Inputs.IndexOf(input) + 1) + " | " + (input.Source == null ? "" : input.Source.Node.Name)); }