/// <summary>
        /// Decrypts the image hidden
        /// </summary>
        /// <returns>the image without the encrypted image below</returns>
        public MyImage Decrypt()
        {
            byte[] zero = { 0, 0, 0, 0 };
            Pixel[,] img = new Pixel[image.GetLength(0), image.GetLength(1)];
            MyImage result = new MyImage(img);

            for (int i = 0; i < image.GetLength(0); i++)
            {
                for (int j = 0; j < image.GetLength(1); j++)
                {
                    byte[] rBits  = ByteToBit(image[i, j].R);
                    byte[] gBits  = ByteToBit(image[i, j].G);
                    byte[] bBits  = ByteToBit(image[i, j].B);
                    byte[] rBits2 = ByteToBit(image[i, j].R);
                    byte[] gBits2 = ByteToBit(image[i, j].G);
                    byte[] bBits2 = ByteToBit(image[i, j].B);
                    //insert creation of new image
                    Insert(rBits, SubArray(rBits, 0, 4), 4);
                    Insert(gBits, SubArray(gBits, 0, 4), 4);
                    Insert(bBits, SubArray(bBits, 0, 4), 4);
                    Clean(rBits, 0, 4);
                    Clean(gBits, 0, 4);
                    Clean(bBits, 0, 4);
                    Clean(rBits2, 0, 4);
                    Clean(gBits2, 0, 4);
                    Clean(bBits2, 0, 4);
                    image[i, j].R = BitToByte(rBits);
                    image[i, j].G = BitToByte(gBits);
                    image[i, j].B = BitToByte(bBits);
                    img[i, j]     = new Pixel(BitToByte(rBits2), BitToByte(gBits2), BitToByte(bBits2));
                }
            }
            return(result);
        }
        /* Cryptography */

        /// <summary>
        /// Hide the image into another image
        /// </summary>
        /// <param name="img">image to hide our image</param>
        public void Encrypt(MyImage img)
        {
            int i = 0, j = 0;

            while (image.GetLength(0) >= img.image.GetLength(0) || image.GetLength(1) >= img.image.GetLength(1))
            {
                img.IncreaseSize();
            }
            img.CropFromMiddle(image.GetLength(0), image.GetLength(1));
            for (i = 0; i < image.GetLength(0); i++)
            {
                for (j = 0; j < image.GetLength(1); j++)
                {
                    byte[] rBits1 = ByteToBit(image[i, j].R);
                    byte[] rBits2 = ByteToBit(img.image[i, j].R);
                    byte[] gBits1 = ByteToBit(image[i, j].G);
                    byte[] gBits2 = ByteToBit(img.image[i, j].G);
                    byte[] bBits1 = ByteToBit(image[i, j].B);
                    byte[] bBits2 = ByteToBit(img.image[i, j].B);
                    Insert(rBits2, SubArray(rBits1, 4, 4), 0);
                    Insert(gBits2, SubArray(gBits1, 4, 4), 0);
                    Insert(bBits2, SubArray(bBits1, 4, 4), 0);
                    image[i, j].R = BitToByte(rBits2);
                    image[i, j].G = BitToByte(gBits2);
                    image[i, j].B = BitToByte(bBits2);
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            MyImage img = new MyImage("taxi.bmp");

            img.RedFilter();
            img.Save("taxi.bmp");
            Console.ReadKey();
        }
        /// <summary>
        /// Creates an histogram based on the image
        /// </summary>
        /// <param name="filename">specify the folder and filename</param>
        /// <returns>
        /// returns a string with the filename
        /// itcan vary because of existing file in the folder
        /// </returns>
        public string Histogram(string filename)
        {
            imageType        = "BM";
            offsetSize       = 54;
            int[,] histogram = this.histogram;
            int max = 0;

            foreach (int n in histogram)
            {
                if (n > max)
                {
                    max = n;
                }
            }
            float ratio = 100f / (float)max;

            Pixel[,] imageTemp = new Pixel[100, 256];
            for (int i = 0; i < imageTemp.GetLength(1); i++)
            {
                for (int j = 0; j < imageTemp.GetLength(0); j++)
                {
                    imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1] = Pixel.Black;
                    if (histogram[0, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddRed();
                    }
                    if (histogram[1, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddGreen();
                    }
                    if (histogram[2, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddBlue();
                    }
                }
            }
            MyImage histo = new MyImage(imageTemp);

            string[] split = filename.Split('\\');
            filename = "";
            for (int i = 0; i < split.Length - 1; i++)
            {
                filename += split[i] + '\\';
            }
            filename += "histogram-" + split.Last();
            return(histo.Save(filename));
        }
示例#5
0
        /// <summary>
        /// Decode a QRCode
        /// </summary>
        /// <param name="img">image containing the QRCode</param>
        private QRCode(MyImage img)
        {
            // Copy image on this object
            image = new Pixel[img.image.GetLength(0), img.image.GetLength(1)];
            for (int i = 0; i < image.GetLength(0); i++)
            {
                for (int j = 0; j < image.GetLength(1); j++)
                {
                    image[i, j] = new Pixel(img.image[i, j]);
                }
            }
            /* https://www.researchgate.net/publication/221337868_Fast_QR_Code_Detection_in_Arbitrarily_Acquired_Images */
            //Assume image is flat on the surface
            //Find the size of a finder and the size of a code to determine the version
            //and the size of a bit to be accurate while reading
            // plus save the start index of QRCode;
            // Different size horizontal and vertical (if image is warped
            int  sizeOfFinderHorizontal = 0;
            int  sizeOfCodeHorizontal   = 0;
            int  sizeOfFinderVertical   = 0;
            int  sizeOfCodeVertical     = 0;
            bool b           = true;
            int  line        = 0;
            int  column      = 0;
            int  startLine   = 0;
            int  startColumn = 0;

            //Searching
            while (b)
            {
                column = 0;
                while (column < image.GetLength(1) && !image[line, column].isCloseToBlack)
                {
                    column++;
                }
                startColumn = column;
                startLine   = line;
                // For horizontal size
                while (column < image.GetLength(1) && image[startLine, column].isCloseToBlack)
                {
                    b = false;
                    sizeOfFinderHorizontal++;
                    column++;
                }
                // For Vertical size
                while (!b && line < image.GetLength(0) && image[line, startColumn].isCloseToBlack)
                {
                    sizeOfFinderVertical++;
                    line++;
                }
                if (!b)
                {
                    // Horizontal size
                    for (int j = image.GetLength(1) - 1; j >= 0 && sizeOfCodeHorizontal == 0; j--)
                    {
                        if (image[startLine, j].isCloseToBlack)
                        {
                            sizeOfCodeHorizontal = j - startColumn;
                        }
                    }
                    // Vertical Size
                    for (int j = image.GetLength(0) - 1; j >= 0 && sizeOfCodeVertical == 0; j--)
                    {
                        if (image[j, startColumn].isCloseToBlack)
                        {
                            sizeOfCodeVertical = j - startLine;
                        }
                    }
                }
                line++;
            }
            //Compute the size of a bit (finder is 7 pixels wide)
            int bitSizeHorizontal = sizeOfFinderHorizontal / 7;
            int bitSizeVertical   = sizeOfFinderVertical / 7;
            int approxSize        = sizeOfCodeHorizontal / bitSizeHorizontal;

            //Determine the version of QR based on the size
            if (approxSize < 23)
            {
                type = 1;
            }
            else
            {
                type = 2;
            }
            //Now read the QRCode but first Draw the Canvas
            DrawCanvas();
            //Read DAta
            string messageBits = ReadData(bitSizeHorizontal, bitSizeVertical, startLine, startColumn);

            // Get rid of the last seven bits if type 2
            if (type == 2)
            {
                messageBits = messageBits.Substring(0, 352);
            }
            Console.WriteLine(messageBits);
            // Get The Error count
            int eccCount = 7 * 8;

            if (type == 2)
            {
                eccCount = 10 * 8;
            }
            //Split error bits and message bits
            string errorBits = messageBits.Substring(messageBits.Length - eccCount, eccCount);

            messageBits = messageBits.Substring(0, messageBits.Length - eccCount);
            // Decode with Reed Solomon Algorithm
            byte[] messageBytes = BitsToByte(messageBits);
            byte[] errorBytes   = BitsToByte(errorBits);
            byte[] finalMessage = ReedSolomonAlgorithm.Decode(messageBytes, errorBytes, ErrorCorrectionCodeType.QRCode);
            messageBits = ByteToBit(finalMessage);
            // Assume the image is alphanumeric and get rid of the length
            messageBits = messageBits.Substring(4, messageBits.Length - 4);
            Decode_Message(messageBits);
        }
示例#6
0
        /// <summary>
        /// Decode a QRCode
        /// </summary>
        /// <param name="img">the image containing the QRCode</param>
        /// <returns>the message contatained in the QRCode</returns>
        public static string Decode(MyImage img)
        {
            QRCode init = new QRCode(img);

            return(init.message);
        }