Ejemplo n.º 1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                // ImageOperations.distinct_color(ImageMatrix);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
        }
        private static int err_r, err_g, err_b; //->O(1)
        /// <summary>
        ///  for each pixel an "error" is generated and then distributed to four pixels around
        /// the surrounding the current pixel. Each of the four offset pixels has a different
        /// weight - the error is multiplied by the weight, divided by 16 and then
        /// added to the existing value of the offset pixel
        /// four offset pixels:
        ///     7 for the pixel to the right of the current pixel
        ///     3 for the pixel below and to the left
        ///     5 for the pixel below
        ///      1 for the pixel below and to the right
        /// </summary>
        /// <param name="ImageMatrix"></param>
        /// <param name="factor">quant_error </param>
        /// <returns></returns>
        public static RGBPixel[,] Atkinson_Dithering(RGBPixel[,] ImageMatrix, int factor)                                    // ->>O(H * W)
        {
            h = ImageOperations.GetHeight(ImageMatrix);                                                                      //->O(1)
            w = ImageOperations.GetWidth(ImageMatrix);                                                                       //->O(1)
            RGBPixel[,] Buffer = ImageMatrix.Clone() as RGBPixel[, ];                                                        // => O(H * W)

            for (int i = 0; i < w - 1; i++)                                                                                  //horizontal             //->O(W) * O(H)    ->>O(H * W)
            {
                for (int j = 1; j < h - 1; j++)                                                                              // vertical                //->O(H) *O(1)  ->>O(H)
                {
                    R1 = Buffer[j, i].red;                                                                                   //->O(1)
                    G1 = Buffer[j, i].green;                                                                                 //->O(1)
                    B1 = Buffer[j, i].blue;                                                                                  //->O(1)

                    R2 = Convert.ToInt32(Math.Round(factor * R1 / 255)) * (255 / factor);                                    //->O(1)
                    G2 = Convert.ToInt32(Math.Round(factor * G1 / 255)) * (255 / factor);                                    //->O(1)
                    B2 = Convert.ToInt32(Math.Round(factor * B1 / 255)) * (255 / factor);                                    //->O(1)
                    Buffer[j, i].red   = (byte)R2;                                                                           //->O(1)
                    Buffer[j, i].green = (byte)G2;                                                                           //->O(1)
                    Buffer[j, i].blue  = (byte)B2;                                                                           //->O(1)
                    err_r = (int)R1 - R2;                                                                                    //->O(1)
                    err_g = (int)G1 - G2;                                                                                    //->O(1)
                    err_b = (int)B1 - B2;                                                                                    //->O(1)
                    // right
                    Buffer[j + 1, i].red   = (byte)(Buffer[j + 1, i].red + err_r * 7 / 16);                                  //->O(1)
                    Buffer[j + 1, i].green = (byte)(Buffer[j + 1, i].green + err_g * 7 / 16);                                //->O(1)
                    Buffer[j + 1, i].blue  = (byte)(Buffer[j + 1, i].blue + err_b * 7 / 16);                                 //->O(1)
                    gray_scale(ref Buffer[j + 1, i].red, ref Buffer[j + 1, i].green, ref Buffer[j + 1, i].blue);             //->O(1)
                                                                                                                             //below and to the left
                    Buffer[j - 1, i + 1].red   = (byte)(Buffer[j - 1, i + 1].red + err_r * 3 / 16);                          //->O(1)
                    Buffer[j - 1, i + 1].green = (byte)(Buffer[j - 1, i + 1].green + err_g * 3 / 16);                        //->O(1)
                    Buffer[j - 1, i + 1].blue  = (byte)(Buffer[j - 1, i + 1].blue + err_b * 3 / 16);                         //->O(1)
                    gray_scale(ref Buffer[j - 1, i + 1].red, ref Buffer[j - 1, i + 1].green, ref Buffer[j - 1, i + 1].blue); //->O(1)
                    // below
                    Buffer[j, i + 1].red   = (byte)(Buffer[j, i + 1].red + err_r * 5 / 16);                                  //->O(1)
                    Buffer[j, i + 1].green = (byte)(Buffer[j, i + 1].green + err_g * 5 / 16);                                //->O(1)
                    Buffer[j, i + 1].blue  = (byte)(Buffer[j, i + 1].blue + err_b * 5 / 16);                                 //->O(1)
                    gray_scale(ref Buffer[j, i + 1].red, ref Buffer[j, i + 1].green, ref Buffer[j, i + 1].blue);             //->O(1)
                    // below and to right
                    Buffer[j + 1, i + 1].red   = (byte)(Buffer[j + 1, i + 1].red + err_r * 1 / 16);                          //->O(1)
                    Buffer[j + 1, i + 1].green = (byte)(Buffer[j + 1, i + 1].green + err_g * 1 / 16);                        //->O(1)
                    Buffer[j + 1, i + 1].blue  = (byte)(Buffer[j + 1, i + 1].blue + err_b * 1 / 16);                         //->O(1)
                    gray_scale(ref Buffer[j + 1, i + 1].red, ref Buffer[j + 1, i + 1].green, ref Buffer[j + 1, i + 1].blue); //->O(1)
                }
            }

            return(Buffer); //->O(1)
        }
Ejemplo n.º 3
0
 private void quantizedToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (Histo != null)
     {
         Histo.Close();
     }
     if (pictureBox2.Image != null)
     {
         Histo = new Histogram((Bitmap)pictureBox2.Image, ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix));
         Histo.Show();
     }
     else
     {
         MessageBox.Show("Please Select an Image .");
     }
 }
Ejemplo n.º 4
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
            st             = Stopwatch.StartNew();
            System.Threading.Thread.Sleep(500);
        }
Ejemplo n.º 5
0
        public static int[] CountRedFrequency(RGBPixel[,] image) //ϴ(n^2)
        {
            int[] RedArr = new int[256];                         //ϴ(1)
            int   width  = ImageOperations.GetWidth(image);      //ϴ(1)
            int   height = ImageOperations.GetHeight(image);     //ϴ(1)

            for (int i = 0; i < height; i++)                     //ϴ(n^2)
            {
                for (int j = 0; j < width; j++)                  //ϴ(n)
                {
                    RedArr[image[i, j].red] += 1;                //ϴ(1)
                }
            }


            return(RedArr);
        }
Ejemplo n.º 6
0
        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            if (op.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = op.FileName;

                // create instance of video reader
                VideoFileReader reader = new VideoFileReader();
                // open video file
                reader.Open(fileName);
                // read 100 video frames out of it
                for (int i = 0; i <= 1312; i++)
                {
                    Bitmap videoFrame = reader.ReadVideoFrame();
                    Program.images_name[Program.index_vedio] = "C:\\Users\\JOE\\Desktop\\[TEMPLATE] ImageEncryptCompress\\Take Pictures\\" + i.ToString();
                    Program.index_vedio++;
                    videoFrame.Save(@"C:\\Users\\JOE\\Desktop\\[TEMPLATE] ImageEncryptCompress\Take Pictures\\" + i.ToString() + ".bmp");
                    // dispose the frame when it is no longer required
                    videoFrame.Dispose();
                }
                reader.Close();
            }

            Huffman_Tree tree = new Huffman_Tree();

            Huffman_Tree.Comp   = new FileStream("Compressed_Picture.bin", FileMode.Append);
            Huffman_Tree.Comp_r = new BinaryWriter(Huffman_Tree.Comp);
            Huffman_Tree.Comp_r.Write(Program.index_vedio);
            Huffman_Tree.Comp_r.Close();
            Huffman_Tree.Comp.Close();
            for (int i = 0; i < Program.index_vedio; i++)
            {
                Huffman_Tree.Comp   = new FileStream("Compressed_Picture.bin", FileMode.Append);
                Huffman_Tree.Comp_r = new BinaryWriter(Huffman_Tree.Comp);
                string OpenedFilePath = Program.images_name[i];
                Program.OriginalImage = ImageOperations.OpenImage(OpenedFilePath + ".bmp");
                Width  = ImageOperations.GetWidth(Program.OriginalImage);
                Height = ImageOperations.GetHeight(Program.OriginalImage);
                tree.FreqMatrix(Program.OriginalImage);
                Compress c = new Compress();
                c.convert_Image_to_binary();
            }
            MessageBox.Show("DONE");
        }
Ejemplo n.º 7
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            g = new Graph();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
                txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
                g.Find_Distinct_colors(ImageMatrix);
                DistinctColors.Text = g.Distinct.Count.ToString();
            }
        }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix    = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
                txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
                FilePath       = OpenedFilePath.Remove((OpenedFilePath.Length - 4), 4);
                //img = new Bitmap(pictureBox1.Image);
                img = new Bitmap(OpenedFilePath);
            }
        }
Ejemplo n.º 9
0
        private void btnDisplay_Click(object sender, EventArgs e)
        {
            var stopwatch      = Stopwatch.StartNew();
            int imageWidth     = ImageOperations.GetWidth(ImageMatrix);  //O(1)
            int imageHeight    = ImageOperations.GetHeight(ImageMatrix); //O(1)
            int maxDistinctNum = 60000;                                  //Maximum number of distinic in the given test cases //O(1)

            //Dictionary that contains MinSpanningTree
            Dictionary <int, KeyValuePair <int, double> > MSTree = new Dictionary <int, KeyValuePair <int, double> >(maxDistinctNum);//O(1)

            //Helper Dictionary for keeping struct values concatenated as integer (Key) and the struct as Value
            Dictionary <int, RGBPixel> distinctHelper = new Dictionary <int, RGBPixel>(maxDistinctNum);                        //O(1)
            //Checks visited nodes in minimum spanning tree
            Dictionary <int, bool> visited = new Dictionary <int, bool>(maxDistinctNum);                                       //O(1)
            int color = 0;                                                                                                     //O(1)
            //Any node that we start from the Minimum Spanning
            KeyValuePair <int, KeyValuePair <int, double> > minVertix = new KeyValuePair <int, KeyValuePair <int, double> >(); //O(1)
            //O(D^2)
            int noDistinctColors = MST.FindDistinctColors(ImageMatrix, ref MSTree, ref distinctHelper, ref visited, ref color, ref minVertix);
            //List that contains mimimum spanning edges sorted
            List <KeyValuePair <double, int> > edges = new List <KeyValuePair <double, int> >(maxDistinctNum);              //O(1)
            double MST_Sum = MST.FindMinimumSpanningTree(ref MSTree, distinctHelper, visited, color, minVertix, ref edges); //O(D^2)

            int k = int.Parse(txtGetK.Text);                                                                                //O(N)
            //Dictionary carries each original color as key and representative color of each cluster as value
            Dictionary <int, RGBPixel> represntativeColor = new Dictionary <int, RGBPixel>(maxDistinctNum);
            //O(K+D) = O(D)
            Dictionary <int, List <int> > clusteredGraph = Clustering.ProduceKClusters(k, edges, MSTree, maxDistinctNum, visited);

            //O(E+V) =O(V) = O(D)
            Clustering.DFS(clusteredGraph, visited, maxDistinctNum, k, ref represntativeColor, distinctHelper);
            //O(N^2)
            MST.Coloring(ref ImageMatrix, represntativeColor);

            ImageOperations.DisplayImage(ImageMatrix, pictureBox2);
            stopwatch.Stop();
            double Miliseconds = (stopwatch.Elapsed.TotalMilliseconds);

            txtMili.Text = Miliseconds.ToString(); //O(1)
            double Seconds = (stopwatch.Elapsed.TotalSeconds);

            txtSec.Text      = Seconds.ToString();          //O(1)
            txtDistinct.Text = noDistinctColors.ToString(); //O(1)
            txtMST.Text      = MST_Sum.ToString();          //O(1)
        }
Ejemplo n.º 10
0
 public ImageQuantizer(RGBPixel[,] imageMatrix)
 {
     hashDistinctColors = new HashSet <int>();
     distanceFromWhite  = new List <KeyValuePair <int, int> >();
     MstGraph           = new List <List <KeyValuePair <int, double> > >();
     distinctColors     = new List <int>();
     height             = ImageOperations.GetHeight(imageMatrix);
     width = ImageOperations.GetWidth(imageMatrix);
     quantizedImageMatrix = new RGBPixel[height, width];
     for (int i = 0; i < height; ++i)
     {
         for (int j = 0; j < width; ++j)
         {
             RGBPixel pix = imageMatrix[i, j];
             quantizedImageMatrix[i, j] = new RGBPixel(pix.red, pix.green, pix.blue);
         }
     }
 }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.get_Distincit(ImageMatrix);
                ImageOperations.grph(int.Parse(txtGaussSigma.Text));
                ImageOperations.Clustring();
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                ImageMatrix = ImageOperations.Refill_Mtrx(ImageMatrix);
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string initial_seed;
            int    tap_position;

            initial_seed = textBox1.Text;
            tap_position = int.Parse(textBox2.Text);
            // hna m7taga 2handl lw md5l4 initial seed w tap positon


            int width  = ImageOperations.GetWidth(ImageMatrix);
            int height = ImageOperations.GetHeight(ImageMatrix);

            obj = new Encryption(initial_seed, tap_position);
            obj.convert_str_to_arr();
            obj.enc(ImageMatrix, width, height);
            ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
        }
Ejemplo n.º 13
0
        public void Encryption_Decryption_with_Big_seed(ref RGBPixel[,] img, ref StringBuilder initial, ref int tap, ref int last_bit)
        {
            int img_Height = ImageOperations.GetHeight(img);
            int img_Width  = ImageOperations.GetWidth(img);

            for (int i = 0; i < img_Height; i++)
            {
                for (int j = 0; j < img_Width; j++)
                {
                    StringBuilder redseed      = LFSR_Big_Seed(ref initial, ref tap, ref last_bit);
                    int           redextracted = 0;
                    int           counter      = 0;
                    for (int a = redseed.Length - 8; a <= redseed.Length - 1; a++)
                    {
                        redextracted += (redseed[a] - 48) * powersoftwo[counter];
                        counter++;
                    }
                    img[i, j].red = Convert.ToByte(img[i, j].red ^ redextracted);
                    counter       = 0;
                    int           greenextracted = 0;
                    StringBuilder greenseed      = LFSR_Big_Seed(ref redseed, ref tap, ref last_bit);
                    for (int a = greenseed.Length - 8; a <= greenseed.Length - 1; a++)
                    {
                        greenextracted += (greenseed[a] - 48) * powersoftwo[counter];
                        counter++;
                    }
                    img[i, j].green = Convert.ToByte(img[i, j].green ^ greenextracted);
                    counter         = 0;
                    int           blueextracted = 0;
                    StringBuilder blueseed      = LFSR_Big_Seed(ref greenseed, ref tap, ref last_bit);
                    for (int a = blueseed.Length - 8; a <= greenseed.Length - 1; a++)
                    {
                        blueextracted += (blueseed[a] - 48) * powersoftwo[counter];
                        counter++;
                    }
                    img[i, j].blue = Convert.ToByte(img[i, j].blue ^ blueextracted);
                    counter        = 0;
                    initial        = blueseed;
                }
            }

            ImageOperations.DisplayImage(img, pictureBox2);
        }
 private void imageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog openFileDialog1 = new OpenFileDialog();
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             string OpenedFilePath = openFileDialog1.FileName;
             ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
             ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
         }
         txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
         txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
     }
     catch
     {
         MessageBox.Show("Please Select Photo");
     }
 }
Ejemplo n.º 15
0
        //function to find the difrent colors
        public void get_colors(RGBPixel[,] ImageMatrix)
        {
            bool[, ,] pixels = new bool[265, 265, 265];
            int height = ImageOperations.GetHeight(ImageMatrix);
            int width  = ImageOperations.GetWidth(ImageMatrix);

            for (long i = 0; i < height; i++)
            {
                for (long j = 0; j < width; j++)
                {
                    if (pixels[ImageMatrix[i, j].red, ImageMatrix[i, j].green, ImageMatrix[i, j].blue] == false)
                    {
                        pixels[ImageMatrix[i, j].red, ImageMatrix[i, j].green, ImageMatrix[i, j].blue] = true;
                        colors.Add(ImageMatrix[i, j]);
                        count++;
                    }
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Function that repaints the image with the new representative color of each cluster
        /// </summary>
        /// <param name="Buffer">Image 2D array</param>
        /// <param name="represntativeColor">Dictionary that carries every distinct node with its new color</param>
        /// <returns>The quantized image</returns>
        /// Time Complexity: O(N^2)

        public static RGBPixel[,] Coloring(ref RGBPixel[,] Buffer, Dictionary <int, RGBPixel> represntativeColor)
        {
            int imageWidth  = ImageOperations.GetWidth(Buffer);  //O(1)
            int imageHeight = ImageOperations.GetHeight(Buffer); //O(1)

            RGBPixel[,] modifiedImage = Buffer;                  //O(1)
            //Outer for loop approaches an O(N) operation, N is the image height
            for (int i = 0; i < imageHeight; ++i)
            {
                //Inner for loop approaches an O(N) operation, N is the image width
                for (int j = 0; j < imageWidth; ++j)
                {
                    RGBPixel node     = Buffer[i, j];                                   //O(1)
                    int      color    = CantorPairing(node.red, node.green, node.blue); //O(1)
                    RGBPixel newColor = represntativeColor[color];                      //O(1)
                    modifiedImage[i, j] = newColor;                                     //O(1)
                }
            }
            return(modifiedImage); //O(1)
        }
Ejemplo n.º 17
0
        /*
         * Colouring Function
         * Summary : Quantizes the original image by replacing each pixel with it's corresponding average
         * Parameters : Orginal Image as 2D array of RGBPixel, Colour Pallete as a dictionary of color as key represented as double and it's corresponding average represented as a RGBPixel
         * Return : Quantized Image as 2D array of RGBPixel
         */
        public RGBPixel[,] colouring(RGBPixel[,] matrix, Dictionary <double, RGBPixel> pallete) //O(N^2)
        {
            int height = ImageOperations.GetHeight(matrix);                                     //O(1)
            int width  = ImageOperations.GetWidth(matrix);                                      //O(1)

            for (int i = 0; i < height; i++)                                                    // O(H*W) = O(N^2)
            {
                for (int j = 0; j < width; j++)                                                 // O(W)
                {
                    double red   = matrix[i, j].red;                                            //O(1)
                    double blue  = matrix[i, j].blue;                                           //O(1)
                    double green = matrix[i, j].green;                                          //O(1)
                    double key   = 0.5 * (red + blue) * (red + blue + 1) + blue;                //O(1)
                    key = 0.5 * (green + key) * (green + key + 1) + key;                        //O(1)

                    matrix[i, j] = pallete[key];                                                //O(1)
                }
            }
            return(matrix);//O(1)
        }
Ejemplo n.º 18
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
            Graph g = new Graph();

            g.Costruct_MST(ImageMatrix);
            g.Clustering(int.Parse(Clusters.Text.ToString()), ref ImageMatrix);
            ImageOperations.DisplayImage(ImageMatrix, pictureBox2);
            pictureBox2.Image.Save("C:\\Users\\Mohamed\\Desktop\\images Quantizarion\\New\\Complete Test\\Complete Test\\Large\\My.bmp", ImageFormat.Bmp);
        }
Ejemplo n.º 19
0
        public RGBPixel[,] replace()
        {
            int Dcolors_width = ImageOperations.GetWidth(ImageMatrix);
            //Get The Height Of The Image
            int Dcolors_height = ImageOperations.GetHeight(ImageMatrix);

            for (int i = 0; i < Dcolors_height; i++)
            {
                for (int j = 0; j < Dcolors_width; j++)
                {
                    int res = ImageMatrix[i, j].red;
                    res = (res << 8) + ImageMatrix[i, j].green;
                    res = (res << 8) + ImageMatrix[i, j].blue;
                    int indexcheck   = Distictit_Colors.check[res];
                    int indexCluster = guid[indexcheck];
                    ImageMatrix[i, j] = Clusters[indexCluster];
                }
            }
            return(ImageMatrix);
        }
Ejemplo n.º 20
0
        //string OpenedFilePath2;

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (!checkBox2.Checked)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //Open the browsed image and display it
                    string OpenedFilePath = openFileDialog1.FileName;
                    ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                    ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                }
                txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
                txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
            }
            else
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //Open the browsed image and display it

                    string OpenedFilePath = openFileDialog1.FileName; //filepath

                    Stopwatch sw = Stopwatch.StartNew();


                    ImageMatrix = ImageOperations.Decompress_image(OpenedFilePath, ref seed, ref tap, ref height, ref width);
                    ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                    sw.Stop();
                    text_seed.Text         = seed;
                    text_tap.Text          = tap.ToString();
                    txtHeight.Text         = height.ToString();
                    txtWidth.Text          = width.ToString();
                    btnGaussSmooth.Enabled = true;
                    MessageBox.Show("Decompression time: " + ((double)sw.ElapsedMilliseconds / 1000).ToString() + " seconds");
                    //label1.Text = "Encrypted Image";
                }
            }
        }
 private void btnOpen_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog openFileDialog1 = new OpenFileDialog();
         openFileDialog1.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             string OpenedFilePath = openFileDialog1.FileName;
             ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
             ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
         }
         txtWidth.Text   = ImageOperations.GetWidth(ImageMatrix).ToString();
         txtHeight.Text  = ImageOperations.GetHeight(ImageMatrix).ToString();
         button1.Enabled = true;
     }
     catch
     {
         DialogResult d1 = MessageBox.Show("Please Select Photo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Ejemplo n.º 22
0
 private void button18_Click(object sender, EventArgs e)
 {
     try
     {
         pictureBox9.SizeMode = PictureBoxSizeMode.Normal;
         OpenFileDialog openFileDialog1 = new OpenFileDialog();
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             //Open the browsed image and display it
             string OpenedFilePath = openFileDialog1.FileName;
             ImageMatrix            = ImageOperations.OpenImage(OpenedFilePath);
             ImageOperations.factor = 1;
             ImageOperations.DisplayImage(ImageMatrix, pictureBox9);
         }
         txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
         txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
     }
     catch
     {
     }
 }
        private void chooseImage_Click(object sender, EventArgs e)
        {
            // intialization the tools
            ClusterK.Value   = 0;                                  // -> O(1)
            factor.Value     = 1;                                  // -> O(1)
            txtMST.Text      = null;                               // -> O(1)
            txtDisColor.Text = null;                               // -> O(1)
            factor.Text      = "1";                                // -> O(1)
            maskSize.Text    = "3";                                // -> O(1)
            Preimage.Image   = null;                               // -> O(1)
            OpenFileDialog openFileDialog1 = new OpenFileDialog(); // -> O(1)

            if (openFileDialog1.ShowDialog() == DialogResult.OK)   // -> O(1)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;               // -> O(1)
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);        // -> O(W*H)
                ImageOperations.DisplayImage(ImageMatrix, Preimage, 0);         // -> O(W*H)
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();  // -> O(1)
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString(); // -> O(1)
        }
Ejemplo n.º 24
0
        private void button2_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            HuffmanTree compression    = new HuffmanTree();
            double      CRBCompression = 0;
            double      CRACompression = 0;

            compression.Compression(ref ImageMatrix, ref CRBCompression, ref CRACompression, ref red_bytes_in_file, ref green_bytes_in_file, ref blue_bytes_in_file);

            //save Trees in file
            Red_Huffman   = new HuffmanTree();
            Green_Huffman = new HuffmanTree();
            Blue_Huffman  = new HuffmanTree();

            Red_Huffman.PrintHuffmanTree(Red_Root);
            Green_Huffman.PrintHuffmanTree(Green_Root);
            Blue_Huffman.PrintHuffmanTree(Blue_Root);
            // save width and height and initial seed and tap position in file
            FileStream   FN  = new FileStream("Total_Info.dat", FileMode.Append);
            BinaryWriter FNR = new BinaryWriter(FN);

            FNR.Write(ImageOperations.GetHeight(ImageMatrix));
            FNR.Write(ImageOperations.GetWidth(ImageMatrix));
            FNR.Write(txt_initialseed.Text);
            FNR.Write(txt_tapposition.Text);
            FNR.Close();
            FN.Close();
            sw.Stop();
            compression_lbl.Text = sw.Elapsed.ToString();

            MessageBox.Show("Compressed !");
            MessageBox.Show("Original Size = " + CRBCompression.ToString());
            MessageBox.Show("Compression Ratio After Compression = " + CRACompression.ToString());
            MessageBox.Show("stored bytes red" + red_bytes_in_file.ToString());
            MessageBox.Show("stored bytes green" + green_bytes_in_file.ToString());
            MessageBox.Show("stored bytes blue" + blue_bytes_in_file.ToString());
        }
Ejemplo n.º 25
0
        public static void EncodeAndDecode(ref RGBPixel[,] ImageMatrix, BitArray seedInBit, int Tap)
        {
            int length = seedInBit.Length - 1;

            int[] valueInDecimal = new int[1];
            seedInBit.CopyTo(valueInDecimal, 0);
            BitArray Seed = new BitArray(new int[] { valueInDecimal[0] });

            RGBPixel[,] Imageenc = new RGBPixel[ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix)];
            byte valueInByte = new byte();

            byte[]   valueAftermodification = new byte[1];
            BitArray valueInBits;

            for (int i = 0; i < ImageOperations.GetHeight(ImageMatrix); i++)
            {
                for (int j = 0; j < ImageOperations.GetWidth(ImageMatrix); j++)
                {
                    valueInByte = ImageMatrix[i, j].red;
                    valueInBits = new BitArray(new byte[] { valueInByte });
                    BitArray SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].red = valueAftermodification[0];

                    valueInByte       = ImageMatrix[i, j].green;
                    valueInBits       = new BitArray(new byte[] { valueInByte });
                    SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].green = valueAftermodification[0];

                    valueInByte       = ImageMatrix[i, j].blue;
                    valueInBits       = new BitArray(new byte[] { valueInByte });
                    SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].blue = valueAftermodification[0];
                }
            }
            ImageMatrix = Imageenc;
        }
Ejemplo n.º 26
0
        private void button2_Click(object sender, EventArgs e)
        {
            int width  = ImageOperations.GetWidth(ImageMatrix);  // read from file
            int height = ImageOperations.GetHeight(ImageMatrix); // read from file
            var bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int red   = ImageMatrix[y, x].red;   // read from array
                    int green = ImageMatrix[y, x].green; // read from array
                    int blue  = ImageMatrix[y, x].blue;  // read from array
                    bitmap.SetPixel(x, y, Color.FromArgb(0, red, green, blue));
                }
            }
            SaveFileDialog save_dialog = new SaveFileDialog();

            save_dialog.Filter = "Png Image|*.png|Bitmap Image|*.bmp";

            if (save_dialog.ShowDialog() == DialogResult.OK)
            {
                switch (save_dialog.FilterIndex)
                {
                case 0:
                {
                    bitmap.Save(save_dialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
                }
                break;

                case 1:
                {
                    bitmap.Save(save_dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                break;
                }
            }
        }
Ejemplo n.º 27
0
        public static bool[] visitedHeap;                                           // -> O(1)

        /// <summary>
        /// responsible for extracting all unique colors and
        /// pushing them into a list.
        /// <param name= "ImageMatrix">2D Array holds data colors</param>
        /// <returns>number of distinct color</returns>
        /// </summary>
        public static long Find_Distinct_Color(RGBPixel[,] ImageMatrix) // -> O(H * W)
        {
            Distinct_Colors_List.Clear();                               // -> O(N)
            bool[,,] check = new bool[256, 256, 256];                   // -> O(1)
            int width_image  = ImageOperations.GetWidth(ImageMatrix);   // -> O(1)
            int height_image = ImageOperations.GetHeight(ImageMatrix);  // -> O(1)

            for (int i = 0; i < height_image; i++)                      // -> O(H) * O(W) -> O(H * W)
            {
                for (int j = 0; j < width_image; j++)                   // -> O(W)*  O(1)
                {
                    int r = ImageMatrix[i, j].red                       // -> O(1)
                    , g   = ImageMatrix[i, j].green                     // -> O(1)
                    , b   = ImageMatrix[i, j].blue;                     // -> O(1)
                    if (!check[r, g, b])                                //distinct_colors.Contains(ImageMatrix[i, j]) // -> O(1)
                    {
                        Distinct_Colors_List.Add(ImageMatrix[i, j]);    // -> O(1)
                        check[r, g, b] = true;                          // -> O(1)
                    }
                }
            }
            return(Distinct_Colors_List.Count); // -> O(1)
        }
Ejemplo n.º 28
0
        public void get_distict_colors()                                        // O(n*m)      overall
        {
            distinct.Clear();                                                   // hashset
            my_distinct.Clear();;                                               // list with values of the hashset

            for (int i = 0; i < ImageOperations.GetHeight(ImageMatrix); i++)    //  O(n)  n-> height of the image
            {
                for (int j = 0; j < ImageOperations.GetWidth(ImageMatrix); j++) //  O(m)   m-> width of the image
                {
                    //  all O(1)
                    int rgb = ImageMatrix[i, j].red;
                    rgb = (rgb << 8) + ImageMatrix[i, j].green;
                    rgb = (rgb << 8) + ImageMatrix[i, j].blue;
                    distinct.Add(rgb);                                                   //  O(1)   hashset uses hash fn
                }
            }
            Dis_txt.Text = distinct.Count.ToString() + " distinct colors";

            foreach (int x in distinct)                                                  //  O(n)   " n number of distinct color"
            {
                my_distinct.Add(x);
            }
        }
Ejemplo n.º 29
0
        public static RGBPixel[,] enc(int pass, RGBPixel[,] pic, int position, int len) //ϴ(n^2)
        {
            long ShiftedPassRED   = ImageOperations.pass(pass, position, len);          //ϴ(1)
            long ShiftedPassGREEN = ImageOperations.pass(SavedSeed, position, len);     //ϴ(1)
            long ShiftedPassBLUE  = ImageOperations.pass(SavedSeed, position, len);     //ϴ(1)
            int  width            = ImageOperations.GetWidth(pic);                      //ϴ(1)
            int  height           = ImageOperations.GetHeight(pic);                     //ϴ(1)

            for (int i = 0; i < height; i++)                                            //ϴ(n^2)
            {
                for (int j = 0; j < width; j++)                                         //ϴ(n)
                {
                    pic[i, j].red   ^= Convert.ToByte(ShiftedPassRED);                  //ϴ(1)
                    pic[i, j].green ^= Convert.ToByte(ShiftedPassGREEN);                //ϴ(1)
                    pic[i, j].blue  ^= Convert.ToByte(ShiftedPassBLUE);                 //ϴ(1)
                    //Note that complexity of convert is O(n) ,but the number of n is limited (8)
                    ShiftedPassRED   = ImageOperations.pass(SavedSeed, position, len);  //ϴ(1)
                    ShiftedPassGREEN = ImageOperations.pass(SavedSeed, position, len);  //ϴ(1)
                    ShiftedPassBLUE  = ImageOperations.pass(SavedSeed, position, len);  //ϴ(1)
                }
            }
            return(pic);
        }
Ejemplo n.º 30
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //Open the browsed image and display it
                    string OpenedFilePath = openFileDialog1.FileName;

                    ImageMatrix           = ImageOperations.OpenImage(OpenedFilePath);
                    Width                 = ImageOperations.GetWidth(ImageMatrix);
                    Height                = ImageOperations.GetHeight(ImageMatrix);
                    Program.OriginalImage = new RGBPixel[Height, Width];
                    Program.OriginalImage = ImageMatrix;
                }
                txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
                txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
            }
            catch
            {
                MessageBox.Show("No image selected.");
            }
        }