示例#1
0
        public override async IAsyncEnumerable <AlgorithmResultElement> AddWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            complexImage     = ComplexImage.FromBitmap(parameters.Original);
            complexWatermark = ComplexImage.FromBitmap(parameters.Watermark, complexImage.Width);

            ct.ThrowIfCancellationRequested();

            complexImage.ForwardFourierTransform();
            var fourierDomain = complexImage.ToEffectiveBitmapFourier();

            yield return(new AlgorithmResultElement("Fourier domain (DFT)", fourierDomain.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            complexWatermark.ForwardFourierTransform();
            complexImage.EmbedImageFourier(complexWatermark, parameters.Key, parameters.Alpha);
            var fourierDomainWatermarked = complexImage.ToEffectiveBitmapFourier();

            yield return(new AlgorithmResultElement("DFT + watermark", fourierDomainWatermarked.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            complexImage.BackwardFourierTransform();
            var watermarked = complexImage.ToEffectiveBitmapFourier();

            yield return(new AlgorithmResultElement("Watermarked", watermarked.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));
        }
示例#2
0
        public override async IAsyncEnumerable <AlgorithmResultElement> RemoveWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            ComplexImage complexWatermarked = ComplexImage.FromBitmap(parameters.Watermarked);

            complexWatermarked.ForwardFourierTransform();

            ct.ThrowIfCancellationRequested();

            ComplexImage complexOriginal = ComplexImage.FromBitmap(parameters.Original);

            complexOriginal.ForwardFourierTransform();

            ct.ThrowIfCancellationRequested();

            int[]    v      = new int[complexWatermarked.Width];
            double[] vAlpha = new double[complexWatermarked.Width];
            Random   random = new Random(parameters.Key);

            ct.ThrowIfCancellationRequested();

            for (int i = 0; i < complexWatermarked.Width; i++)
            {
                v[i]      = random.Next(0, 2);
                vAlpha[i] = v[i] * parameters.Alpha;
            }

            ct.ThrowIfCancellationRequested();

            for (int y = 0; y < complexWatermarked.Height; y++)
            {
                for (int x = 0; x < complexWatermarked.Width; x++)
                {
                    double watermarkedReal      = complexWatermarked.Data[y, x].Real;
                    double watermarkedImaginary = complexWatermarked.Data[y, x].Imaginary;
                    double originalReal         = complexOriginal.Data[y, x].Real;
                    double originalImaginary    = complexOriginal.Data[y, x].Imaginary;
                    if (vAlpha[x] == 0)
                    {
                        complexWatermarked.Data[y, x] = new System.Numerics.Complex(0, 0);
                    }
                    else
                    {
                        complexWatermarked.Data[y, x] = new System.Numerics.Complex((watermarkedReal - originalReal) / vAlpha[x], (watermarkedImaginary - originalImaginary) / vAlpha[x]);
                    }
                }
            }

            ct.ThrowIfCancellationRequested();

            yield return(new AlgorithmResultElement("Extracted watermark DFT", complexWatermarked.ToEffectiveBitmapFourier(true).ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            complexWatermarked.BackwardFourierTransform();

            ct.ThrowIfCancellationRequested();

            yield return(new AlgorithmResultElement("Extracted watermark", complexWatermarked.ToEffectiveBitmapFourier(true).ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));
        }
示例#3
0
        public override async IAsyncEnumerable <AlgorithmResultElement> AddWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            int size = 0;

            if (Math.Max(parameters.Original.Width, parameters.Original.Height) > 512)
            {
                size = Math.Max(parameters.Original.Width, parameters.Original.Height) / 2;
            }
            complexImage     = ComplexImage.FromBitmap(parameters.Original, size);
            complexWatermark = ComplexImage.FromBitmap(parameters.Watermark, complexImage.Width);

            ct.ThrowIfCancellationRequested();

            complexImage.DCT();
            var cosineTransform = complexImage.ToEffectiveBitmapCosine();

            yield return(new AlgorithmResultElement("Cosine transform (DCT)", cosineTransform.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            complexWatermark.DCT();

            ct.ThrowIfCancellationRequested();

            complexImage.EmbedImageCosine(complexWatermark, parameters.Key, parameters.Alpha);
            var cosineWatermarked = complexImage.ToEffectiveBitmapCosine();

            yield return(new AlgorithmResultElement("DCT + watermark", cosineWatermarked.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            complexImage.IDCT();
            var watermarked = complexImage.ToEffectiveBitmapCosine();

            yield return(new AlgorithmResultElement("Watermarked", watermarked.ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));
        }
示例#4
0
        public override async IAsyncEnumerable <AlgorithmResultElement> RemoveWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            int size = 0;

            if (Math.Max(parameters.Watermarked.Width, parameters.Watermarked.Height) > 512)
            {
                size = Math.Max(parameters.Watermarked.Width, parameters.Watermarked.Height) / 2;
            }
            ComplexImage complexWatermarked = ComplexImage.FromBitmap(parameters.Watermarked, size);

            ct.ThrowIfCancellationRequested();

            complexWatermarked.DCT();

            ct.ThrowIfCancellationRequested();

            ComplexImage complexOriginal = ComplexImage.FromBitmap(parameters.Original, complexWatermarked.Width);

            complexOriginal.DCT();

            ct.ThrowIfCancellationRequested();

            int[]    v      = new int[complexWatermarked.Width];
            double[] vAlpha = new double[complexWatermarked.Width];
            Random   random = new Random(parameters.Key);

            ct.ThrowIfCancellationRequested();

            for (int i = 0; i < complexWatermarked.Width; i++)
            {
                v[i]      = random.Next(0, 2);
                vAlpha[i] = v[i] * parameters.Alpha;
            }

            ct.ThrowIfCancellationRequested();

            for (int y = 0; y < complexWatermarked.Height; y++)
            {
                for (int x = 0; x < complexWatermarked.Width; x++)
                {
                    if (vAlpha[x] == 0)
                    {
                        complexWatermarked.DCTData[y, x] = 0;
                    }
                    else
                    {
                        complexWatermarked.DCTData[y, x] = (complexWatermarked.DCTData[y, x] - complexOriginal.DCTData[y, x]) / vAlpha[x];
                    }
                }
            }

            ct.ThrowIfCancellationRequested();

            yield return(new AlgorithmResultElement("Extracted watermark DCT", complexWatermarked.ToEffectiveBitmapCosine(true).ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));

            complexWatermarked.IDCT();

            ct.ThrowIfCancellationRequested();

            yield return(new AlgorithmResultElement("Extracted watermark", complexWatermarked.ToEffectiveBitmapCosine(true).ToBitmap(parameters.Original.Size), new ResultDescription(ToString())));
        }