Esempio n. 1
0
        public EffectiveBitmap ProcessHaar(EffectiveBitmap image, bool isRevert, int layers)
        {
            var haarColors = new HaarColor[image.Height, image.Width];

            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    var color     = image.GetPixel(i, j);
                    var haarColor = new HaarColor(color);
                    haarColors[j, i] = haarColor;
                }
            }

            if (!isRevert)
            {
                FWT(haarColors, layers);
            }
            else
            {
                IWT(haarColors, layers);
            }

            var haarBitmap = EffectiveBitmap.Create(image.Width, image.Height, image.Depth, (i, j) =>
            {
                var haarColor = haarColors[j, i];
                return(haarColor.GetPixelInfo());
            });

            return(haarBitmap);
        }
Esempio n. 2
0
        private EffectiveBitmap Watermark(EffectiveBitmap original, EffectiveBitmap watermark)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var originalPixel = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                var r = (int)(originalPixel.R + (watermarkPixel.R * parameters.Ratio)) / 2;
                var g = (int)(originalPixel.G + (watermarkPixel.G * parameters.Ratio)) / 2;
                var b = (int)(originalPixel.B + (watermarkPixel.B * parameters.Ratio)) / 2;

                return new PixelInfo(r, g, b);
            }, original, watermark));
        }
Esempio n. 3
0
        private EffectiveBitmap CleanWatermark(EffectiveBitmap watermarked)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);

                var divider = (int)(Math.Pow(2, parameters.BitsForWatermark) + 0.5);
                // TODO better method instead of random bit on last position
                var r = (byte)(watermarkedImgPixel.R - watermarkedImgPixel.R % divider + CreateRandomNumber(divider));
                var g = (byte)(watermarkedImgPixel.G - watermarkedImgPixel.G % divider + CreateRandomNumber(divider));
                var b = (byte)(watermarkedImgPixel.B - watermarkedImgPixel.B % divider + CreateRandomNumber(divider));

                return new PixelInfo(r, g, b);
            }, watermarked));
        }
Esempio n. 4
0
        private EffectiveBitmap PreprocessToSimplifiedWatermark(EffectiveBitmap watermark)
        {
            var divider = (byte)(Math.Ceiling(255 / Math.Pow(2, parameters.BitsForWatermark)) + 0.5);

            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkPixel = sources[0].GetPixel(i, j);

                byte r = (byte)(watermarkPixel.R / divider);
                byte g = (byte)(watermarkPixel.G / divider);
                byte b = (byte)(watermarkPixel.B / divider);

                return new PixelInfo(r, g, b);
            }, watermark));
        }
        public override double CalculateDifference(EffectiveBitmap bitmap)
        {
            bitmap = bitmap.Resize(target.Width, target.Height);

            double differenceSum = 0;

            target.RunOnEveryPixel((x, y) =>
            {
                var p1         = target.GetPixel(x, y);
                var p2         = bitmap.GetPixel(x, y);
                differenceSum += Math.Abs(p1.R - p2.R) + Math.Abs(p1.G - p2.G) + Math.Abs(p1.B - p2.B);
            });

            return(differenceSum);
        }
Esempio n. 6
0
        private EffectiveBitmap ExtractWatermark(EffectiveBitmap watermarked)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);

                var divider = (int)Math.Pow(2, parameters.BitsForWatermark);
                var multiplier = 255 / (divider - 1);
                byte r = (byte)(watermarkedImgPixel.R % divider * multiplier);
                byte g = (byte)(watermarkedImgPixel.G % divider * multiplier);
                byte b = (byte)(watermarkedImgPixel.B % divider * multiplier);

                return new PixelInfo(r, g, b);
            }, watermarked));
        }
Esempio n. 7
0
        private EffectiveBitmap Watermark(EffectiveBitmap original, EffectiveBitmap watermark)
        {
            var simplifiedWatermark = PreprocessToSimplifiedWatermark(watermark);

            return(EffectiveBitmap.Create(original.Width, original.Height, original.Depth, (i, j) =>
            {
                var originalPixel = original.GetPixel(i, j);
                var watermarkPixel = simplifiedWatermark.GetPixel(i, j);

                var divider = (int)Math.Pow(2, parameters.BitsForWatermark);
                var r = (byte)(Math.Clamp(originalPixel.R - originalPixel.R % divider + watermarkPixel.R, 0, 255));
                var g = (byte)(Math.Clamp(originalPixel.G - originalPixel.G % divider + watermarkPixel.G, 0, 255));
                var b = (byte)(Math.Clamp(originalPixel.B - originalPixel.B % divider + watermarkPixel.B, 0, 255));

                return new PixelInfo(r, g, b);
            }));
        }
Esempio n. 8
0
        private EffectiveBitmap CleanWatermark(EffectiveBitmap imgWatermarked, EffectiveBitmap watermark)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                var r = (int)(watermarkedImgPixel.R * 2 - watermarkPixel.R * parameters.Ratio);
                var g = (int)(watermarkedImgPixel.G * 2 - watermarkPixel.G * parameters.Ratio);
                var b = (int)(watermarkedImgPixel.B * 2 - watermarkPixel.B * parameters.Ratio);

                r = r < 0 ? r + 1 : r;
                g = g < 0 ? g + 1 : g;
                b = b < 0 ? b + 1 : b;

                return new PixelInfo(r, g, b);
            }, imgWatermarked, watermark));
        }
Esempio n. 9
0
        private EffectiveBitmap ExtractWatermark(EffectiveBitmap imgWatermarked, EffectiveBitmap original)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);
                var originalPixel = sources[1].GetPixel(i, j);

                var r = (int)((2 * watermarkedImgPixel.R - originalPixel.R) * (1 / parameters.Ratio));
                var g = (int)((2 * watermarkedImgPixel.G - originalPixel.G) * (1 / parameters.Ratio));
                var b = (int)((2 * watermarkedImgPixel.B - originalPixel.B) * (1 / parameters.Ratio));

                r = r < 0 ? 0 : r;
                g = g < 0 ? 0 : g;
                b = b < 0 ? 0 : b;

                return new PixelInfo(r, g, b);
            }, imgWatermarked, original));
        }
Esempio n. 10
0
        public override async IAsyncEnumerable <AlgorithmResultElement> RemoveWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
            var haaredWatermarked = ProcessHaar(parameters.Watermarked, false, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            var haaredOriginal = ProcessHaar(parameters.Original, false, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            var extractedWatermark = BitmapOperations.Create((sources, i, j) =>
            {
                var layers = parameters.Layers;
                var haaredWatermarkedPixel = sources[0].GetPixel(i, j);
                var haaredPixel            = sources[1].GetPixel(i, j);

                var alpha = parameters.Alpha;

                var r = (int)((haaredWatermarkedPixel.R - haaredPixel.R) / alpha) % 255;
                var g = (int)((haaredWatermarkedPixel.G - haaredPixel.G) / alpha) % 255;
                var b = (int)((haaredWatermarkedPixel.B - haaredPixel.B) / alpha) % 255;

                return(new PixelInfo(r, g, b));
            }, haaredWatermarked, haaredOriginal);

            EffectiveBitmap croppedRemovedWatermark = null;

            if (parameters.Layers == 1)
            {
                croppedRemovedWatermark = extractedWatermark.Crop(extractedWatermark.Width / 2, 0, extractedWatermark.Width, extractedWatermark.Height / 2);
            }
            else if (parameters.Layers == 2)
            {
                croppedRemovedWatermark = extractedWatermark.Crop(extractedWatermark.Width * 3 / 4, 0, extractedWatermark.Width, extractedWatermark.Height / 4);
            }

            ct.ThrowIfCancellationRequested();

            var haaredRemovedWatermark = BitmapOperations.Create((sources, i, j) =>
            {
                var layers         = parameters.Layers;
                var originalPixel  = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                if (i > sources[0].Height * (2 * layers - 1) / (2 * layers) && j < sources[0].Width / (2 * layers))
                {
                    var alpha = parameters.Alpha;

                    var r = (int)(originalPixel.R - (watermarkPixel.R * alpha)) % 255;
                    var g = (int)(originalPixel.G - (watermarkPixel.G * alpha)) % 255;
                    var b = (int)(originalPixel.B - (watermarkPixel.B * alpha)) % 255;

                    return(new PixelInfo(r, g, b));
                }

                return(originalPixel);
            }, haaredWatermarked, extractedWatermark);

            var removedWatermark = ProcessHaar(haaredRemovedWatermark, true, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            yield return(new AlgorithmResultElement("Cleaned", removedWatermark, new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();
            yield return(new AlgorithmResultElement("Extracted watermark", croppedRemovedWatermark, new ResultDescription(ToString())));
        }
Esempio n. 11
0
 public DwtParameters(EffectiveBitmap original, EffectiveBitmap watermark, EffectiveBitmap watermarked, int layers, decimal alpha) : base(original, watermark, watermarked)
 {
     Layers = layers;
     Alpha  = (double)alpha;
     AlphaM = alpha;
 }
Esempio n. 12
0
 public abstract double CalculateDifference(EffectiveBitmap bitmap);
Esempio n. 13
0
 public PixelAveragingParameters(EffectiveBitmap original, EffectiveBitmap watermark, EffectiveBitmap watermarked, decimal ratio) : base(original, watermark, watermarked)
 {
     Ratio  = (double)ratio;
     RatioM = ratio;
 }
Esempio n. 14
0
 public LsbParameters(EffectiveBitmap original, EffectiveBitmap watermark, EffectiveBitmap watermarked, int bitsForWatermark) : base(original, watermark, watermarked)
 {
     BitsForWatermark = bitsForWatermark;
 }
Esempio n. 15
0
        private Task <List <AlgorithmResultElement> > GuessResult(IEnumerable <IAsyncEnumerable <AlgorithmResultElement> > results, EffectiveBitmap target, CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
            var evaluatedResults = results.Select(async x => await x.ToListAsync()).ToList();

            var bitmapMatcher = new BasicBitmapMatcher(target);

            var bests = evaluatedResults.OrderBy(x => bitmapMatcher
                                                 .CalculateDifference(
                                                     x.Result.Where(r => r.Label == "Cleaned").First().Image.TransformToEffectiveBitmap()
                                                     )
                                                 );

            return(bests.First());;
        }
Esempio n. 16
0
 public DctParameters(EffectiveBitmap original, EffectiveBitmap watermark, EffectiveBitmap watermarked, int key, decimal alpha) : base(original, watermark, watermarked)
 {
     Key    = key;
     Alpha  = (double)alpha;
     AlphaM = alpha;
 }
Esempio n. 17
0
 public BitmapMatcher(EffectiveBitmap target)
 {
     this.target = target;
 }
Esempio n. 18
0
 public RecognizerParameters(EffectiveBitmap original, EffectiveBitmap watermark, EffectiveBitmap watermarked) : base(original, watermark, watermarked)
 {
 }
 public BasicBitmapMatcher(EffectiveBitmap target) : base(target)
 {
 }