using System;
using OpenCvSharp;

namespace OpenCVStudio_v0
{
    public sealed class FastNlMeansDenoisingExecutor : IImageBlockExecutor
    {
        public string BlockType => "FastNlMeansDenoising";

        public Mat Execute(Mat input, ProjectBlock block, ProjectManager projectManager)
        {
            if (input == null)
                throw new ArgumentNullException(nameof(input));
            if (input.Empty())
            {
                throw new InvalidOperationException("FastNlMeansDenoising: изображение пустое.");
            }
            float h = projectManager.GetBlockParameter(block.Id, "H", 10f);
            int templateWindowSize = projectManager.GetBlockParameter(block.Id, "TemplateWindowSize", 7);
            int searchWindowSize = projectManager.GetBlockParameter(block.Id, "SearchWindowSize", 21);
            Mat result = new Mat();
            Cv2.FastNlMeansDenoising(input, result, h, templateWindowSize, searchWindowSize);
            return result;
        }
    }
}