private static IImageProcessingAlgorithm CreateAlgorithm(IImageProcessingAlgorithmTemplate template, Type algorithmType)
        {
            var algorithmConstructor = algorithmType.GetConstructor(new[] { template.GetType() });

            if (algorithmConstructor == null)
            {
                throw new AlgorithmCreationException(algorithmType);
            }

            var algorithmInstance = algorithmConstructor.Invoke(new object[] { template }) as IImageProcessingAlgorithm;

            if (algorithmInstance == null)
            {
                throw new AlgorithmCreationException(algorithmType);
            }

            return(algorithmInstance);
        }
        public IImageProcessingAlgorithm CreateInstance(IImageProcessingAlgorithmTemplate template, ImageModel imageModel)
        {
            var iImageProcessingAlgorithmTemplateType = typeof(IImageProcessingAlgorithm);
            var algorithmType = template.AlgorithmType;

            if (!(algorithmType.IsClass && !algorithmType.IsAbstract && iImageProcessingAlgorithmTemplateType.IsAssignableFrom(algorithmType)))
            {
                throw new AlgorithmCreationException(algorithmType);
            }

            template.ImageModel = imageModel;

            if (template is TwoPointNonUniformityCorrectionTemplate)
            {
                return(CreateTwoPointNonUniformityCorrectionTemplate((TwoPointNonUniformityCorrectionTemplate)template, algorithmType));
            }

            return(CreateAlgorithm(template, algorithmType));
        }