Beispiel #1
0
        public override Mat Quantize(Mat image)
        {
            // convert to gray values
            Mat imageGray = new Mat();

            if (image.NumberOfChannels > 1)
            {
                CvInvoke.CvtColor(image, imageGray, ColorConversion.Rgb2Gray);
            }
            else
            {
                imageGray = image;
            }

            // transform
            var imageWarped = new Mat(new Size(GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight), DepthType.Default, 1);

            CvInvoke.WarpPerspective(imageGray, imageWarped, Transform, new Size(GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight));

            if (_blurEnabled)
            {
                // gauss
                CvInvoke.GaussianBlur(imageWarped, imageWarped, new Size(3, 3), 0.6, 0.6);
            }

#if DEBUG
            if (NoiseLevel > 0.0)
            {
                imageWarped = imageWarped.AddNoise(NoiseLevel);
            }
#endif

            // threshold
            var imageBinarized = new Mat(new Size(GameBoyConstants.ScreenWidth, GameBoyConstants.ScreenHeight), DepthType.Default, 1);
            CvInvoke.AdaptiveThreshold(imageWarped, imageBinarized, _thresholdMaxValue, _thresholdAdaptiveThresholdType, _thresholdType, ThresholdBlockSize, ThresholdConstant);

            return(imageBinarized);
        }